Hello,
I have problems measuring battery voltage and an analog sensor connected to A5. The sensor works fine when I do not read the battery voltage. But i can not read battery voltage AND the sensor an A5. When i try to re
d both values the value on A5 is always 1023. I also tested other analog pins with the same effect.
Here is some of the code I use
I have problems measuring battery voltage and an analog sensor connected to A5. The sensor works fine when I do not read the battery voltage. But i can not read battery voltage AND the sensor an A5. When i try to re
Here is some of the code I use
Code: Select all
#include <RFM69.h>
#include <SPI.h>
#include <T2WhisperNode.h>
#include <LowPower.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
#define SOIL_SENSOR A5
#define NODEID 2
#define NETWORKID 1
#define GATEWAYID 1
#define FREQUENCY RF69_868MHZ
#define SERIAL_BAUD 9600
#define ACK_TIME 60 // # of ms to wait for an ack
byte sendSize = 0;
boolean requestACK = false;
//RFM69 radio;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
typedef struct {
float temp;
int soil_humidity;
// float voltage;
} Payload;
Payload soilData;
void setup() {
Serial.begin (SERIAL_BAUD);
// radio.initialize(FREQUENCY, NODEID, NETWORKID);
// radio.setHighPower();
sensors.begin();
}
void loop() {
//LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
sensors.requestTemperatures();
soilData.temp = sensors.getTempCByIndex(0);
//soilData.voltage = T2Utils::readVoltage(T2_WPN_VBAT_VOLTAGE, T2_WPN_VBAT_CONTROL) / 1000.0;
soilData.soil_humidity = analogRead(SOIL_SENSOR);
Serial.print ("Soil Temperature = ");
Serial.println (soilData.temp);
Serial.print ("Soil Humidity = ");
Serial.println (soilData.soil_humidity);
//radio.sendWithRetry(GATEWAYID, (const void*)(&theData), sizeof(theData)));
//radio.send (GATEWAYID, (const void*)(&soilData), sizeof(soilData), requestACK);
//radio.sleep();
delay (1000);
}
