RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Reset GPIO button

    Scheduled Pinned Locked Moved Help and Support
    retropiereset buttonexit emulator
    4 Posts 2 Posters 2.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • soggypeteS
      soggypete
      last edited by

      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?

      caver01C 1 Reply Last reply Reply Quote 0
      • caver01C
        caver01 @soggypete
        last edited by

        @sphirst this thread might get you close.

        My 4-player cocktail style cabinet built as a custom "roadcase"

        1 Reply Last reply Reply Quote 0
        • soggypeteS
          soggypete
          last edited by soggypete

          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

          #!/usr/bin/python
          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)
          
          GPIO.setmode(GPIO.BOARD)  
          
          # 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:
              subprocess.call("sudo su && pkill retroarch && nohup emulationstation && pkill mupen64plus &", shell=True, 
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
              oldButtonState1 = buttonState1
          
              time.sleep(.1)
          

          Does this look ok?

          caver01C 1 Reply Last reply Reply Quote 0
          • caver01C
            caver01 @soggypete
            last edited by

            @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.

            My 4-player cocktail style cabinet built as a custom "roadcase"

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            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.