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

    Want to use USB Controllers and GPIO-Buttons for Hotkeys.

    Scheduled Pinned Locked Moved Help and Support
    pythongpiobuttons gpiopython buttonsraspberry pi 3b
    11 Posts 2 Posters 5.5k 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.
    • O
      opusa
      last edited by

      Hello Everyone!
      First Things first:

      • Raspberry Pi3 B V1,2 2015

      • Using Retropie 4.1, installed from the Image found on https://retropie.org.uk/download/

      • Power: 5.1V 2.5A

      • PullUp Buttons. (Prototypes done and working on Raspbian with Python 2.7.9)

      Well, what I am strugling with right now is this:
      I want to use Buttons over GPIO-Pins for Hotkeys and a Controller/Controllers for the Games.
      The initial Plan is a Pythonscript running in the Background of all of the Emulators and Fronts acting like a "Keyboard" with a Shutdown Function and the Rest of it.
      Basically the Script will be telling the Pi that the F4 Button was pressed if Pin12 gets a Contact and so on...

      What I do not know by now and hope someone can Help me out is this: Where do I put the Script in RetroPie?
      Is there a rc.local and if, where?

      How do I assign the Buttons in a Way they do not interfere with the Controllers?*

      • Script (its all just for a Test that it works, so no Buttons really assigned as by now):
        http://paste.ubuntu.com/23763917/

      Thank you very much!

      1 Reply Last reply Reply Quote 0
      • Capt_MorganCreekC
        Capt_MorganCreek
        last edited by

        I have similiar plan for my project and did some Research how it could work.

        I'd configure a keyboard as a controller (basic SNES setup) and use PyAutoGUI via scripting to simulate button presses if GPIO pin Inputs are detected.

        RetroPie64 - My Nintendo 64 conversion: https://retropie.org.uk/forum/post/55927

        1 Reply Last reply Reply Quote 0
        • O
          opusa
          last edited by

          So, if I understand you correctly: You want to use a Keyboard as a "third" Controller?
          That would do the Trick I think.
          Hardcode the Keyboard as a Controller additional to the others and see if it works.
          But would the RetroPie reset the Controlls after Reboot? If so, can that be stopped?
          I had to remap the Controller after every Reboot sofar...

          1 Reply Last reply Reply Quote 0
          • Capt_MorganCreekC
            Capt_MorganCreek
            last edited by

            Retropie should remember controllers properly if you don't switch up inputs between reboots. I first configured the controllers and then the keyboard.

            RetroPie64 - My Nintendo 64 conversion: https://retropie.org.uk/forum/post/55927

            1 Reply Last reply Reply Quote 0
            • O
              opusa
              last edited by opusa

              Back at it again...
              I'm stuck. The Script runs in Background no Problem.
              But I can't get the Buttons to work. I tried to Remap the Safefunktion in retroarch.conf but it does not do anything. I can however use F4 as Exit out of the Emustation via the GPIO Pins. But all the other Buttons just don't do anything.
              Don't know anywhere else to look in the System. I also tried the Config in the Setup and chose Option (1) for enabeling the Hotkeys without the need of pressing Alt. But still to no avail.
              Anybody any Ideas?

              PS: The Buttons work in Console...

              Capt_MorganCreekC 1 Reply Last reply Reply Quote 0
              • Capt_MorganCreekC
                Capt_MorganCreek @opusa
                last edited by

                @opusa I also had problems using pyautogui, so I searched around and found retrogame by adafruit. It's a litte software that maps GPIO inputs to keyboard presses, so i can save, load, change slots and return to ES via buttons on my N64. I hide 4 buttons where the expansion pack usually sits, RESET returns to ES.

                Retrogame Installation guide

                This thread probalby helps configuring the retroarch.cfg to use only one button instead of a hotkey and button:

                https://retropie.org.uk/forum/topic/2012/universal-emulator-exit-button

                RetroPie64 - My Nintendo 64 conversion: https://retropie.org.uk/forum/post/55927

                1 Reply Last reply Reply Quote 0
                • O
                  opusa
                  last edited by

                  Well. The Script is running. If I assign F4 to one of my own Buttons it kills the RetroPie like a Keyboard would. The Shutdown Button works fine as well. (Regardless if I am in a Game or in the Setupconfig of Retropie or anywhere). With the Xbox360 Controller I can use all the Hotkeys (Select + Button = Something).
                  What I can not do is assign a Function to my buttons to do the same. Means: Press Button to Save, Load ect...
                  I tried messing aroung with the .cfg Files but to no Avail. The only Thing I managed to do was to kill all Hotkeys all together.
                  I tried to rebind the Controllerbuttons to Keyboardbuttons by just changing the Button in the .cfg for the 360 to a Keyboardbutton but that did not work.
                  If I hook up a Keyboard simultaniously with the Controller I can't use the Hotkeys on a original Keyboard neither. Except F4.
                  Somewhat at a loss right now.

                  Saves state,

                  (# input_save_state =
                  (# Loads state,
                  (# input_load_state =
                  ...

                  #input_state_slot_increase =
                  #input_state_slot_decrease =
                  how parts of the retroarch.cfg look like after Changes:

                  -# Saves state,
                  input_save_state = s

                  Loads state,

                  input_load_state = b

                  input_state_slot_increase = q
                  input_state_slot_decrease = w

                  ...

                  input_enable_hotkey = "nul" (tried without anything, no change)
                  auto_remaps_enable = "false" (tried it with true no change)

                  any ideas?
                  thx

                  Capt_MorganCreekC 1 Reply Last reply Reply Quote 0
                  • Capt_MorganCreekC
                    Capt_MorganCreek @opusa
                    last edited by

                    @opusa You need to disable the hotkey button in the cfg, so you can use a single button to trigger the events. If you do that make sure to disable hotkeys on the controller, because nearly every button will trigger some hotkey event.

                    I did this for my controllers and mapped the rgui menu on the centerbutton/psbutton so I can still access important emulator functions without a keyboard.

                    RetroPie64 - My Nintendo 64 conversion: https://retropie.org.uk/forum/post/55927

                    1 Reply Last reply Reply Quote 0
                    • O
                      opusa
                      last edited by opusa

                      I tried all of that. At least I think I did...
                      How do I disable the Hotkeybuttons on a Controller? After I tempered with the .cfgs it stoped working but I am not sure why.
                      Writing this Line in the .cfg File for the Controller would do the Trick? And if, where in the .cfg?
                      input_enable_hotkey = "nul"
                      I tried that but it did not help.
                      Well, since I have Backups I will try from a new again next week.
                      At least I have the Hardware build by now.
                      All in all I belive I made a small Mistake somewhere and stumble over it the entire Time...

                      Capt_MorganCreekC 1 Reply Last reply Reply Quote 0
                      • Capt_MorganCreekC
                        Capt_MorganCreek @opusa
                        last edited by

                        @opusa

                        Hey,

                        this is the content of my retroarch.cfg:

                        http://pastebin.com/2GntsNMH

                        This is where I disabled the hotkeys and mapped them to single keys on the keyboard. Aside from escape I only used letters to avoid any problems. I hope this helps!

                        RetroPie64 - My Nintendo 64 conversion: https://retropie.org.uk/forum/post/55927

                        O 1 Reply Last reply Reply Quote 1
                        • O
                          opusa @Capt_MorganCreek
                          last edited by

                          @Capt_MorganCreek Hey!
                          Thank you very much for the file and the Help!
                          I had to change a little bit in the Script and use now uinput from uinput.
                          I ran into Problems with Dependencies... basically I haven't read thoroughly enough...
                          Everything else in the Script is the same.
                          Software works and the Buttons also... but! I have to make a new Plan on the Hardware itself.
                          It turned out that the Way I wantet to build the entire Thing does not work. It just does not fit...
                          Will have to see when I will have enough Time again to make a new Plan...

                          Big Thanks for the Help!

                          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.