battery status, sleep interval

This commit is contained in:
2021-04-11 11:58:39 +02:00
parent 97bb091ae5
commit c50cb8acc2
2 changed files with 27 additions and 17 deletions

View File

@@ -3,8 +3,6 @@
2021 Stefan Ostermann based on several source from the internetz.
*NOT working in platformio right now!*
Sources:
https://git.cryhost.de/crycode/attiny85-radiohead-dht22-weather-sensor/-/tree/master
*/
@@ -25,12 +23,17 @@
// the own RadioHead address
#define RH_OWN_ADDR 0xca // 202
// the server RadioHead address
#define RH_SERVER_ADDR 0x01
// RadioHead bitrate in bit/s
#define RH_SPEED 1000
/*
define when to wake up
0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
*/
#define WATCHDOG_WAKEUP 9
// pins for the radio hardware
#define RH_RX_PIN 6 // not used, set to a non-existent pin
#define RH_TX_PIN 3
@@ -123,7 +126,7 @@ void setup() {
rh_buf[0] = MSG_START;
rh_send(1);
setup_watchdog(6); // approximately 4 seconds sleep
setup_watchdog(WATCHDOG_WAKEUP);
}
@@ -136,7 +139,7 @@ void loop() {
digitalWrite(LED_PIN, HIGH);
// temperature and humidity
float t = 0;//float is 32bit = 1byte
float t = 0;//float is 32bit = 4 byte
float h = 0;
int soil = 0;
long battery = 0;
@@ -170,7 +173,6 @@ void loop() {
// turn off the LED
digitalWrite(LED_PIN, LOW);
system_sleep();
//_delay_ms(1000);
}
}
@@ -230,10 +232,17 @@ void setup_watchdog(int ii) {
From https://github.com/cano64/ArduinoSystemStatus/blob/master/SystemStatus.cpp
*/
int getVcc() {
//reads internal 1V1 reference against VCC
ADMUX = _BV(MUX3) | _BV(MUX2); // For ATtiny85/45
_delay_ms(5);; // Wait for Vref to settle
//reads internal 1V1 reference against VCC
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
ADMUX = _BV(MUX5) | _BV(MUX0); // For ATtiny84
#elif defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny45__)
ADMUX = _BV(MUX3) | _BV(MUX2); // For ATtiny85/45
#elif defined(__AVR_ATmega1284P__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); // For ATmega1284
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); // For ATmega328
#endif
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA, ADSC));
uint8_t low = ADCL;
@@ -243,6 +252,6 @@ int getVcc() {
while (bit_is_set(ADCSRA, ADSC));
low = ADCL;
val = (ADCH << 8) | low;
return (long)val;
return ((long)1024 * 1100) / val;
}