Hello and welcome to this video where I'll show you how to add a shutdown button
to your RetroPie arcade system.
Shutting down RetroPie is usually done using the on-screen menu within Emulation Station.
This is a bit fiddly and not something that's easy to explain to friends or young children.
Adding a shutdown switch makes shutting down the system easy for anyone
and reduces the chances of someone else corrupting your SD card.
To follow this tutorial I'm assuming you've already got an internet connected Raspberry Pi
running the latest RetroPie.
You'll need a momentary action switch.
Choose a design that suits your project and you can mount easily.
Finally you'll need some wires with female pin-headers to connect to the Pi.
Connect the two wires to the switch either with suitable connectors or with solder.
Here I insulated the exposed metal with some heat shrink tubing.
Be careful if you use a naked flame and try not to melt or burn anything.
Connect the other end to Pin 17 and Pin 15 on the Pi's GPIO header.
Pin 17 is 3.3V.
Pin 15 is GPIO22.
You can use another GPIO if you want but you'll have to update the Python script with the new number.
To configure the shutdown script you will need access to the command line.
This can either be done on the Pi with a keyboard connected or remotely using SSH.
Enabling SSH from within RetroPie can be done via the RetroPie configuration menu and selecting Raspi-Config.
Then "Interfacing Options" and finally "SSH".
Complete the confirmation prompts and return to the main RetroPie screen.
Restart the system via the Quit menu and SSH will be enabled.
Please see this blog post for help on enabling SSH within ReptroPie:
https://www.raspberrypi-spy.co.uk/2018/03/how-enable-retropie-ssh-interface/
Once SSH is enabled you need to find the IP address of your Pi.
You can either do this via the RetroPie configuration menu selecting "Show IP"
or look for it in your router settings.
You can then use an SSH client such as Putty on your PC
to connect to your Pi.
My shutdown script uses the GpioZero library which is not installed by default under RetroPie.
To install it type :
sudo apt-get -y install python3-gpiozero
Now make sure you are in the home directory by typing :
cd /home/pi
and then download the script from BitBucket using :
wget and the following URL:
https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/retropie_shutdown.py
If you connected your switch to another GPIO pin you will need to edit this file and change the GPIO number.
You can do this with the nano text editor by typing "nano" and the name of the script.
retropie_shutdown.py
This will launch the script in the editor.
Scroll down to the myGPIO variable and change as required.
I'm going to leave it at the default of 22.
Then press CTRL-X to quit
Y to confirm the file overwrite
followed by ENTER to action.
This script needs to be run automatically when the Pi starts up.
This can be done using the cron task scheduler.
Type : sudo crontab -e
to edit your cron settings.
If prompted selected nano as the default editor.
Add the following line at the bottom :
@reboot python3 /home/pi/retropie_shutdown.py &
Press ENTER after the final & to ensure you end with a blank line.
Press CTRL-X, Y and ENTER to save the crontab.
Check the crontab is correct using :
sudo crontab -l
Cron will now run the script in the background when the Pi starts up.
Reboot the Pi using :
sudo reboot
Your system should start up as normal.
With RetroPie running quit the current game and return to the main menu.
Hold down the button for 6 seconds and wait for the shutdown sequence to start.
Once shutdown, wait 10 seconds and then turn off the power.
[CLUNK]
If you wish to change the number of seconds you have to hold down the button
before it shuts down
you can go back and edit the RetroPie shutdown script
and change the myHoldTime variable
to the number of seconds you require.
Thank you for watching and I hope you found this video useful.
Please subscribe if you are interested in more Raspberry Pi based videos.
