I have a project with a pretty simple code like this:
servo.attach(2);
servo.writeMicroseconds(800);
//The delay below is just so that the servo has enough time to move to the desired position.
delay(1000);
servo.detach();
//Wait ~24h.
delay(24*60*60*1000);
servo.attach(2);
servo.writeMicroseconds(1200);
//The delay below is just so that the servo has enough time to move to the desired position.
delay(1000);
servo.detach();
//Wait ~24h.
delay(24*60*60*1000);
servo.attach(2);
servo.writeMicroseconds(1600);
//The delay below is just so that the servo has enough time to move to the desired position.
delay(1000);
servo.detach();
//Wait ~24h.
delay(24*60*60*1000);
....
You can see 99,999% of the time Arduino is doing nothing (long delays between each servo move). So I am wondering: is there some code I can execute before each long delay so Arduino can save power without using wake interrupts?
I am aware of the "avr/sleep.h" library but when I use the code below, arduino stops completely the execution (of course, it's waiting to be woken up). I tried changing "SLEEP_MODE_PWR_DOWN" to "SLEEP_MODE_IDLE" and this way arduino does not stop execution BUT I cant see any current drop using my multmeter.
@jremington Thanks, I had already read that link, it's great! However it messes with registers and is a lot advanced. I was wondering if there is a known library that provides the "delay with power saving" or something similar... I really think that arduino should already have it built in in the language since any delay does absolutely nothing, just waits... every time a delay is called, Arduino could check if there is any interrupt attached or any code to watchdog attached, otherwise it should disable everything untill the delay has passed since the user explicitly didnt set any interrupt or watchdog that could cause problem disabling.
Sure, there are a couple of popular power saving libraries, and they have been around for years. But none that I have seen are sophisticated enough to let you to use all the techniques discussed in Gammon's tutorial.
There is nothing like "delay while power saving", as the MCU clock must be turned off. You have to put it to sleep, with some sort of interrupt to wake the MCU. Most people use the watchdog timer to effect a short wakeup period. Google "Arduino watchdog wakeup" for some examples.