Sending your data through the air

The Sleep Code – DS3231

The second way I put the processor to sleep (or rather, wake a processor that's been powered down) is to use the special timer hardware in the optional DS3231 clock that can be plugged into the Pro Mini LP. I analyzed of the accuracy of the DS3231 in a previous column [11], and the DS3231 was the clear winner. The DS3231 has two sets of alarm registers that can be used periodically to interrupt the ATMega328P according to the DS3231 time/day/date. You are somewhat limited as to how fast you can send packets (one per second is the maximum), and you can't send them, for example, every 32 seconds, but you can set send every 30 seconds, 1 minute, 1 hour, and so on. You can even send yourself a message on December 21, 2017, if you like. Whereas, before, I used the Sleepy class to put the processor to sleep (loseSomeTime), in this case I use the Sleepy class powerDown function (Listing 3) to make the processor go away forever until it gets an interrupt. By checking the source of the interrupt (i.e., from either the DS3231 or the rain bucket), I can decide whether to send a packet or go right back to sleep. The code in Listing 4 wakes up the processor every 30 seconds.

Listing 3

powerDown Function

// use DS3231 Alarm to Wake up
    Serial.println(F("Using DS3231 to Wake Up"));
    Sleepy::powerDown ();

Listing 4

Waking Up Processor

// choose once per 30 seconds
 RTC.setAlarm(ALM1_MATCH_SECONDS, 30, 0, 0, 0);
 RTC.setAlarm(ALM2_EVERY_MINUTE , 0, 0, 0, 0);
 RTC.alarmInterrupt(ALARM_1, true);
 RTC.alarmInterrupt(ALARM_2, true);

The DS3231 is a very, very nice real-time clock chip with lots of good features, and it even has a temperature sensor. SwitchDoc Labs provides a DS3231 plug-in board with each Pro Mini LP. Note that cutting the LED on the DS3231 saves about 2mA. The DS3231 itself only uses 0.4mA.


The test power results in Figure 6 show current consumption with a transmission every 30 seconds. Note that the current monitoring system only reads the current about every second, so sometimes it misses the current spike. I am probably off on total current consumption by 25% or so. The actual average current consumption is probably about 4mA rather than 3mA, but that is still well under the design goal of 5mA.

Figure 6: Current consumption graph from the Pro Mini LP transmitter.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content