@reboot python3 /home/pi/retropie_shutdown.py &
Press CTRL-X, y and ENTER to save the crontab.
You should be returned to the command line. Check the contents of crontab using :
sudo crontab -l
Make sure the name of the script matches the script you downloaded and that you included the “&” symbol at the end.
Finally with the button connected to the GPIO header and the script ready you can reboot using:
or using the RetroPie system menu and selecting “Quit” > “Shutdown System”.
When the system reboots you should see your RetroPie interface as expected. Press and hold the RetroPie Shutdown button for six seconds and the Pi should start shutting down.
You are now free to turn off the power.
Customising the Python Script
Editing the script will allow you to easily change the number of seconds that the button must be held before it triggers a shutdown. The default is 6 seconds. You can also change the GPIO number if your switch is connected to a different header pin.
Simply edit the script using your favourite text editor and change the “myGPIO” and “myHoldTime” variables.
For example, using nano type :
make your changes and then use CTRL-X, Y and ENTER to save and exit. Don’t forget to reboot for the changes to take effect.
My Arcade Table Shutdown Button
Here are some photos of my arcade shutdown button which I fitted to my arcade table.
An illuminated switch is a nice touch as it makes it easier to find in a darkened room.
Finally if the button isn’t working as expected here are some things to consider :
- Check the button wiring. Are you connecting the correct GPIO pin through the switch to 3.3V?
- Did you install GpioZero?
- Is the script located in the /home/pi directory?
- Did you modify and check the crontab entry? Is it pointing to the script in the correct directory?
- If you are not using GPIO22 did you edit the script and update the GPIO reference?