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

    activer bouton arcade gpio

    Scheduled Pinned Locked Moved Help and Support
    gpiobouton arcade
    31 Posts 3 Posters 1.6k 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.
    • J
      Jimmy14 @Jimmy14
      last edited by

      I noticed a small error (I would even say that it is an incisive detail) but I connected the A player 1 button and it is the B player 1 button which is detected, is this normal or a problem coming from my configuration?

      LolonoisL 1 Reply Last reply Reply Quote 0
      • J
        Jimmy14
        last edited by

        As I explained above, I'm using a TFT screen connected to GPIO in this configuration.
        The problem is that the GPIO connections for Player 1's buttons are identical to four GPIO connections on my screen, and for Player 2, there are two GPIO connections identical to those on the screen. (See diagram above.)

        LolonoisL 1 Reply Last reply Reply Quote 0
        • LolonoisL
          Lolonois @Jimmy14
          last edited by

          @Jimmy14 said in activer bouton arcade gpio:

          I connected the A player 1 button and it is the B player 1 button which is detected, is this normal or a problem coming from my configuration

          This is not specific to your configuration. The assignment could be flipped in the *.dts source files (or in RetroArch in upper software layer), but don't go that way (yet) - see my next answer on your next post.

          1 Reply Last reply Reply Quote 0
          • LolonoisL
            Lolonois @Jimmy14
            last edited by

            @Jimmy14 said in activer bouton arcade gpio:

            As I explained above, I'm using a TFT screen connected to GPIO in this configuration.

            That is what we will handle now.
            Apologies, if I took the long road, but first I wanted to assure that a simple setup with one joystick works.

            So, as the TFT display uses pins from both joysticks and you can not dual-use a GPIO pin for two devices, I see two options:
            One will take a little more space, the other takes less space but needs more fiddling in the *.dts files.

            Option 1:
            Get two MCP23017 (port expander) on a breakout board, they will use I2C (simple but effective wire protocol) instead of one GPIO port per Button/Direction. Daisy-chain them as I outlined on the Arcade DT project site. The MCP will use the I2C ports of the Raspberry Pi (GPIO2 and GPIO3), which are unused by the TFT. Wire the buttons to the MCP and use the configuration in config.txt instead of the gpio-joystick entry:

            # two MCP 23017 connected joysticks, the second with: I2C address 0x21, IRQ on GPIO17
            dtoverlay=gpio-mcp-joystick,joy1
            dtoverlay=gpio-mcp-joystick,joy2,addr=0x21,gpiopin=17
            

            This should work as GPIO4 and GPIO17 are not used by the TFT display.

            If you wire/solder some MCP pin to the "wrong" BTN function you can change the MCP ports to the BTN function in this file. However any changes there need a recompile/re-install and re-boot.

            Option 2:
            Use one Joystick directly on GPIO and one via an MCP23017. I would go only this path if space is a absolute premium in your Arcade build.

            It also requires that you only use spare GPIO ports which are neither used by the TFT (thus not GPIO 18,27,10,11,25,8) nor by the MCP23017 (thus not GPIO 2,3,4).

            The GPIO ports for Joystick 1 via GPIO should then be entered in
            this brcm,pins line, also altered in fragment@3 in the up, down, left, ... sections that each GPIO from fragment@1 (brcm,pins) is used exactly once.

            Additionally the Hotkey configuration in fragment@5 and fragment@7 should be adjusted to a spare GPIO (as the currently defined GPIO 2 is needed for I2C and MCP).

            Eventually I would remove any even fragment@ (2,4,6,8) entry and anything that relates to joystick2 in gpio-joystick.dts (as joystick 2 will be addressed via MCP).

            That said, I guess using two MCP is the easier option.

            Hopefully, my answer is not too confusing. If something is not understood please let me know.

            J 1 Reply Last reply Reply Quote 0
            • J
              Jimmy14 @Lolonois
              last edited by

              @Lolonois
              Since space is a critical factor for my arcade project (transforming a Nintendo NES controller into a portable game console with a small integrated TFT screen), I'd prefer to use the option where I modify the GPIO ports.
              I only need to configure player 1; player 2 is useless.
              Without wasting your time, you might not have a gpio-joystick.dts file, or at best, a gpio-joystick.dtbo file that matches my configuration. 😅
              I'm not sure I'll be able to properly modify and compile the gpio-joystick.dts file to match my configuration. 🤣
              Thanks.

              1 Reply Last reply Reply Quote 0
              • J
                Jimmy14
                last edited by

                I deleted the .dtbo files that were created during installation in the arcade-dt and overlays folders, then I modified the gpio-joystick.dts file (see below), then I ran the command:
                sudo make install
                It created a gpio-joystick.dtbo file in the overlays folder, but when I run the command: evtest, I don't get the gpio arcade joystick 1 option to test the buttons.

                ''' /*

                • Device Tree Source for GPIO connected arcade controllers.
                • Supports up to two controllers with max 13 buttons each.
                • Copyright (c) 2024 Gemba @ GitHub
                • SPDX-License-Identifier: GPL-2.0-only
                  */

                #include <dt-bindings/input/linux-event-codes.h>
                #include <dt-bindings/gpio/gpio.h>

                /dts-v1/;
                /plugin/;

                / {
                compatible = "brcm,bcm2835", "brcm,bcm2712", "brcm,bcm2711", "brcm,bcm2710", "brcm,bcm2709", "brcm,bcm2708";

                fragment@1 {
                    target = <&gpio>;
                    __dormant__ {
                        button_pins1: button_pins1 {
                            /* joy1:     up dn le ri st sl tl  x  y tr  a  b */
                            brcm,pins = < 4 17  6 22 19  9 14 15 12 23 24 21>; /* GPIO port numbers */
                            brcm,function = <0>; /* all input */
                            brcm,pull = <2>; /* all pull up */
                        };
                    };
                };
                
                fragment@2 {
                    target-path = "/";
                    __dormant__ {
                        gpio-joy1 {
                            compatible = "gpio-keys";
                            label = "GPIO Arcade Joystick 1";
                            status = "okay";
                            pinctrl-names = "default";
                            pinctrl-0 = <&button_pins1>;
                            /* cf. https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h */
                            up1: up {
                                linux,code = <BTN_DPAD_UP>;
                                gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
                                label = "BTN_DPAD_UP";
                            };
                            down1: down {
                                linux,code = <BTN_DPAD_DOWN>;
                                gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
                                label = "BTN_DPAD_DOWN";
                            };
                            left1: left {
                                linux,code = <BTN_DPAD_LEFT>;
                                gpios = <&gpio 6 GPIO_ACTIVE_LOW>;
                                label = "BTN_DPAD_LEFT";
                            };
                            right1: right {
                                linux,code = <BTN_DPAD_RIGHT>;
                                gpios = <&gpio 22 GPIO_ACTIVE_LOW>;
                                label = "BTN_DPAD_RIGHT";
                            };
                            start1: start {
                                linux,code = <BTN_START>;
                                gpios = <&gpio 19 GPIO_ACTIVE_LOW>;
                                label = "BTN_START";
                            };
                            select1: select {
                                linux,code = <BTN_SELECT>;
                                gpios = <&gpio 9 GPIO_ACTIVE_LOW>;
                                label = "BTN_SELECT";
                            };
                            tl1: tl {
                                linux,code = <BTN_TL>;
                                gpios = <&gpio 14 GPIO_ACTIVE_LOW>;
                                label = "BTN_TL";
                            };
                            x1: x {
                                linux,code = <BTN_X>; /* BTN_NORTH */
                                gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
                                label = "BTN_X";
                            };
                            y1: y {
                                linux,code = <BTN_Y>; /* BTN_WEST */
                                gpios = <&gpio 12 GPIO_ACTIVE_LOW>;
                                label = "BTN_Y";
                            };
                            tr1: tr {
                                linux,code = <BTN_TR>;
                                gpios = <&gpio 23 GPIO_ACTIVE_LOW>;
                                label = "BTN_TR";
                            };
                            a1: a {
                                linux,code = <BTN_A>; /* BTN_SOUTH */
                                gpios = <&gpio 24 GPIO_ACTIVE_LOW>;
                                label = "BTN_A";
                            };
                            b1: b {
                                linux,code = <BTN_B>; /* BTN_EAST */
                                gpios = <&gpio 21 GPIO_ACTIVE_LOW>;
                                label = "BTN_B";
                            };
                        };
                    };
                };
                
                fragment@3 {
                    target = <&gpio>;
                    __dormant__ {
                        hotkey_pin1: hotkey_pin1 {
                            brcm,pins = <2>;
                            brcm,function = <0>;
                            brcm,pull = <2>;
                        };
                    };
                };
                
                fragment@4 {
                    target-path = "/";
                    __dormant__ {
                        gpio-joy1 {
                            compatible = "gpio-keys";
                            status = "okay";
                            pinctrl-names = "default";
                            pinctrl-0 = <&button_pins1>, <&hotkey_pin1>;
                            hk1: hotkey {
                                linux,code = <BTN_MODE>;
                                gpios = <&gpio 2 GPIO_ACTIVE_LOW>;
                                label = "BTN_MODE";
                            };
                        };
                    };
                };
                
                
                __overrides__ {
                    /* odd fragments for joystick 1 */
                    joy1        = <0>, "+1+3";
                    joy1-hotkey = <0>, "+5+7";
                
                
                    /* per dtparam overwriteable */
                    /* joy1 */
                    up1     = <&button_pins1>, "brcm,pins:0",
                              <&up1>, "gpios:4";
                    down1   = <&button_pins1>, "brcm,pins:4",
                              <&down1>, "gpios:4";
                    left1   = <&button_pins1>, "brcm,pins:8",
                              <&left1>, "gpios:4";
                    right1  = <&button_pins1>, "brcm,pins:12",
                              <&right1>, "gpios:4";
                    start1  = <&button_pins1>, "brcm,pins:16",
                              <&start1>, "gpios:4";
                    select1 = <&button_pins1>, "brcm,pins:20",
                              <&select1>, "gpios:4";
                    tl1     = <&button_pins1>, "brcm,pins:24",
                              <&tl1>, "gpios:4";
                    x1      = <&button_pins1>, "brcm,pins:28",
                              <&x1>, "gpios:4";
                    y1      = <&button_pins1>, "brcm,pins:32",
                              <&y1>, "gpios:4";
                    tr1     = <&button_pins1>, "brcm,pins:36",
                              <&tr1>, "gpios:4";
                    a1      = <&button_pins1>, "brcm,pins:40",
                              <&a1>, "gpios:4";
                    b1      = <&button_pins1>, "brcm,pins:44",
                              <&b1>, "gpios:4";
                    hk1     = <&hotkey_pin1>, "brcm,pins:0",
                              <&hk1>,"gpios:4";
                };
                

                };
                '''

                LolonoisL 1 Reply Last reply Reply Quote 0
                • LolonoisL
                  Lolonois @Jimmy14
                  last edited by

                  @Jimmy14 pretty close. I was just about to provide you an example *.dts but I see you did it already by yourself. Chapeau!

                  For your question:
                  I assume the fragment@NN and the numbers in __overrides__ are not aligned in your implementation:

                  These two lines (joy1, joy1-hotkey) below must match the fragment@NN numbers in the *.dts:

                  Currently you have:

                  __overrides__ {
                      /* odd fragments for joystick 1 */
                      joy1        = <0>, "+1+3";
                      joy1-hotkey = <0>, "+5+7";
                  

                  But it should read as:

                  __overrides__ {
                      joy1        = <0>, "+1+2";  /* fragment@1 and fragment@2 */
                      joy1-hotkey = <0>, "+3+4";  /* fragment@3 and fragment@4 */
                  

                  Which means for the device tree parser: If in config.txt the joy1 is set then do load fragments one and two, and if joy1-hotkey is set in config.txt do load fragment three and four, which should be defined already in the dts file.

                  If they can't be found they are silently not loaded, unless you have set dtdebug=1 in your config.txt and examine the log with sudo vclog -m after reboot.

                  Hope this helps.

                  J 1 Reply Last reply Reply Quote 0
                  • J
                    Jimmy14 @Lolonois
                    last edited by

                    @Lolonois

                    It's okay, it works ☺️ I managed to change the GPIO ports for the keys, which were the same as those on the screen.
                    Now that I've more or less figured out how it works, I'm going to install arcade-dt on my real Retropie setup and finish assembling my project 😉.
                    If there's any problems, I'll come back and bother you a bit to figure out what's wrong, otherwise I'll come back and post the final rendering anyway.
                    Thanks for your help.

                    LolonoisL 1 Reply Last reply Reply Quote 0
                    • J
                      Jimmy14
                      last edited by

                      Do you have any ideas on Retropie with a Raspberry Pi Zero on how to get a sound output from the GPIOs? Thanks

                      LolonoisL 1 Reply Last reply Reply Quote 0
                      • LolonoisL
                        Lolonois @Jimmy14
                        last edited by

                        @Jimmy14 said in activer bouton arcade gpio:

                        It's okay, it works ☺️

                        Cool. :)

                        1 Reply Last reply Reply Quote 0
                        • LolonoisL
                          Lolonois @Jimmy14
                          last edited by

                          @Jimmy14 Getting off-topic here but as a starter:

                          You may want to use something like the PAM8302 and then use audremap in the config.txt

                          I have not been down that road but the information in the refenced pages should get you started.

                          Feel free to start a new thread here, but I assume in the Raspberry Pi forums you will have more guys which may have dealt with it already.

                          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.