I implemented a simple script (well, someone else created it, just installed it hehe) to shutdown my raspberry pi when a button is pressed that connects pin 5 and 6 (I think those are the numbers - basically, GPIO3 and the ground next to it).
root@retropie:/home/pi# cat scripts/shutdown.py #!/usr/bin/python import RPi.GPIO as GPIO import time import subprocess GPIO.setmode(GPIO.BOARD) # we will use the pin numbering to match the pins on the Pi, instead of the # GPIO pin outs (makes it easier to keep track of things) # use the same pin that is used for the reset button (one button to rule them all!) GPIO.setup(5, GPIO.IN) oldButtonState1 = True while True: #grab the current button state buttonState1 = GPIO.input(5) #print "Button state: %s" % buttonState1 # check to see if button has been pushed if buttonState1 != oldButtonState1 and buttonState1 == False: #print "Got ya!" # shutdown subprocess.call("shutdown -h -P now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) oldButtonState1 = buttonState1 time.sleep(.5) root@retropie:/home/pi#
This works beautifully to both power down AND wake up the raspberry pi BUT I've noticed it will automatically start by itself with no apparent source / reason / event!
Any ideas on how I can debug what is causing it to wake up? There shouldn't be a bad pin connection to the button, otherwise it would power off while I'm using it. It just seems to randomly turn back on, not off!
I have a wireless keyboard / mouse dongle connected to it BUT the keyboard/mouse are both disconnected (in case that's what was pushing a wake event).
There are also 2 USB joysticks hooked up to it, but I tried waking it up by pressing the buttons and it doesn't seem to do it, so something else must be triggering the wake up!
Probably not related but just noticed this in dmesg:
root@retropie:/home/pi# dmesg | grep -i power [ 0.649860] Init: Port Power? op_state=1 [ 0.649865] Init: Power Port (0) [ 5.770889] brcmfmac: power management disabled [ 6.772418] brcmfmac: power management disabled root@retropie:/home/pi#
Any thoughts on what I should look out for?