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.
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 all done let’s boot up the pi and get the scripts going.
download this script from github.
and move it to a nice place. i used
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
download this file and save it to
now enable and run the service
sudo systemctl enable piboot.service sudo systemctl start piboot.service
systemctl to check if it’s up and running and test your reset button!
thx to ETA PRIME for the inspiration…