Please do not post a support request without first reading and following the advice in

Reset GPIO button

  • I've hooked up a no/off button to my rpi3 using this great video (


    Now I'd like to hook up another button to exit an emulator (a reset button) whenever it is pressed. I also run kodi so it should not affect that.

    Any one have any insight or appropriate code that will me realise this dream?

  • @sphirst this thread might get you close.

  • thanks @caver01 for the link! It's not quite what I think I'll need but might be useful to add to my shutdown script.

    Looking at bits and bobs from here there and everywhere, I've botched this code together

    import RPi.GPIO as GPIO
    import time
    import subprocess
    # 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)
    # I'm using GPIO 39 to Ground and GPIO 21 on my rpi3
    GPIO.setup(40, GPIO.IN, pull_up_down = GPIO.PUD_UP)  
    oldButtonState1 = True
    while True:
        #grab the current button state
        buttonState1 = GPIO.input(40)
      # check to see if button has been pushed
      if buttonState1 != oldButtonState1 and buttonState1 == False:"sudo su && pkill retroarch && nohup emulationstation && pkill mupen64plus &", shell=True, 
          stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        oldButtonState1 = buttonState1

    Does this look ok?

  • @sphirst I dunno. I don't know python, but it is not like you will break anything trying it.

    I just thought you should know that there are several discussions active right now on the topic of shutdown scripts. Most of my work recently has been related to the Mausberry circuit, a little PCB that goes on the USB port and hooks into GPIO to trigger safe shutdown. You can do something similar without the circuit, but the Mausberry adds the ability to truly cut power.

    I did not look at the video you linked above, but you might also find a little software package called GPIOnext interesting. This is the evolution of GPIOneer, a GPIO button handler/driver created by mholgatem. I use GPIOneer, but I will be replacing/upgrading. My buttons that use it include volume control as well as safe shutdown.

Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.