Putting the Raspberry Pi to sleep
As much as I wanted the SmartUPS to work for the OspreyCam project, I decided to take a look at the Spell Foundry Sleepy Pi instead. The Sleepy Pi is basically an Arduino board with regulators and switching transistors to control the power to a Raspberry Pi board. It also has a real-time clock (RTC) chip, which will be handy for keeping track of the date when the Raspberry Pi does not have an internet connection. The RTC can also be used for waking up the Sleepy Pi (and optionally, the Raspberry Pi) at predetermined times.
Programming the Sleepy Pi
I will admit, I am an Arduino novice. I keep looking around under the hood, wanting to see the actual compiler and header files. But first things first. To do anything more sophisticated than blinking an LED, you will need the SleepyPi and RTC libraries:
$ cd ~/sketchbook/libraries/ # created by Arduino IDE $ git clone -o github https://github.com/SpellFoundry/SleepyPi.git $ git clone -o github https://github.com/SpellFoundry/DS1374RTC.git $ git clone -o github https://github.com/rocketscream/Low-Power.git LowPower $ git clone -o github https://github.com/PaulStoffregen/Time.git
The File/Examples/SleepyPi/ButtonOnOff example is a good place to start.
Using the RTC in Raspbian
Since the original RTC on Raspberry Pi instructions were published, Raspbian has undergone a change in the way that peripherals are configured in the kernel. The I2C drivers are configured via Device Tree blobs, rather than by passing options into the modules when they are loaded.
According to this Device Tree forum post, the new way to enable I2C
is to add the following line to
Since I occasionally use the SmartUPS for testing indoors, I use the following line instead to drop the I2C baud rate to 50 kHz:
Since we're talking about editing
config.txt, another thing I tend to tweak
is the camera LED:
# http://elinux.org/Rpi_Camera_Module disable_camera_led=1
Also, the I2C /dev and RTC modules need to be loaded by adding the following
After making sure that
/etc/rc.local is executable, add the following lines
exit 0, and reboot:
echo ds1374 0x68 > /sys/class/i2c-adapter/i2c-1/new_device #printf "\nSetting system time from hardware clock\n" #/sbin/hwclock -s
I commented out the call to
hwclock because you will probably want to allow
the Raspberry Pi to grab the actual time from the internet via NTP, then call
/sbin/hwclock -wu to set the time in the RTC. After that, you can uncomment
/sbin/hwclock -s and the line above it.