Creating menu to control GPIO python script
-
Hello, I am new to RPi and have my RetroPie setup and working well (except as described in a future post). What an impressive system, this RetroPie is !
I now know enough to be dangerous, and I have made a Python script that triggers a GPIO pin that energizes a transistor to light up LED lighting. Occasionally (more often that seldom), the connection gets dropped, or sometimes, I just want to turn the LEDs off.
I would like to make a menu that is accessible, selectable and executable with the game controller while at the RetroPie to select "Game lights on" or "Game light off". (No keyboard attached, nor do I want to go to my PC and use SSH to run the scripts). I was hoping something could be entered via the Optional or Experimental packages. I tried copying my script files into the /opt/retropie/supplementary/runcommand folder to see what would happen, but I did not have permissions. So here I am, at RetroPie forums.
Is something this simple but powerful possible?
-
If you have a shell script to toggle the lights, you can copy the
.sh
file to$RetroPie/retropiemenu
and the script will be available in the RetroPie system in EmulationStation, from where it can be run using the gamepad (like starting a game). -
Albeit a little more complex and dangerous (but you're dangerous, ain't you? ;-) ) but in the end more elegant:
You may want to learn about triggerhappy.
In a nutshell:
Once you know which events your control(s) fire (for example with:thd --dump /dev/input/event1
) you may use "button kung-fu" (read: button combinations) to yield the same. Just make sure to not use any combination which is used in street fighter games. :-DTo bind your button kung-fu to cool actions you may add a
*.conf
file in/etc/triggerhappy/triggers.d
containing as example:# Hotkey+Start+North (Btn X) --> run "halt" BTN_NORTH+BTN_START+BTN_MODE 1 sudo /sbin/halt -p
Change the button combo as needed and add a the full path to the script you want to run. Don't remove the
1
. Restart triggerhappy service.Note: A "feature" of triggerhappy is to have the mode button put at last in order in the config (in my example above), although you press it first to trigger this combination. So in general: the order of buttons in the config is reversed to those actually pressed.
HTH
-
@mitu Thankyou very much ! It is better than I hoped for !
-
@lolonois Thankyou very much. I will keep this in mind !
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.