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

    (SOLVED) Trouble executing exit game/emulator with multi_switch.sh

    Scheduled Pinned Locked Moved Help and Support
    multiswitch
    5 Posts 2 Posters 148 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.
    • C
      cjc1972
      last edited by cjc1972

      Hi friends, I am diagnosing why @cyperghost multi_switch.sh script will not execute for me. I am running a RPi3B with Retropie version 4.8.2 and a PowerBlock for shutdown. I am only using the multi_switch.sh for the --ES-CLOSEEMU functionality for exiting a game/emulator with a single button. I am using a basic micro switch as my button. The exitemulator.py script that I am using to call the --ES-CLOSEEMU function is one that I have copied from the forum that apparently worked (https://retropie.org.uk/forum/post/187358)and was written by @mitu. Although there is a bit of script within the exitemulator.py for calling the shutdown function within the multi_switch.sh, I don’t believe that it should be interring with the exit emulator function that I am interested in.

      Script for exitemulator.py script written by @mitu

      #!/usr/bin/python
      import RPi.GPIO as GPIO
      import time
      import subprocess
      
      GPIO.setmode(GPIO.BOARD)
      
      shutdownPin=25
      resetPin=26
      
      GPIO.setup(shutdownPin, GPIO.IN)
      GPIO.setup(resetPin, GPIO.IN)
      
      oldButtonState1 = True
      
      while True:
          #grab the current button state
          buttonState1 = GPIO.input(shutdownPin)
          buttonState2 = GPIO.input(resetPin)
      
          # check to see if button has been pushed
          if buttonState1 != oldButtonState1 and buttonState1 == False:
              # shutdown
              subprocess.call("shutdown -h now", shell=True,
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
              oldButtonState1 = buttonState1
          
          if not buttonState2:
              # Reset emulator
              print "Reset pressed"
              subprocess.call("/home/pi/scripts/multi_switch.sh --es-closeemu", shell=True,
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      
          time.sleep(.3)
      

      I have both the scripts (exitemulator.py and multi_switch.sh) in the /home/pi/scripts folder as can been seen below.

      Script LS picture.png

      I used the following to make it executable:

      chmod +x /home/pi/scripts/multi_switch.sh 
      

      I have both scripts included in the autostart.sh file as can be seen below.

      autostartsh pic.png

      I am using board pin 26 (blue wire) for input and pin 34 (green wire) for GND.

      Pi pic.png

      I tried running the script manually and got the following:

      permission denied.png

      I have spent many hours/days trying to get this to work and any help in getting this up and running is greatly appreciated. Thx

      mituM 1 Reply Last reply Reply Quote 0
      • mituM
        mitu Global Moderator @cjc1972
        last edited by

        @cjc1972 said in Trouble executing exit game/emulator with multi_switch.sh:

        I tried running the script manually and got the following:
        ...

        Have you tried the advice from the error printed - running the script as root (via sudo) ?

        Btw, since you're using a PowerBlock, you can use the PowerBlock scripts to invoke @cyperghost's multi_switch script, instead of the .py script.

        C 1 Reply Last reply Reply Quote 0
        • C
          cjc1972 @mitu
          last edited by cjc1972

          @mitu I ran with sudo and got the following error:

          error.jpg

          After seeing the error I realized that pin 25 for the shutdown pin was a ground so I changed to 24. I executed the script in ssh and it seemed to compile without error. However, this produced a loop of starting and rebooting prior to emulationstation launching. So I am guessing that the script is now being called at autostart.sh and getting either a false signal or the code is creating a loop.

          i have the sd card backed prior to working on this script.

          So, do you see anything in the code that would have caused this? Also, I was thinking of simplifying the code to focus solely on exiting an emulator to avert at least the shutdown loop so that I can determine if there is a larger issue with the Pi's pins? My deduction on the pin concern is I am assuming the existing code in the exit emulator.py is correct and should not be producing the death loop that I got by changing the input pin for the shutdownPin.

          I put together the following, should this work to isolating just the exit feature?

          #!/usr/bin/python
          import RPi.GPIO as GPIO
          import time
          import subprocess
          
          GPIO.setmode(GPIO.BOARD)
          
          resetPin=26
          
          GPIO.setup(resetPin, GPIO.IN)
          
          oldButtonState1 = True
          
          while True:
              #grab the current button state
              buttonState1 = GPIO.input(resetPin)
          
              # check to see if button has been pushed
              if buttonState1 == True:
                  # Reset emulator
                  print "Reset pressed"
                  subprocess.call("/home/pi/scripts/multi_switch.sh --es-closeemu", shell=True,
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
          
              time.sleep(.3)
          

          Thanks for the heads up on shutdown but my shutdown process is working fine and I would be hesitant to adjust unless there was a strategic reason.

          1 Reply Last reply Reply Quote 0
          • mituM
            mitu Global Moderator
            last edited by

            If the 26 pin is always 'on' when started, then you may need to change the 'direction' and trigger the action when it's Low (False).

            Experiment with it and see what value is read when you press the button - just comment the subprocess part and just print the button state in the while loop.

            C 1 Reply Last reply Reply Quote 0
            • C
              cjc1972 @mitu
              last edited by cjc1972

              Update - I adjusted the script and everything is working as it should! Thanks @mitu for your help.

              #!/usr/bin/python
              import RPi.GPIO as GPIO
              import time
              import subprocess
              
              GPIO.setmode(GPIO.BOARD)
              
              resetPin=26
              
              GPIO.setup(resetPin, GPIO.IN, pull_up_down = GPIO.PUD_UP)
              
              #oldButtonState1 = False
              print GPIO.input(resetPin)
              
              while True:
                  #grab the current button state
                  buttonState1 = GPIO.input(resetPin)
              
                  # check to see if button has been pushed
                  if buttonState1 == False:
                      # Reset emulator
                      print "Reset pressed"
                      subprocess.call("/home/pi/scripts/multi_switch.sh --es-closeemu", shell$
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
              
                  time.sleep(.3)
              
              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.