When powering from USB (5v) my sketch runs as expected, when powering from 2xAAA via battery pack accessory I get a few weird behaviours.
Output on USB ~5V:
Output on battery:
The Serial output is disjoined, text will be randomly cut off, you can see that in the final output in the picture above.
The text still appears to be in a buffer as when the device wakes up for next poll the remaining text will appear in the next output (as is evident by all the proceeding outputs being complete).
The temperature sensor (DS18B20) reports -127.0 degrees on most readings (sometimes it reports a reading, but mostly it's -127), I'm assuming this is its null value.
I added a whole bunch of delay() statements to my code, to give it enough time to output prior to sleeping, and also added Serial.flush() to attempt to get it to flush all the output prior to sleeping.
This was mostly to try and solve the Serial output issue.
I have no idea how to solve the DS18B20 issue, I'm getting a steady 3.26v on the 3.3v headers so I'm not sure why it would be returning a null value.
Here is my code, it's fairly simple, inclusive of all the additional delay() statements.
Output on USB ~5V:
Output on battery:
The Serial output is disjoined, text will be randomly cut off, you can see that in the final output in the picture above.
The text still appears to be in a buffer as when the device wakes up for next poll the remaining text will appear in the next output (as is evident by all the proceeding outputs being complete).
The temperature sensor (DS18B20) reports -127.0 degrees on most readings (sometimes it reports a reading, but mostly it's -127), I'm assuming this is its null value.
I added a whole bunch of delay() statements to my code, to give it enough time to output prior to sleeping, and also added Serial.flush() to attempt to get it to flush all the output prior to sleeping.
This was mostly to try and solve the Serial output issue.
I have no idea how to solve the DS18B20 issue, I'm getting a steady 3.26v on the 3.3v headers so I'm not sure why it would be returning a null value.
Here is my code, it's fairly simple, inclusive of all the additional delay() statements.
Code: Select all
#include "struct.h"
#include <T2WhisperNode.h>
#include <LowPower.h>
#include <RH_RF95.h>
RH_RF95 myRadio;
T2Flash myFlash;
#define RADIO_FREQUENCY 868.0
#define RADIO_TX_POWER 13
#define SERIAL_BAUDRATE 115200
#include <OneWire.h> // DS18B20 Libraries
#include <DallasTemperature.h> // DS18B20 Libraries
#define ONE_WIRE_BUS 3 // DS18B20 GPIO
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature ds18b20(&oneWire); // Pass our oneWire reference to Dallas Temperature sensor
void read_ds18b20(SENSORDATA* data) {
ds18b20.requestTemperatures();
data->ds18b20.temperature = ds18b20.getTempCByIndex(0);
}
#include "DHT.h"
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void read_dht(SENSORDATA* data) {
data->dht.humidity = dht.readHumidity();
data->dht.temperature = dht.readTemperature();
if (isnan(data->dht.humidity) || isnan(data->dht.temperature)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
data->dht.heatindex = dht.computeHeatIndex(data->dht.temperature, data->dht.humidity, false);
}
void setup() {
Serial.begin(SERIAL_BAUDRATE);
while (!Serial) {} // Wait for Serial
// Radio - Initialize the radio and put it to sleep to save energy
myRadio.init();
myRadio.setFrequency(RADIO_FREQUENCY);
myRadio.setTxPower(RADIO_TX_POWER);
myRadio.sleep();
// Flash - We're not using, so just power it down to save energy
myFlash.init(T2_WPN_FLASH_SPI_CS);
myFlash.powerDown();
dht.begin();
ds18b20.begin();
delay(1000);
}
void loop() {
delay(1000);
SENSORDATA data;
delay(1000);
read_dht(&data);
delay(1000);
read_ds18b20(&data);
delay(1000);
data.power.battery = T2Utils::readVoltage(T2_WPN_VBAT_VOLTAGE, T2_WPN_VBAT_CONTROL);
delay(1000);
data.power.supply = T2Utils::readVoltage(T2_WPN_VIN_VOLTAGE, T2_WPN_VIN_CONTROL);
Serial.println(F("-------------------------"));
Serial.print(F(" Temperature: ")); Serial.print(data.ds18b20.temperature); Serial.println(F("ºC "));
Serial.print(F(" Humidity: ")); Serial.print(data.dht.humidity); Serial.println(F("%"));
Serial.print(F(" Battery: ")); Serial.print(data.power.battery); Serial.println(F(" millivolts."));
Serial.print(F(" Power Supply: ")); Serial.print(data.power.supply); Serial.println(F(" millivolts."));
Serial.flush();
delay(1000);
myRadio.send((uint8_t *) &data, sizeof(data));
myRadio.waitPacketSent();
myRadio.sleep();
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}