How to decrease battery usage:
- sleep for longer.
- decrease oscillator frequency.
@amvv: I don't think you get the best usage from you batteries. You can easily sleep 8000x longer,-
My understanding of sleep mode:
Once you put the system to sleep, your'e normal loop() function will basically stop executing -right at the systemsleep() command.
The code will continue executing after the sleep command once its awaken. (Continue with the main loop())
ANY HARDWARE INTERRUPT will cause the system to wake.
The Arduino code base has a millis() function which uses a timer0 overflow:
See wiring.c, line 44: SIGNAL(TIMER0OVFvect).
That means you get waken up every millisecond and your main loop executes once (only once, since you have a systemsleep() at the end. Only until wdt also wakes you, and sets WDT=1
To get MUCH better battery usage, I would recommend the following.
-Disable TIMER0. (You cant use millis() then, or any function that depends on it for timing)
In your current code WDT will wake you up every set seconds
-Kill the counter/Period loop and the wdt variable - you only need this if other things disturbs your precious sleep.
- Serial UART activity will still wake you, but I assume the Rx pin is not connected
You loop() would become:
void loop() {
// DO THE STUFF
// will happen every WDT interval
systemsleep();
}
This approach kills millis(), but you can sleep for 8 seconds - this would be great for the battery!!
Note that you should probably enable TIMER0, when doing your stuff, since most Arduino related libs uses this (even the RF12 driver uses millis()). millis() would be correct in a relative way, not a correct absolute value (since uC startup).
void loop() {
ENABLETIMER0;
// DO THE STUFF
// will happen every WDT interval
DISABLETIMER0;
systemsleep();
}
If you want a absolute time value, you can count your wake-ups and multiply by the sleep time.
Hope it helps!