Getting the Sleepy Pi to Shutdown the Raspberry Pi

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 shutdown
GPIO 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 shutdown
Monitor 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:

  1. Set GPIO 25 to indicate that we are running
  2. Monitor GPIO 24 for a command to shutdown
  3. When we receive a command to shutdown issue a sudo shutdown -h now command

Setting up the Raspberry Pi Handshaking

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:

To run this script at startup, we must edit the /etc/rc.local

In LXTerminal:

and insert the following line just before the final exit 0 and save changes:

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:

Other Options for Handshaking With Sleepy Pi 2

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 😉

Sleepy Pi2 Solder Jumpers

Sleepy Pi2 Solder Jumpers

Back to Top

Site design & build by FUB Software