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

    Creating menu to control GPIO python script

    Scheduled Pinned Locked Moved Help and Support
    experimentalpython scriptgpiocontrols
    5 Posts 3 Posters 797 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.
    • LouFL
      LouF
      last edited by

      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?

      Pi#2: 4B-2Gb, 5.10.11-v7l+ firmware, 3A power supply
      RetroPie v. 4.7.1 pre-made SD image, transferred from Pi#1
      Emulation Station v. 2.9.6RP
      RetroArch 1.8.8
      Controller: Vilros SNES wireless USB
      WD easystore HDD - 1TB

      Pi#1: 4B-2Gb, 5.4.72-v7l+

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

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

        LouFL 1 Reply Last reply Reply Quote 1
        • LolonoisL
          Lolonois
          last edited by

          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. :-D

          To 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

          LouFL 1 Reply Last reply Reply Quote 1
          • LouFL
            LouF @mitu
            last edited by LouF

            @mitu Thankyou very much ! It is better than I hoped for !

            Pi#2: 4B-2Gb, 5.10.11-v7l+ firmware, 3A power supply
            RetroPie v. 4.7.1 pre-made SD image, transferred from Pi#1
            Emulation Station v. 2.9.6RP
            RetroArch 1.8.8
            Controller: Vilros SNES wireless USB
            WD easystore HDD - 1TB

            Pi#1: 4B-2Gb, 5.4.72-v7l+

            1 Reply Last reply Reply Quote 0
            • LouFL
              LouF @Lolonois
              last edited by

              @lolonois Thankyou very much. I will keep this in mind !

              Pi#2: 4B-2Gb, 5.10.11-v7l+ firmware, 3A power supply
              RetroPie v. 4.7.1 pre-made SD image, transferred from Pi#1
              Emulation Station v. 2.9.6RP
              RetroArch 1.8.8
              Controller: Vilros SNES wireless USB
              WD easystore HDD - 1TB

              Pi#1: 4B-2Gb, 5.4.72-v7l+

              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.