(SOLVED) Trouble executing exit game/emulator with multi_switch.sh
-
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.
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.
I am using board pin 26 (blue wire) for input and pin 34 (green wire) for GND.
I tried running the script manually and got the following:
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
-
@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
(viasudo
) ?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. -
@mitu I ran with sudo and got the following error:
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.
-
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 thewhile
loop. -
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)
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.