
For those struggling with a way to achieve a Safe (software) Shutdown, here is how you can wire the Push Button Power Switch breakout board with any power supply / PSU, using a DPDT sliding switch.
Here is the main product page for the board, but you can buy it many places around the web: https://www.adafruit.com/product/1400
There are also custom-built solutions from Camble designed for AdaFruit's Powerboost model, and Pocket Adventures and Tinkerboy who both have it integrated into their own power supply boards.
... but if you have some of your own power supply boards (the popular generic or "banggood" ones for instance), or just want to do it yourself with a different PSU or whatever... read on...
..
Wiring:
Software:
If you are using RetroPie 4.4 or later, you should only need to add this to the /boot/config.txt file, replacing the ALL-CAPS text with the appropriate GPIO pin number:
Code: Select all
## Safe Shutdown ##
dtoverlay=gpio-poweroff, gpiopin="GPIO_POWEROFF_PIN"
dtoverlay=gpio-shutdown, gpio_pin=GPIO_SHUTDOWN_PIN
You still need the "power off" which I believe exists on all the RetroPie builds, at least back to 4.0:
Code: Select all
## Safe Shutdown ##
dtoverlay=gpio-poweroff, gpiopin="GPIO_POWEROFF_PIN"
At a command prompt, create the file with sudo nano ~/shutdown.py and paste this in, updating for your GPIO pin:
Code: Select all
from gpiozero import Button
from signal import pause
from subprocess import check_call
def doShutdown():
check_call(['sudo', 'poweroff'])
# Button interupts
shutdownButton = Button(GPIO_SHUTDOWN_PIN)
shutdownButton.when_pressed = doShutdown
pause()
and finally add it to startup by using sudo nano /etc/rc.local to edit the script, and add the following before the "exit 0" line:
Code: Select all
python /home/pi/shutdown.py &
Good luck!

.