The Sleepy Pi 1 contains an Arduino processor (ATMEGA328P) and its functionality is governed by the code that the Arduino contains. That means that to shutdown / start the Raspberry Pi you need to write / load / run some code on the Arduino. Fortunately there are some examples and a library that help you along the way.
NOTE: Sleepy Pi 2 uses a different RTC and the library is slightly different. There will be a page dedicated to Sleepy Pi 2 coming. For now see the Github page for the latest code and examples.
The Sleepy Pi Arduino library contains routines that control the main functionality of the hardware. The latest version can be downloaded from GitHub.
In code terms it takes the form of a Sleepy Pi class and in true C++ tradition makes use of inheritance. For those new to programming and C++, inheritance provides a convenient way to make use of other code and integrate it into main class as if it born with it in.
The Sleepy PI currently makes use of three libraries:
These must be present in your Sketchbook/libraries folder so that the Arduino IDE knows where to find them.To use an inherited routine as if it was our own we simply use the “.” notation:For example, to use the LowPower libraries “powerDown” feature on SleepyPi we could write:
The Sleepy Pi is a very flexible board and it can turn it’s hand to many things. In broad concept though, the Sleepy Pi is designed to maximize battery life in Raspberry Pi applications that do not require the RaspPi to be on all the time. In order to do this best, when the Arduino has cut the power to the RaspPi, it should itself go into a low power mode and then “wakeup” either on some event or periodically to check something.
The Arduino processor used is typical of many microcontrollers, in that it has the ability to “sleep” and when doing so reduce it’s power consumption. When asleep, though, we need some way of waking it up. I’ve found that shouting at it, is not too effective, nor is throwing a cup of water over it. Instead, I’ve found that these three methods work best:
Triggering an interrupt is best performed using an I/O line. We can setup a GPIO line such that if it goes high or low or even changes it will wake the processor.
Using an Alarm Clock is really just a variation on the interrupt method, but is highlighted separately here because we actually have an Alarm line that goes from the RTC to the Arduino. We can set-up the RTC to trigger this Alarm at the desired time, which in turn wakes up the processor (there is no snooze button though).
Using the Watchdog Timer is an internal timer that can still run when the main parts of the processor are asleep. You can only set-up the timer with fixed times which are:
The watchdog is a great way to wake-up the Sleepy Pi to perform some periodic task – like take a sensor reading, check whether some other event has happened.
In all cases you can decide whether or not to wake the RaspPi.
Here is a simple example of using the watchdog timer:
Getting your processor to sleep can be a bit of a Black Art at times and generally doesn’t involve rocking it or taking it for a drive, but instead wading through the intricacies of the processor datasheet. This is where the LowPower library comes in and takes the pain out of using low power sleep modes.
There are a number of different flavours of sleep and they each have a different levels of power consumption. In essence these are (in rough order from highest power to lowest):
For a complete overview of this visit the Rocketscream website. When used with the Sleepy Pi, the code snippet becomes:
Your email address will not be published. Required fields are marked *