Abstract

As our production of open source devices with a variety of sensors continues to roll out, it is of the utmost importance to try and make these devices as power efficient as possible in order to conserve battery life. The solution is simple, using a variety of adafruit and SparkFun libraries such a LowPower.h, RTClib and a custom RTClibExtended. However, the problem at hand is the compatibility and settle discrepancies between the processors we are using and how they interface with these libraries. This post will serve as a walkthrough on how to work with these power saving libraries with the latest 32u4 and M0 processor boards as well as integrating this logic into Arduino UNO projects. 

Methods

I think the best place to start off is a diagram of what a template program using sleep functionality should look like. Below is flow chart of sorts of how your program should be set-up in order to follow the structure of the example code included with this guide.

Sleep-RTC Logic Diagram (1).jpg

*Important note, any delays or program functions should be contained within a conditional statement in the wake flag routine. * 

Using Pin Interrupts

Often times the simplest way to conserve battery is to put the processor to "sleep" which causes the device to enter a lower power state where it is no longer constantly checking all peripherals or running any processes. However, the most common (and simplest) way to wake a processor is to specify an interrupt pin. An interrupt pin is a specified digital or analogue pin that is expecting an interrupt signal (typically rising or falling voltage). An interrupt is a signal that tells the processor to immediately stop what it is doing and handle some high priority processing, in our case WAKE UP! Below is a brief breakdown of the different syntax used to initialize an interrupt pin on the 32u4 and M0 Adafruit processors boards as well as a basic Arduino. 

 Arduino Uno

- use A0 pin as an interrupt (using attachInterrupt function as laid out in the code provided)

- Example Code:

32u4

- Use SleepWake32uPCINT

- Example Code:

M0

- Use SleepWakeMoInt

- Example code:

 

Using the DS3231 Real Time Clock to Send an interrupt signal

Note: There are two types of alarm styles (Wake up once daily, or after a certain elapsed time) included in the RTClibExtended library, Both are included in the linked sketches. 

 

Arduino Uno

- use RCTSleepWakeUseIntA0

- Example Code:

32u4

- use SleepWake32u4RTCPCINT

-Example Code:

 M0

- use SleepWakeMoRTCInt

- Example Code:

Conclusion

After looking at three of the most common processor boards and how to establish Pin interrupts and RTC interrupts, this tutorial should greatly increase the power efficiency of our future projects. 

Tom DeBell