Deep sleep implementation example


I quite can’t get the idea of deep sleep showed on support page or github examples. Could anyone provide an example for Sara AFF to go to sleep for X seconds every time the main loop is done? I know that to achive this 26uA power consumption we need to use (built-in?) RTC timer?

I would be glad for any simple implementation of this functionality

Hi Mike,

It is not a must to use the RTC timer to wake the device up, we also use the watchdog to do this. The watchdog will wake the device every 8(.192) seconds also, that’s the one we use in the low power sketch. The RTC is particularly useful if you want to wake the device every minute, hour, etc.

Let’s say to want to sleep for 40 seconds or so per loop. In that case you can use a counter that increments every time the loop is entered and do work after 5 times.

If this wasn’t clear please let me know.


So f.e if I would like to send location of the device every, let’s say 30 min it is better approach (in terms of battery usage) to use RTC lib or to just program watchdog with cycle amount (until next location send) to do every 8 seconds?

Hi mike,

If you want something to happen every 30 minutes I’d recommend you look into our RTCTimer.h & .cpp.
First instantiate it:

RTCTimer timer;

Then initialize it:

timer.setNowCallback(getNow); // set how to get the current time
timer.every(30 * 60, ENTERYOURCALLBACKHERE);

In your loop make sure to periodically call this, you can hitch your RTC alarm every minute or your watchdog wakeup event.


The update will call your callback when enough time has passed (here it’s 30*60 seconds, 30 minutes).

Your getNow() can be anything, but it should return the current time in seconds since epoch. You probably want to ask that from your RTC like so.

uint32_t getNow()
    return rtc.getEpoch();

This is often a question on how to juggle accuracy with power consumption. A higher resolution and lower interval means higher consumption and the need for alternative events, but with 30 minutes I’d recommend using the RTC events (every minute).