Launching Specific ROMs/EMUs from dedicated buttons
-
Hey everyone!
Background:
I was talking about video games and their benefits on brains. My partner's elderly father has limited motor movement and at his age, it's important to keep his brain exercised. So what better to keep the brain going strong with games such as:
- Pinball (for reactions)
- Racing (for reactions, short-term planning and hand-eye coordination)
- Chess (for planning)
- Solitaire (for organisation)
- Pool (for visual prediction)
- Golf - for ...erm... golf!
Having a couple of monitors, some PIs and access to other materials, I decided to build him an arcade with just 6 carefully selected games.
Before I got to building, I took to a RetroPie page on facebook where I enquired as to whether it was possible to be able to have 6 buttons at the side that are listened to in a script that runs in the background, and on detection of the button press, do the following:If no game running then run game/emu associated with the pressed button else: exit game run game/emu associated with the pressed button
This question was received well and was told by a few people that it was a great idea and definitely possible. I'd searched everywhere I could to find some code to help with this, as I really wanted to get this part of it nailed before I built the thing, but I couldn't find anything - just bits and pieces that I could maybe cobble together, using bits of 'safe shutdown button' scripts and the bash commands. Excited for the project and knowing that it could be done, I went ahead and got designing - the dedicated rom buttons could surely be sorted out later; "I'll cross that bridge when I come to it"...
Pushing Onward
I designed a lightweight but strong mini cabinet with a really basic layout. Instead of the usual 4/6/8 buttons you get on single-player arcade cabinets, it's just Start, Select, Joystick, 2 side buttons for pinball and one giant button. During this time I had been testing loads of games/systems to see which games can be played (without advanced controls) with just 1 button - you'll be surprised but I managed to do this with success! I changed the per-rom config for each rom and they're all saved.
I've now built it and am really happy with it, and he's going to love playing all games using the joystick and the big button. However I am now standing at 'the bridge' that I have now finally come to cross, except I don't know how to move my legs.
I've not programmed/coded anything since the 1990s and even then that was on an old Sinclair Spectrum +3 and that was before the days of script-calling and libraries etc, so I'm quite stuck.
Where I'm at now, with my limited knowledge:
I am able to manually launch the 6 games from bash (after pressing F4 to get to the terminal(?)) which I guessed was the first thing to work out. The commands are:
Crue Ball (MegaDrive) lr-picodrive
/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ megadrive "$HOME/RetroPie/roms/megadrive/Crue Ball - Heavy Metal Pinball (USA, Europe).md"
Side Pocket (Megadrive) lr-picodrive
/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ megadrive "$HOME/RetroPie/roms/megadrive/Side Pocket (USA).md"
Virtua Racing Deluxe (32X) lr-picodrive
/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ sega32x "$HOME/RetroPie/roms/sega32x/Virtua Racing Deluxe (32X) (U) [!].32x"
Neo Turf Masters (MAME) lr-mame2000
/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ mame-libretro "$HOME/RetroPie/roms/mame-libretro/turfmast.zip"
Solitaire (NES) lr-fceumm
/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ nes "$HOME/RetroPie/roms/nes/Solitaire (USA) (Unl).nes"
The Chessmaster (NES) lr-fceumm
/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ nes "$HOME/RetroPie/roms/nes/Chessmaster, The (USA).nes"
I'm also aware that I need a script to run on startup. I took a script from Clinton at Core Electronics and modified it after reading the replies and changes to Python since the tutorial had been written. It also only contains 1 button/rom until I get it working, when I can then add the other buttons/roms. It is called
buttons.py
and is stored in$HOME/RetroPie/roms/Scripts/
and I've toldrc.local
to run it with the&
symbol to run in the background.from gpiozero import Button #import button from the Pi GPIO library import time # import time functions import os #imports OS library for Shutdown control gameButton = Button(23) # defines the button as an object and chooses GPIO 23 while True: #infinite loop if gameButton.is_pressed: #Check to see if button is pressed time.sleep(1) # wait for the hold time we want. if gameButton.is_pressed: #check if the user let go of the button os.system("/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ megadrive '$HOME/RetroPie/roms/megadrive/Crue Ball - Heavy Metal Pinball (USA, Europe).md'")
When run this way, pressing the gamebutton doesn't do anything when in the ES GUI and so I have to press F4 to get to the command line, only then the script detects the button and the 'runcommand' grey box appears telling me the usual 'press a button to configure rom'... but when it disappears after no button press, the screen goes blank apart from a blinking cursor, and the excitement goes away.
I did notice some brief text appear at the bottom and so I captured this on my phone, in slo-mo. I can see that it says:
[ 310.975317] rc.local[677]: /opt/retropie/supplementary/runcommand/runcommand.sh: line 1213: /dev/tty: No such device or address [ 310.978024] rc.local[677]: /opt/retropie/supplementary/runcommand/runcommand.sh: line 145: kill: (2250) - No such process [ 312.124325] rc.local[677]: /opt/retropie/supplementary/runcommand/runcommand.sh: line 1255: /dev/tty: No such device or address
I guess my questions are:
- Is rc.local the right way to launch
buttons.py
at startup? - Is the line within
buttons.py
script that launches the rom (via os.system) correct? - How do I make the script work in the GUI (not that important, don't really need the GUI)
- What do I need to add to the script to make it more like:
When button (1-6) is pressed Check to see if a game is currently running If no game running then run game/emu associated with the pressed button else: exit game run game/emu associated with the pressed button
I would really appreciate/welcome any help with finishing this project, I feel so close yet so far and I am aware that I'm an idiot for not having this part sorted out before cutting my first sheet of plywood!
Many thanks,
Scottps Raspberry Pi 3, running RetroPie v4.6, Raspbian GNU/Linux 9.13 (stretch)
-
@Cottmonter said in Launching Specific ROMs/EMUs from dedicated buttons:
Is rc.local the right way to launch buttons.py at startup?
No, that's not the right place and it's probably why you get the errors you posted.
Is the line within buttons.py script that launches the rom (via os.system) correct?
The
runcommand
lines are correct, you can use them to launch a game directly. You can probably hide the launch menu by configuringruncommand
and disabling it.How do I make the script work in the GUI (not that important, don't really need the GUI)
There's no method right now to hide the gui and launch the game - EmulationStation will 'minimize' only when launching a game/menu item from itself, doesn't know about external programs.
What do I need to add to the script to make it more like:
You can probably use your existing script, adding an extra command when the button is pressed, before the emulator launch line (
os.system
). The command should runkillall retroarch
to stop the current emulator, but you should probably check the button pressed, so you don't stop the current game and start it again (i.e. remember the button that was previously pressed).To run it, just add the script in
/opt/retropie/configs/all/autostart.sh
, instead of/etc/rc.local
and comment the line that's starting EmulationStation.You can also start a minimal
dialog
script that would show a text at boot, instead of the GUI, waiting for a button press that would start an emulator./home/pi/RetroPie/roms/Scripts/buttons.py 2>/dev/null & while true; do dialog --title "Game ON" --infobox " Choose a game by pressing a button\n\n 1.SOLITAIRE\n 2.PINBALL" 15 50; sleep 10; done # Commented out EmulationStation auto-start # emulationstation #audo
-
Hi Mitu,
Thank you so much for getting back to me about this. From the small knowledge I seem to have learnt from looking through hundreds of other posts, what you have said looks like it make logical sense and I can't wait to try your suggestions!
Thanks again!
-
Experiment away - if you have any questions don't hesitate to ask.
PS. No Pacman ?
-
Hi Mitu, just wanted to say thank you for your help!
I added the code to autostart.sh as you said.
At first I'd not realised that I'd missed the word 'Python' when trying to run buttons.py haha. I then replaced the infobox with a .PNG file by using FBI. It works exactly as I'd hoped and he can change game by just pressing the game button!
Thanks again!
-
@mitu I forgot to mention - we looked at PacMan but unfortunately it's too fast-paced and unforgiving for his disability which impedes his reaction time, so I don't think he'd find it much fun. However I might try it with him and manually load it up next time I visit :)
-
Glad you got it working and thank you for the photos - the barcade looks really nice.
-
I just want to say grats and I am a little jealous of your bartop. I am a Campbell, too.
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.