|
|
|
|
@ -1,6 +1,7 @@
@@ -1,6 +1,7 @@
|
|
|
|
|
// Enable debug prints to serial monitor
|
|
|
|
|
#define MY_DEBUG |
|
|
|
|
#define MY_RADIO_NRF24 |
|
|
|
|
#define MY_RF24_PA_LEVEL RF24_PA_MAX |
|
|
|
|
//#define MY_NODE_ID 7
|
|
|
|
|
|
|
|
|
|
#include <SPI.h> |
|
|
|
|
@ -15,8 +16,8 @@
@@ -15,8 +16,8 @@
|
|
|
|
|
#define SKETCH_NAME "Rain Gauge" // Change to a fancy name you like
|
|
|
|
|
#define SKETCH_VERSION "1.1" // Your version
|
|
|
|
|
|
|
|
|
|
//unsigned long SLEEP_TIME = 18*60000; // Sleep time (in milliseconds).
|
|
|
|
|
unsigned long SLEEP_TIME = 20000; // use this instead for debug
|
|
|
|
|
unsigned long SLEEP_TIME = 20*60000; // Sleep time (in milliseconds).
|
|
|
|
|
//unsigned long SLEEP_TIME = 20000; // use this instead for debug
|
|
|
|
|
|
|
|
|
|
float hwRainVolume = 0; // Current rainvolume calculated in hardware.
|
|
|
|
|
int hwPulseCounter = 0; // Pulsecount recieved from GW
|
|
|
|
|
@ -34,10 +35,10 @@ MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
@@ -34,10 +35,10 @@ MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
|
|
|
|
|
// BATTERY VOLTAGE DIVIDER SETUP
|
|
|
|
|
// 1M, 470K divider across battery and using internal ADC ref of 1.1V
|
|
|
|
|
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
|
|
|
|
|
// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
|
|
|
|
|
// 3.44/1023 = Volts per bit = 0.003363075
|
|
|
|
|
#define VBAT_PER_BITS 0.003363075 |
|
|
|
|
#define VMIN 2.0 // Vmin (radio Min Volt)=1.9V (564v)
|
|
|
|
|
// ((100e3+35e3)/35e3)*1.1 = Vmax = 4,24 Volts
|
|
|
|
|
// 4,24/1023 = Volts per bit = 0.004144673
|
|
|
|
|
#define VBAT_PER_BITS 0.004144673 |
|
|
|
|
#define VMIN 3.0 // Vmin (radio Min Volt)=1.9V (564v)
|
|
|
|
|
#define VMAX 4.2 // Vmax = (2xAA bat)=3.0V (892v)
|
|
|
|
|
int batteryPcnt = 0; // Calc value for battery %
|
|
|
|
|
int batLoop = 0; // Loop to help calc average
|
|
|
|
|
@ -108,7 +109,7 @@ boolean tipped = oldReedState != reedState;
@@ -108,7 +109,7 @@ boolean tipped = oldReedState != reedState;
|
|
|
|
|
if (tipped==false) { |
|
|
|
|
|
|
|
|
|
//No bucket tipped over last sleep-period, check battery then...
|
|
|
|
|
//batM();
|
|
|
|
|
batM(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lastSend=currentTime; |
|
|
|
|
@ -137,6 +138,14 @@ void batM(){ //The battery calculations
@@ -137,6 +138,14 @@ void batM(){ //The battery calculations
|
|
|
|
|
// Calculate the battery in %
|
|
|
|
|
float Vbat = sensorValue * VBAT_PER_BITS; |
|
|
|
|
int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.); |
|
|
|
|
|
|
|
|
|
if (batteryPcnt > 100) { |
|
|
|
|
batteryPcnt=100; |
|
|
|
|
} |
|
|
|
|
if (batteryPcnt < 0) { |
|
|
|
|
batteryPcnt=0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); |
|
|
|
|
|
|
|
|
|
// Add it to array so we get an average of 3 (3x20min)
|
|
|
|
|
@ -146,10 +155,6 @@ void batM(){ //The battery calculations
@@ -146,10 +155,6 @@ void batM(){ //The battery calculations
|
|
|
|
|
batteryPcnt = (batArray[0] + batArray[1] + batArray[2]); |
|
|
|
|
batteryPcnt = batteryPcnt / 3; |
|
|
|
|
|
|
|
|
|
if (batteryPcnt > 100) { |
|
|
|
|
batteryPcnt=100; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %"); |
|
|
|
|
sendBatteryLevel(batteryPcnt); |
|
|
|
|
batLoop = 0; |
|
|
|
|
|