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.

sudo mkdir /opt/scripts && sudo wget -nv -O /opt/scripts/piboot.py  https://raw.githubusercontent.com/munzli/pi/master/piboot.py

this creates and downloads to /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 (optional)

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.

sudo wget -nv -O /etc/systemd/system/piboot.service https://raw.githubusercontent.com/munzli/pi/master/piboot.service

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…

[edit]updated commands to fetch and save scripts, just copy/paste

4 thoughts on “reset/shutdown with the NESPi case reset button

  1. You rock man, this works GREAT! Just did all this on my new pi and it all works flawlessly.
    One question just for my learning.. how does the reset button still power the Pi on after it’s been shutdown ?
    Thanks!
    -Evan

  2. glad you like it…
    to your question: since you’ve only halted the system and the pi still has power (since the power button is on), pressing the reset button will fire a wake-from-halt. this is a feature that is in the pi firmware itself.

  3. Good night and thanks for the tutorial, just a question, what is the nr 5? I do not have it very clear. cheers and thank you again.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.