reset/shutdown with the NESPi case reset button

got myself a NESPi case (an awesome case btw!) and after noticing that the reset button just cuts the main power i wanted a correct shutdown/restart solution.

with a bit of code, some soldering and 2 resistors it’s actually quite simple to get going.

first off you need a 150 ohm ¼ watt resistor, a 100 ohm ¼ watt resistor, a bit of stranded wire and a 2.54mm female crimp jumper terminal connector (or a pi GPIO single female connector cable).

remove the top hub with the 2 usb ports and the ethernet port from the NESPi case so that you can reach the circuit with the buttons.

since the GPIO (general purpose input/output) pins on the raspberry pi can only handle 3.3 volts and the usb power on the reset button is 5V, we’ll need a simple voltage divider.

so if Vout = Vin(R2/(R1+R2)) then in our example we’d have 3V = 5V(150R/(100R+150R)) which will work great.

since we want the raspberry pi to always receive power even if the reset button is pressed a small bridge is needed. solder together the pins which are connected while the reset button is not pressed. check the image for more detail.
placing the two resistors in series will divide the voltage and we can use the 3 volts to pass onto a GPIO pin.

if that’s done we can hook up the jumper terminal connector to the GPIO board.
i used pin nr 5, if you change this you need to make sure your script is correct aswell.

if that’s all done let’s boot up the pi and get the scripts going.

download this script from github.

wget https://raw.githubusercontent.com/munzli/pi/master/piboot.py

and move it to a nice place. i used /opt/scripts/.

this script will wait for an interrupt on pin 5 and checks how long the “button” was pressed. it restarts with a short press and if held longer than 3 seconds it shuts down.

make sure you have the gpio python librarys installed

sudo apt-get -y update
sudo apt-get install --yes python-rpi.gpio python3-rpi.gpio

if you’d like to try it just call it with python

sudo python /opt/scripts/piboot.py

to get this to autostart on your pi we can use systemd.
download this file and save it to /etc/systemd/system/.

now enable and run the service

sudo systemctl enable piboot.service
sudo systemctl start piboot.service

use systemctl to check if it’s up and running and test your reset button!

thx to ETA PRIME for the inspiration…