For future reference, this is how i do it on my Pi3
I use a momentary with the input wire on 21 (the last one next to the usb ports, closes to the edge) and the ground on it's mate (next to usb ports, closer to one of the processors, just next to 21) . In my retropie autostart.sh script I call a script (/home/pi/.off-button.py).
Autostart:
/opt/retropie/configs/all/autostart.sh
python /home/pi/.off-button.py &
emulationstation
.off-button.py script:
#!/bin/python
import RPi.GPIO as GPIO
import os
gpio_pin_number=21
# number may be different in other Pi versions. This is for Pi3
# pin must be an input so as to not short the Pi
GPIO.setmode(GPIO.BCM)
GPIO.setup(gpio_pin_number, GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
GPIO.wait_for_edge(gpio_pin_number, GPIO.FALLING)
#Use falling edge detection to see if pin is pulled low to avoid repeated polling
os.system("sudo shutdown -h now")
except:
pass
GPIO.cleanup()
That's the cleanest way I've figured out to setup a power switch. You can do something similar for resets. I don't have a reset button though, so it's not in the script. If anyone needs reference on that I can look it up. I think there are some dedicated pins for power and reset without programming these days, but It's just not what I have set up at the moment
There have been a few times where I wanted to disable the power button (kids)... this way lets me do it from a script instead of disabling hardware.