The Sleepy Pi has the ability to co-ordinate a shutdown of the Raspberry Pi via two GPIO handshake lines:
GPIO 24: – Command the RPi to shutdownGPIO 25: – RPi is running
Software must be running on both the Raspberry Pi and also the Sleepy Pi that react to these signals.
From the Sleepy Pi’s perspective, the shutdown sequence is as follows:
Set GPIO 24 high to signal that we are going to shutdownMonitor GPIO 25, wait for it to go low indicating that the Raspberry Pi software has stopped running.Cut the power to the Raspberry Pi.
From the Raspberry Pi’s perspective, the shutdown sequence is as follows:
NOTE: The Sleepy Pi Setup script will setup the handshaking on Raspbian for you. This section outlines the manual process of setting this up should you not use the script.
To properly handshake, the Raspberry Pi must install a script that runs at boot and continues in the background setting and monitoring the handshake lines.
Copy the following script to /home/pi/bin/button/
The shutdowncheck.py script looks like this:
import RPi.GPIO as GPIO
import os, time
print ("[Info] Telling Sleepy Pi we are running pin 25")
print ("Sleepy Pi requesting shutdown on pin 24")
os.system("sudo shutdown -h now")
To run this script at startup, we must edit the /etc/rc.local
$ sudo nano /etc/rc.local
and insert the following line just before the final exit 0 and save changes:
python /home/pi/bin/button/shutdowncheck.py &
DONT forget the “&” which allows the script to run in the background!
(This script is based on this one)
NOTE: On a fresh PI install you will need to set the permissions on /etc/rc/local so that it can execute at startup. To do this execute the following command from a terminal window:
sudo chmod u+x /etc/rc.local
The Sleepy Pi 2 is setup by default to use GPIO 24 and 25 for handshaking via solder jumpers. There may be circumstances where you might need to use these GPIO pins for something else – such as those used by another plugin board. In this case you can remove the solder jumpers and free up these pins, replacing the handshaking with something more creative or arcane. I’d suggest making the Arduino an i2c slave and handshaking via the i2c bus – but that’s just me 😉
Your email address will not be published. Required fields are marked *