The RetroPie GPIO Adapter

If you want to use your Raspberry Pi for gaming you certainly want to attach some sort of controller(s) to it. Since the Raspberry comes with two USB ports one way would be to simply attach any sort of USB gamepad or joystick via these ports to it. Besides the configuration this approach has the disadvantages that one or both USB ports become occupied and, what I think is even more disturbing, that an active USB hub might become necessary to provide enough energy to the controller(s). Also, if you want to get the real retro feeling you certainly want to use original controllers. The GPIO pins of the Raspberry allow the communication with all sorts of hardware and attaching, for example, SNES controllers can be done in quite a few steps. A user-space program that polls the controller(s) in the background was presented here. In the following I am presenting a dedicated GPIO adapter for the Raspberry Pi that allows an easy and safe connection of up to two NES or SNES controllers.

 

 

The RetroPie GPIO adapter

Based on the experiences with a previously presented adapter PCB I designed a new SNES adapter PCB specifically for the use with the Raspberry Pi.

Hardware

This GPIO adapter aims at

  • an easy and practical installation
  • as well as providing circuitry protection
  • and a button that can be used arbitrarily by software.

An easy and practical installation of the adapter board is achieved by using a 2×13 pins female header for a connection to the GPIO pins and 2×5 pins male header for the connection to, for example, (S)NES controller sockets. The only tinkering needed for a connection to (S)NES connectors is the soldering of the ribbon cable to the connectors. The size of the adapter PCB is only 0.91 in x 1.32 in (23 mm x 33.5 mm). This size does not increase the needed overall volume of the Pi much and allows the usage of most existing cases.

For a practical application the adapter is provided with a circuitry protection as it was proposed in a thread of the official Raspberry Pi forum. To handle over currents a resettable fuse is put on the supply rail. Possible transients are taken care for by a buffer IC 74HC125. As stated by RPi wiki site about circuitry protection

these ICs provide an in-line connection which is buffered via an internal transistor switch to isolate the input from the output.

Four GPIO pins, which would correspond to two data lines, the clock, and the latch in case of (S)NES controllers, are buffered by the adapter.

A momentary on push button is also part of the adapter board. The button is also connected to one of the GPIO pins and, thus, the status of the button can be polled with any suitable software. This allows, for example, to add a reset/back button that is needed with a keyboard-less setup and controllers with no redundant buttons like the SNES or NES controllers.

Pin Out

GPIO pin out: The pin out of the board to the female 2×13 pins header is matched to the gamecon GPIO driver that can also be installed and configured from within the RetroPie Setup Script. The exact pin out together with the according pins on the SNES connector are listed in the following and shown in the diagram (for revision 1 of the Raspberry Board):

  • VCC (3.3V): pin 1
  • Ground: pin 6
  • Clock: pin 19 (out)
  • Button: pin 11 (in)
  • Latch: pin 23 (out)
  • Data 1: pin 7 (in)
  • Data 2: pin 5 (in)

Connectors pin out for (S)NES connectors: The (S)NES connectors are soldered to a 10-wire ribbon cable that has a 2×5 pins female ribbon crimp connector at the other end. The pin out together with the according pins on the SNES connector are shown in the diagram:

Here is an image of two SNES connectors soldered to the ten-wire ribbon cable and connected to the adapter board:

Schematics and assembly Guide: You can find the schematics of the RetroPie GPIO Adapter here. An assembly guide can be found here.

Software

In order to use the RetroPie GPIO adapter a driver is needed that reads the states of the controllers and the button and maps these to the input system of the operating system. This can either be done in kernel- or in user-space. The SNESDev software is an example of an user-space application that interfaces with the controllers. The mentioned gamecon driver is an example that runs in the kernel-space. I have modified the sources of SNESDev such that it can be used with the RetroPie adapter.

With respect to the slightly changed GPIO pin out of revision 2 of the Raspberry, the software has to be matched to the actual revision of each board. In the recent version of the RetroPie Setup Script, the installation and update routines for the gamecon GPIO driver automatically determine the board revision and adapt the configuration of the driver accordingly. Many thanks go to “Marqs” for this!

During the design of the board I was not aware of the “safe mode” of the Raspberry Pi: Adding a jumper between pins 5 and 6 of P1 results in /boot/config.txt being ignored (except for avoid_safe_mode) and a default cmdline.txt is applied, followed by loading kernel_emergency.img. As stated in the official forum

if you connect external hardware to that pin, the worst that will happen is it falsely triggers safe mode.

To avoid this safe mode when the adapter is attached a setting has to be made in /boot/config.txt. This could be done, for example, by opening the config.txt with

sudo nano /boot/config.txt

adding

avoid_safe_mode=1

and saving the changes with “Ctrl-X”, which has to be confirmed with “Y”.

Demo video

A video of the adapter in action can be found in this post.

Installation and Troubleshooting

First of all make sure that you do not have any short bridges or any other possibly problematic parts you soldered. A multimeter could be very handy here. Also, check, if you soldered the tri-state buffer with the correct orientation on the PCB. As stated in the assembly guide: “Pin 1 must be directed towards the fuse holes.”

The software part: Make sure that you are using the latest revision of the sources. If you are going to use the gamecon driver for polling the game pads (which I also prefer, because it is more resource efficient) you need to use the “poll only the button” option for SNESDev. Otherwise the gamecon driver and SNESDev might interfere and lead to some strange behavior.

With the gamecon driver enabled you can test for working connections between the game pads and the RPi with the jstest command (Ctrl+C exits the tool):

jstest /dev/input/js0

and

jstest /dev/input/js1

will test the first and the second game pad.

If you are using SNESDev for polling the game pads you need to use the option “poll game pads and button” in the menu of the RetroPie Script. If everything ism assembled and set up correctly button presses on the game pads will act as keyboard input and you will see according outputs on the console.

A long press (more than 1 second) on the button will lead to a key press of “r” which, again, can be checked on the console.

Conclusion & Getting it

The RetroPie GPIO adapter allows an easy and practical connection of NES and SNES controllers via the GPIO pins of the Raspberry Pi. The size of the adapter is kept as small as possible and should fit into most existing cases. It contains circuitry protection against over currents and transients. Furthermore, a momentary push button is installed on the adapter that can be used, for example, as a back or reset button. The pin out of the GPIO male header is matched to the already existing gamecon RPi GPIO driver, which can easily be installed and updated with the RetroPie Setup script.

I have some of the RetroPie GPIO adapters on hand. If you would like to buy one (only the components and the board for self-assembly or fully assembled and tested) please have a look here. Besides the adapter itself, it comes together with a ribbon cable (about 10 cm long) and a ribbon crimp connector.

 

Advertisements
This entry was posted in microelectronics fun and tagged , , , , , , . Bookmark the permalink.

93 Responses to The RetroPie GPIO Adapter

  1. Daniel S. says:

    Florian… your work is amazing.

    MACH WEITER SO! 🙂

  2. Pingback: SNESDev-RPi: A SNES-Adapter for the Raspberry Pi | petRockBlog

  3. Pingback: The RetroPie GPIO Adapter #piday #raspberrypi @Raspberry_Pi « adafruit industries blog

  4. Pingback: Video of RetroPie GPIO Adapter | petRockBlog

  5. Bleketas says:

    Hi, could you provide a schematics of your new board? I would like to adopt it to psx controller.
    Thanks

    • Florian says:

      Hi, thanks for your interest!
      Good idea – I will provide the schematics this evening.
      Following SPI, two PSX controllers would need GND, 3.3V, MISO (in), MOSI (out), CLOCK (out), SS1 (out), and SS2 (out) – or do I miss something here?

      • Bleketas says:

        Thanks, I’ll wait for schematics, and still waiting for my controllers to arrive, then I will analyze what has to be done to connect them. Will definitely share my findings.

  6. Jeremiah says:

    I am incredibly interested in trying this out, but I did have a concern. Firstly, I am fairly new to electronics and am probably missing something so feel free to call me stupid. I wanted to set up a RetroPie box with my raspberry pi, but in addition, I would like to display the system being emulated as well as the game being played with http://adafruit.com/products/399. My concern is that, your adapter takes up all of the GPIO pins, but doesn’t use them all. Is there a way the extra GPIO pins or am I just being ridiculous?

    • Florian says:

      Hi Jeremiah, thanks for your interest! No worries – asking these kinds of questions is one way of learning.
      You have a point that the 2×5 pins header only breaks out the pins needed for polling two controllers. With a little tinkering the other pins could be accessed by desoldering the desired pins on the PCB-side of the 2×13 pins header first, and then solder whatever you like to these pins. In this way you would at least have a possibility to access the other pins (without circuitry protection though).
      personally, I have not practical experience with LCDs connected to the RPi, but I would try and go for an I2C adapter for the LCDs that are also sold by Adafruit. Synchronizing the displayed game on the LCD with the game that you are currently running on the RPi might be another problem that I would like to have (theoretically) solved before starting to design the hardware for it.
      Hope that helps?

  7. Pingback: Many Raspberry Pi projects - How can you not love a tiny computer? - Scott Hanselman

  8. Loren says:

    Hello! I am interested in how you wired and configured your “momentary push button”. You mentioned that the “button is also connected to one of the GPIO pins and, thus, the status of the button can be polled with any suitable software”. But what GPIO pin is this? Is it GPIO 17 or P1-11 on the RPi? What other configuration / software changes were needed to enable this?

    I have your retropie script installed with NES emulator working fine with the gamecon drivers installed, with the controller configuration of two NES to USB adapters working in retroarch. I have a momentary switch wired with a pull down resistor to the GPIO 17 (P1-11) and I am not getting the ./retroarch-joyconfig to recognize the button nor is emulation station recognizing the escape key when input_exit_emulator_btn = “btn#” is added to /etc/retroarch.cfg. I am not sure what button to replace “btn#” with or if I have the full configuation setup to sense this button.

    Any help would be appreciated!

    • Florian says:

      Hi! Yes – the button is wired to GPIO 17 (P1-11). As far as I know tetrarch-joyconfig looks for /dev/input/jsX devices (joysticks,gamepads, etc.) and is not any help here. Also, the gamecon driver is intended to poll Nintendo controllers that are wired to the GPIOs according to the pin out described above. Thus, it is not used if you are using USB drivers and you can disable it (remove or comment it in /etc/modules).
      One way of polling the button on pin P1-11 is to use SNESDev, which can also be installed with the RetroPie Script. Select source-based installation and deselect everything except the BCM library and SNESDev. Afterwards, you can enable SNESDev in the setup menu. From that menu you can also configure SNESDev to poll only the button.

      I hope that helps!?

      • Loren says:

        Thanks for the Florian!

        I enabled SNESDev in the retro-pie setup script but I do not see where I can configure the SNESDev to poll only the button. Could you provide more details as to where this is?
        Thanks!

      • Daniel says:

        I am curious and clueless at the same time: what is this button used for anyway?

      • Florian says:

        If you use the button in combination with, e.g., RetroArch and SNESDev, a three-state automaton is implemented:

        – press and hold: send “r” key (for rewind function of RetroArch)
        – press and release three times: send “ESC”
        – press and release five times: shutdown

        This allows a keyboard less setup. I plan to post a demo video for these functions soon.

      • Florian says:

        Maybe you have to update your RetroPie script. Just cd to the RetroPie-Setup directory and run “git pull”. You also need to have the latest SNESDev version. You can install it (together with the BCM library) via the source-based setup.
        The latest version of the RetroPie Setup Script allows you to start SNESDev with different arguments (1, 2, or 3). I also just updated the README.md of SNESDev in the repository and updated information about the button usage.

  9. Dennis says:

    Hi, it’s me again… and I hope that my question isn’t again answered anywhere on this blog… :-/

    Anyhow, I have done the following steps:
    1. Started RetroPie-Setup
    2. Option 2 Source Based Install
    3. Options 1-11 enabled / 12-24 disabled / 25 enabled / 26 – 29 disabled / 30-34 enabled (I enabled everything except the emulators, I only chose the SNES emulator as I only want to emulate that)
    4. Reboot after installatoin (just to be sure…)
    5. Entered RetroPie-Setup again
    6. Option 3 Setup
    7. Start SNESDev on Boot -> Option 2 -> Polling pads and button
    8. Install/Update multi/console gamepad driver for GPIO
    9. Enable gamecon_gpio_rpi with SNES-pad config
    10. Reboot

    But: SNES Controller is not working… I am pretty sure it is because of my soldering, it is my first try in 12 years to solder a wire again, but yet I want to make sure it is not because of the steps above. Is there any way for me to test if my soldering is OK on the console?

    Thanks
    Dennis

    • Dennis says:

      By the way, when I do the source based installation there’s also an error saying that it could not compile the SNESDev drivers and tells me to check the debug.log. But the debug.log only reads:
      SNESDev:
      /home/pi/RetroPie/supplementary/SNESDev-Rpi/bin/SNESDev does NOT exist.

      I cannot find anything else about SNESDev there.

      • Florian says:

        To check this in more detail you can change the directory to /home/pi/RetroPie/supplementary/SNESDev-Rpi/bin/SNESDev. Then you clean up the installation with “make clean” and compile SNESDev again with “make”. If anything wants wrong during that you will see it in this way. BTW: these are the steps that are done by the RetroPie script as well.

    • Dennis says:

      Some additional data:
      kern.log:
      Nov 25 00:16:57 raspberrypi kernel: [ 16.877736] input: SNES pad as /devices/virtual/input/input2
      Nov 25 00:16:57 raspberrypi kernel: [ 16.903560] SNES pad data pin connected to GPIO4
      Nov 25 00:16:57 raspberrypi kernel: [ 16.933187] input: SNES pad as /devices/virtual/input/input3
      Nov 25 00:16:57 raspberrypi kernel: [ 16.957803] SNES pad data pin connected to GPIO3
      Nov 25 00:16:57 raspberrypi kernel: [ 87.465027] bcm2835-cpufreq: switching to governor ondemand
      Nov 25 00:16:57 raspberrypi kernel: [ 87.465058] bcm2835-cpufreq: switching to governor ondemand
      Nov 25 00:16:57 raspberrypi kernel: [ 88.992474] input: SNES-to-Keyboard Device as /devices/virtual/input/input4
      Nov 25 00:16:59 raspberrypi kernel: [ 90.823551] Adding 102396k swap on /var/swap. Priority:-1 extents:1 across:102396k SS

      So should it be working?
      Think I should get a multimeter to check my soldering…

    • Florian says:

      Ok, thanks for the detailed description!

      I added a section ” Installation and Troubleshooting” above. This should help you!

  10. Dennis says:

    Thanks for that. In parallel I was checking my soldering and that seems to be OK. What I cannot check with my multimeter is if the ribbon crimp connector is connected correctly (which could be a problem, like I said this is not my everyday business). But I can track that the current is flowing from the SNES adapter through the crimp connector.

    Then I set SNESDev to only poll the button and rebootet. After that I tried to read the input with jstest, but again without success.

    This is the output of jstest:
    Driver version is 2.1.0.
    Joystick (SNES pad) has 2 axes (X, Y)
    and 8 buttons (BtnX, BtnY, BtnTL, BtnTR, BtnTR2, BtnSelect, BtnThumbL, BtnThumbR).
    Testing … (interrupt to exit)
    Axes: 0: 0 1: 0 Buttons: 0:on 1:on 2:on 3:on 4:on 5:on 6:on 7:on

    Shouldn’t the buttons be ‘off’ without button press and ‘on’, when I press a button?

    And I noticed something odd: When I press and hold the button for a couple of seconds nothing happens. Once I release it, the system shuts down. I though I have to push and release the button 5 times for the system to shutdown?

    Sorry for keeping you busy. :-/

    • Florian says:

      Yes, it should say “on”, when the buttons are pressed. Two thoughts here:

      1) It sounds as if (at least) your button is assembled and (hardware-wise) working correctly. However, it sounds as if you are not using the latest version of SNESDev. In a previous version a shutdown command was initiated when pressing the button for more than 3 seconds. This has changed with the more recent version of SNESDev.

      2) Did you solder the tri-state buffer with the correct orientation on the adapter board? As stated in the assembly guide: “Pin 1 must be directed towards the fuse holes.”

      • Dennis says:

        I should have stated that I have bought a pre assembled one. I only soldered the wire from the SNES Connector to your adapter.

        I will now try to reinstall the latest SNESDev with ‘make clean’ && ‘make’ as you have suggested above.

        I now have tested the ribbon crimp connector and I can see that the current should be able to flow between the crimp connector and the 5 pins from the SNES adapter.
        I will check the schematics again, maybe I didn’t check careful enough.

      • Florian says:

        Ah, I see. The pre-assembled ones were tested before shipping.

  11. Dennis says:

    Small success:
    Now jstest behaves differently, all buttons ‘flicker’ from ‘on’ to ‘off’ like mad, only when I press a button they stay ‘on’. Any idea what might be the problem? ‘Unclean’ soldering?

  12. Dennis says:

    Btw, /home/pi/RetroPie/supplementary/SNESDev-Rpi/bin/SNESDev is empty… But that is a totally different problem I think.

    • Florian says:

      /home/pi/RetroPie/supplementary/SNESDev-Rpi/bin/SNESDev should be the binary, and /home/pi/RetroPie/supplementary/SNESDev-Rpi/bin/ the containing folder.

      Since you said that pressing the button leads to a shutdown of the system SNESDev must be there.

      • Dennis says:

        Please forget about my joytest-problem and let’s not talk about it anymore. 😛 (It is working now and was of course my fault, I have connected Data 2 when I thought I had connected Data 1, so joytest /dev/input/js1 works now as it should).

        On to the next:

        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi/bin $ ls -altr
        insgesamt 8
        drwxr-xr-x 8 pi pi 4096 Nov 24 17:16 ..
        drwxr-xr-x 2 pi pi 4096 Nov 24 19:33 .
        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi/bin $

        Am I missing something?

        I see SNESDev writing logs, so yes, it must be there, but where?
        (When I had no success to get the Source based installation running I tried the binary based installation and later the source based again…)

        Thanks for your help.

      • Florian says:

        Ok, let’s try it manually. First of all make sure that you have the latest sources:

        cd ~/RetroPie/supplementary/SNESDev-Rpi/
        git pull

        Then, compile it:

        make clean
        make

        The, copy SNESDev to the bin directory:

        sudo cp ./bin/SNESDev /usr/bin/

        Restart the SNESDev service via

        sudo service SNESDev restart

        Does it work?

      • Dennis says:

        Hi,
        here is the complete output:

        pi@raspberrypi ~ $ cd ~/RetroPie/supplementary/SNESDev-Rpi/
        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ git pull
        Already up-to-date.
        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ make clean
        rm obj/*.o; rm bin/SNESDev
        rm: Entfernen von âobj/*.oâ nicht möglich: Datei oder Verzeichnis nicht gefunden
        rm: Entfernen von âbin/SNESDevâ nicht möglich: Datei oder Verzeichnis nicht gefunden
        make: *** [clean] Fehler 1
        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ make
        gcc -c -Wall -O3 -Iinclude -lbcm2835 src/main.c -o obj/main.o
        gcc -c -Wall -O3 -Iinclude -lbcm2835 src/SNESpad.c -o obj/SNESpad.o
        gcc obj/main.o obj/SNESpad.o -lbcm2835 -o bin/SNESDev
        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ sudo cp ./bin/SNESDev /usr/bin
        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ sudo service SNESDev restart
        [ ok ] Restarting SNESDev GPIO Adapter daemon: SNESDev.

        After that I held down the button for about 5-8 seconds, released it and…

        Broadcast message from root@raspberrypi (Sun Nov 25 15:09:47 2012):

        The system is going down for system halt NOW!

        Even after a reboot -> same behaviour. Can it be that there is another copy of SNESDev somewhere because I tried the binary installation at one point?

        And another thing, unrelated to your adapter, I have overclocked the pi via raspi-config like this:
        “High”; 950 MHz ARM, 450 MHz core, 450 MHz SDRAM, 6 overvolt

        Still Super Mario World + Super Mario Kart (only 2 games I have tested) are very slow. Is it because I output via HDMI?

      • Florian says:

        I am sorry!
        There was a typo in my last comment. It should read
        sudo cp ./bin/SNESDev /usr/bin//usr/local/bin/
        Notice the slash at the end of command! If you leave this out it will copy SNESDev to a file “bin” within the folder /usr.

        Output via HDMI is quite fast for me.

      • Dennis says:

        And I simply copied and pasted the commands without thinking.
        I redid that step and can now see that /usr/bin/SNESDev has a new time stamp, still the same behaviour. 😦
        I have a v2 board if that makes a difference?

        As for speed, did you tweak anything? I have disabled “boot into desktop”, overclock settings as stated above and memory split 50/50.

      • Florian says:

        This should be independent of the RPi board revision. Just to test it and to be sure that you are using the just-compiled version of SNESDev, you can start SNESDev from command line via
        ~/RetroPie/supplementary/SNESDev-Rpi/bin/SNESDev 2&

        Ups, I just found another typo: It must be /usr/local/bin/!
        Restart the service via sudo service SNESDev restart after copying SNESDev to the correct location and things should (finally) work.

      • Florian says:

        What I did was to ssh into the RPi while running an emulator. With this I found that pulseaudio was using a lot of resources in my case. Maybe you find something similar with this approach.

  13. Daniel says:

    you should really make a wiki page from this issue 😉

  14. Dennis says:

    Cannot reply to your last related post.
    That did the trick, it works now. 🙂

    This is my ps aux output while running Super Mario Kart, omitting all 0.0 %CPU entries:

    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
    root 1 0.7 0.2 2136 732 ? Ss 16:37 0:01 init [2]
    root 4 0.1 0.0 0 0 ? S 16:37 0:00 [kworker/0:0]
    root 12 0.2 0.0 0 0 ? S 16:37 0:00 [khubd]
    root 27 1.3 0.0 0 0 ? S< 16:37 0:03 [VCHIQ-0]
    root 28 0.3 0.0 0 0 ? S< 16:37 0:00 [VCHIQr-0]
    root 33 4.0 0.0 0 0 ? S 16:37 0:09 [mmcqd/0]
    root 138 0.2 0.5 2884 1296 ? Ss 16:37 0:00 udevd –daemon
    root 1620 0.1 0.0 0 0 ? S 16:37 0:00 [RTKTHREAD]
    root 1640 0.2 0.0 0 0 ? S 16:37 0:00 [kworker/0:2]
    root 2279 0.4 1.3 10548 3316 ? Ss 16:38 0:00 sshd: pi [priv]
    root 2299 0.1 1.4 26512 3708 ? Sl 16:38 0:00 /usr/sbin/console-kit-daemon –no-daemon
    root 2366 0.1 1.1 23300 2928 ? Sl 16:38 0:00 /usr/lib/policykit-1/polkitd –no-debug
    pi 2376 0.3 0.9 6128 2480 tty1 S+ 16:38 0:00 -bash
    pi 2384 4.0 2.5 64272 6588 tty1 Sl+ 16:38 0:06 ./emulationstation
    pi 2394 87.3 9.3 93712 23828 tty1 Rl+ 16:39 1:52 retroarch -L /home/pi/RetroPie/emulatorcores/pocketsnes-libretro
    pi 2406 0.7 0.6 10548 1732 ? S 16:39 0:00 sshd: pi@pts/0
    pi 2407 1.0 1.3 6784 3352 pts/0 Ss 16:39 0:01 -bash

    pulseaudio was listed, but only with 0.0%, I can only see retroarch consuming a lot of CPU power. Did you tweak anything in the retroarch configuratoin?

    Btw, if I get this thing running I will buy at least one more of your adapters in the future. I want to have a dedicated machine in a SNES case for SNES games only and one in a NES case for NES games only. Who knows, later maybe the same for Genesis…

    I understand that my speed issue has nothing to do with your adapter, so it's OK if you can't give support. I watched your video of Super Mario Kart on youtube and it runs so much faster than mine…

    • Florian says:

      Great to hear that we also solved the SNESDev issue!

      If it is not due to an “external” program I am pretty sure that you can tweak a lot with the settings in /etc/retroarch.cfg.

      First of all disable the rewind functionality and also the audio_driver setting. Change the audio driver to alsa in a next step. Does this have any effect?

  15. Dennis says:

    Setting the driver to alsa had a very negative effect, it is even slower. It was set to sdl initially.

    Disabling the rewind functionality brought a little performance boost, but not enough.

    • Dennis says:

      Just noticed a ton of error messages in the background when using alsa:
      RetroArch [WARN] :: [ALSA]: poll() was signaled, but EAGAIN returned from write.
      Your ALSA driver might be subtly broken.

      It repeats over and over and may well be the cause for it being so slow for me.

      • Dennis says:

        I don’t know exactly what happened, but it now works somehow. Not as good as I hoped, but it’s OK. Mario Kart works smooth only if I overclock to 1 Ghz, but I don’t want to use this setting the whole time. At 900 Mhz Mario Kart is still a bit slow (so I guess Mode 7 emulation is the cause), I tried Super Mario World + Street Fighter IV and I can play them at acceptable speed..

        Things I did to get it working:
        Tweaked retroarch video settings
        Rebuilt SNES core/Retroarch from source via your script

        ALSA is still not working for me btw, but I guess this is a common R-Pi issue.

        Thanks a lot for your help. 🙂 Now I need to find a cheap SNES and NES case to build my R-Pis into.

      • Dave says:

        Dennis I think I may know what your problem is because I did the same thing. Prevously you listed the steps you took and you said you installed the SNESDev (controllers and pad) plus the gamecon driver. I took the same route and my controllers were super buggy. What you need to do is change the polling for SNESDev to “button only” then install the gamecon stuff. Basically you have SNESDev and gamecon both trying to control your gamepads.

        I should add that I am new to all this and might be completely wrong. That said I now have my Rpi working perfectly with two SNES controllers. Hope that helps

  16. Dave says:

    I’m using your GPIO adapter and everything is working great. I’ve only got one question. Is there a way to edit what the button on the adapter does. I would like to have it quit a game after just one press instead of three. Thanks!

  17. John Wilkes Booth says:

    If I’ve got a short between VCC and GND, what’s the next culprit to look at? Has any one compiled a how to on what to test?

    • Florian says:

      Not that I know.
      I could upload the schematics for the device that I use for testing the assembled adapters. Basically, it provides a visual indication for correctly working adapter by testing each line of the tri-state buffer as well as the button.

  18. d4m4s74 says:

    I’ve just ordered the card. I’m planning on building my pi onto a snes, so unfortionately I’ll have to wait for my special screwdrivers to arrive so I can open the snes without damaging it before I can test.

    • Florian says:

      That sounds great! You can send me pictures of your project for a future showroom at the blog site!

      • d4m4s74 says:

        I will need to find out where to get the other parts I will need, and unsolder and extend a couple of things for better accessability (Like I want to wire up your the button on the PCB to the reset button, move the SD card slot, extend the USB ports, HDMI port, composite, everything really. Which means I’ll have to learn how to solder. This will take a while.

      • d4m4s74 says:

        I found out something “useful”. When using the original controller board for the pal snes, the LED lights up. This will save me a lot of time wiring the LED to work on my build, but I hope the controllers get enough power. Ah well, I’ll see once the retropie installer finally is finished.

      • d4m4s74 says:

        turns out I either soldered it wrong, or it doesn’t work with that LED parallel to the controllers. I will make some changes later tonight and try again.

  19. Andrew says:

    Hello, I am trying to implement a push button using your idea to try and replace the escape key so I don’t need a keyboard for the setup. I am having issues getting it to work though and I was hoping you could help me. VCC (3.3 volt pin) is connected to the open switch, which then goes to one leg of a 1k resistor. This leg is also connected to pin 1_11, the same pin you would use with your adaptor. The other leg is connected to ground. Nothing is soldered, it’s all done using test clips until I know it works. I have installed SNES using the RetroPie script and set it up to poll for just the button since I am using usb controllers. Let me know where I need to look to try and get this working. Thank you.

    • Florian says:

      Your setup sounds fine and should be the same as the one of the adapter.
      If you have it available I would recommend to test the circuitry with a multimeter and, in the best case, completely independent from the RPi with a separate power supply.
      Check for short circuit between GNC and VCC. Also check for the correct VCC pin (3.3V, and not 5V).

      • Andrew says:

        I went ahead and checked out the setup with my multimeter. There were not shorts between VCC and ground, the switch is open unless the button is pushed, so that isn’t broken. From the outside, the circuitry is doing what it should, having 0 V outside pin 1_11 until the button is pushed and then it goes high to 3.3V. My setup is installed in the pi user folders. I know one of your articles stated that the uinput could only be used as root? So does my retro arch and everything have to be installed under the root user for this to work? If this is not the case, what would you need from me to try and determine what isn’t right on the software portion of it? Thanks for helping me out with this.

      • Loren says:

        Sounds like you are having an issue like I did. Your switch sounds to be wired in as a pull up. It needs to be wired as a pull down. Pull down is what I needed to get it to work. If you look at this link- http://elinux.org/File:EGHS-PullUpDownSwitch.jpg – the top, I believe is how your currently wired, but you need to wire like the bottom. Try it out and let me know.

      • Florian says:

        I have just updated the source trees of SNESDev and RetroPie-Setup. Please update your RetroPie-Setup version by going into that directory and calling “git pull”. Then start the script and select the source-based installation. Here, you install only the BCM library and SNESDev then.
        When the installation is finished, go to the directory “~/RetroPie/supplementary/SNESDev/supplementary/testButton/”. It is a small C program which print the status of pin P1-11 to the console. To compile the program call “make”. Run it with “sudo ./testButton”. You can cancel the program with “Ctrl-C”. Are your button presses recognized by this program?

      • Andrew says:

        I probably did a poor job of explaining it, but it is wired to be a pull down switch (the bottom picture). And with everything looking fine using the DMM, I’m guessing it has to be something on the software side. Which is where I really wonder what went wrong because it seems to me like the script would take away most of my ability to screw something up. But alas, I seem to have found a way, lol.

      • Loren says:

        If your wiring is all good, it sounds like your connected to the correct GPIO pin- I’d check for updates on the script (git pull) and uninstall/re-install the SNES DEV components and see if that work.

  20. Andrew says:

    Okay, I tried to update SNESDev, but it wouldn’t update and said to check the debug log. Which only has this:
    SNESDev:
    /home/pi/RetroPie/supplementary/SNESDev-Rpi/bin/SNESDev does NOT exist.

    I saw someone had the same issue earlier and followed what you put with pulling it and compiling. Here are the results:

    pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ git pull
    Already up-to-date.
    pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ make clean
    rm obj/*.o; rm bin/SNESDev
    rm: cannot remove `obj/*.o’: No such file or directory
    rm: cannot remove `bin/SNESDev’: No such file or directory
    make: *** [clean] Error 1
    pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ make
    gcc -c -Wall -O3 -Iinclude -lbcm2835 -lrt src/main.c -o obj/main.o
    src/main.c: In function ‘main’:
    src/main.c:216:15: error: ‘RPI_V2_GPIO_P1_11’ undeclared (first use in this function)
    src/main.c:216:15: note: each undeclared identifier is reported only once for each function it appears in
    src/main.c:271:17: error: ‘RPI_V2_GPIO_P1_19’ undeclared (first use in this function)
    src/main.c:272:17: error: ‘RPI_V2_GPIO_P1_23’ undeclared (first use in this function)
    src/main.c:273:17: error: ‘RPI_V2_GPIO_P1_07’ undeclared (first use in this function)
    src/main.c:274:17: error: ‘RPI_V2_GPIO_P1_05’ undeclared (first use in this function)
    make: *** [obj/main.o] Error 1

    Wasn’t sure if the error could be ignored, tried to copy the file

    pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ sudo cp ./bin/SNESDev /usr/local/bin/
    cp: cannot stat `./bin/SNESDev’: No such file or directory

    So that didn’t work, your test button file was there but when I tried to compile and run it I got this:

    pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi/supplementary/testButton $ make
    gcc -c -Wall -O3 -Iinclude -lbcm2835 main.c -o main.o
    main.c: In function ‘main’:
    main.c:20:15: error: ‘RPI_GPIO_V2_P1_11’ undeclared (first use in this function)
    main.c:20:15: note: each undeclared identifier is reported only once for each function it appears in
    main.c:22:31: error: ‘BCM2835_GPIO_FSEL_INP’ undeclared (first use in this function)
    main.c:26:6: warning: implicit declaration of function ‘bcm2835_gpio_read’ [-Wimplicit-function-declaration]
    main.c:28:7: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
    main.c:28:7: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
    main.c:30:7: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
    make: *** [main.o] Error 1
    pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi/supplementary/testButton $ sudo ./testButton
    sudo: ./testButton: command not found

    Hopefully something in that will help you pinpoint what is going on with my board. Thank you very much for taking time to try and help me fix this. I appreciate it.

    • Florian says:

      You also have to update the BCM library via the setup script. With the updated library the errors should be gone.

      • Andrew says:

        Okay, that got rid of a lot of the pin errors, still had errors when trying to make SNESDev.

        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ git pull
        Already up-to-date.
        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ make clean
        rm obj/*.o; rm bin/SNESDev
        rm: cannot remove `bin/SNESDev’: No such file or directory
        make: *** [clean] Error 1
        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ make
        gcc -c -Wall -O3 -Iinclude -lbcm2835 -lrt src/main.c -o obj/main.o
        gcc -c -Wall -O3 -Iinclude -lbcm2835 -lrt src/SNESpad.c -o obj/SNESpad.o
        gcc obj/main.o obj/SNESpad.o obj/cpuinfo.o -lbcm2835 -lrt -o bin/SNESDev
        gcc: error: obj/cpuinfo.o: No such file or directory
        make: *** [SNESDev] Error 1

        In addition, it seems right now SNES isn’t even recognized as a servie

        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi $ sudo service SNESDev restart
        SNESDev: unrecognized service

        I’m sure that is causing me to still get the same error when trying to run the testButton

        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi/supplementary/testButton $ make clean
        rm *.o; rm testButton
        rm: cannot remove `*.o’: No such file or directory
        rm: cannot remove `testButton’: No such file or directory
        make: *** [clean] Error 1
        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi/supplementary/testButton $ make
        gcc -c -Wall -O3 -Iinclude -lbcm2835 main.c -o main.o
        main.c: In function ‘main’:
        main.c:20:15: error: ‘RPI_GPIO_V2_P1_11’ undeclared (first use in this function)
        main.c:20:15: note: each undeclared identifier is reported only once for each function it appears in
        main.c:22:31: error: ‘BCM2835_GPIO_FSEL_INP’ undeclared (first use in this function)
        main.c:26:6: warning: implicit declaration of function ‘bcm2835_gpio_read’ [-Wimplicit-function-declaration]
        main.c:28:7: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
        main.c:28:7: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
        main.c:30:7: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
        make: *** [main.o] Error 1
        pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi/supplementary/testButton $ sudo ./testButton
        sudo: ./testButton: command not found

        Here is something else that may or may not be related in the debug file:

        RetroArch files:
        -rwxr-xr-x 1 root staff 1.3M Dec 1 17:34 /usr/local/bin/retroarch
        -rwxr-xr-x 1 root staff 1.9K Dec 1 17:34 /usr/local/bin/retroarch-zip
        /home/pi/RetroPie/configs/all/retroarch.cfg does NOT exist.

        It starts with the configs folder not existing, but that may be a non-related issue, I don’t have any issues getting my usb controllers to work with the the file in /etc/retroarch.cfg

      • Florian says:

        There was a dependency missing in the Makefile of SNESDev. Furthermore, I have uploaded a wrong version of main.c for testButton. I am sorry for that!

        I am not at home right now, so I did a “quick fix” via the Github interface. Both issues should be fixed now and I hope that I did not miss anything.

        Does it work now?

  21. Andrew says:

    SNESDev was able to compile without any errors. Still was given the error about it not being a service when I tried to restart it (not sure if that matters, I just want to make sure I don’t leave anything out) Also, still not having any luck getting the testButton to run. Info is below. Thank you for continuing to help me with this.

    pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi/supplementary/testButton $ make clean
    rm *.o; rm testButton
    rm: cannot remove `testButton’: No such file or directory
    make: *** [clean] Error 1
    pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi/supplementary/testButton $ make
    gcc -c -Wall -O3 -Iinclude -lbcm2835 main.c -o main.o
    main.c: In function ‘main’:
    main.c:28:7: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
    main.c:28:7: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
    main.c:30:7: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
    gcc -c -Wall -O3 -Iinclude -lbcm2835 cpuinfo.c -o cpuinfo.o
    gcc main.o cpuinfo.o -lbcm2835 -o testButton
    /usr/local/lib/libbcm2835.a(bcm2835.o): In function `bcm2835_delayMicroseconds’:
    /home/pi/RetroPie/supplementary/bcm2835-1.14/src/bcm2835.c:350: undefined reference to `clock_gettime’
    /home/pi/RetroPie/supplementary/bcm2835-1.14/src/bcm2835.c:360: undefined reference to `clock_gettime’
    collect2: ld returned 1 exit status
    make: *** [testButton] Error 1
    pi@raspberrypi ~/RetroPie/supplementary/SNESDev-Rpi/supplementary/testButton $ sudo ./testButton
    sudo: ./testButton: command not found

    • Florian says:

      Ok, I’ll have a look at it tomorrow.

    • Florian says:

      Ok, again “git pull” to update SNESDev and testButton. Then “make clean” and “make”.
      You have to run testButton with “sudo ./testButton”.

      After you have compiled SNESDev you have to enable SNESDev on boot with the RetroPie script in order to have it recognized as a service! The script takes care for copying the necessary files to the right locations. You can have a look the steps in detail at https://github.com/petrockblog/RetroPie-Setup/blob/master/retropie_setup.sh#L814.

      • Andrew says:

        Okay, the test button is finally running and it recognizes button presses. Button state: PRESSED when pushed and Button state: NOT PRESSED when not pushed. I can restart the SNESDev service so that is running. Still not getting the exit out of the emulator though with the a press (I edited the file so that 1 press should exit the emulator). I used the Retro Pie script to configure to poll for the button only. Any idea what is keeping it from working in game?

      • Florian says:

        Sounds good, we are getting close!
        Without further testing, I would modify the source of main.c of SNESDev like this:
        case BTNSTATE_PRESS:
        if (buttonState==LOW ) {
        btnLastTime=time(NULL);
        btnState = BTNSTATE_RELEASE;
        } else if (buttonState==HIGH && btnPressCtr==1 && difftime(time(NULL),btnLastTime)>1) {
        /* send_key_event(uinh, KEY_R,1); */
        }
        break;
        case BTNSTATE_RELEASE:
        if (buttonState==LOW && difftime(time(NULL),btnLastTime)>1 ) {

        if (btnPressCtr==1) {
        // Sending ESC
        send_key_event(uinh, KEY_ESC,1);
        usleep(50000);
        send_key_event(uinh, KEY_ESC,0);
        } else if (btnPressCtr==3) {
        // Sending ESC
        send_key_event(uinh, KEY_ESC,1);
        usleep(50000);
        send_key_event(uinh, KEY_ESC,0);
        } else if ( btnPressCtr==5 ) {
        // shutting down
        pollButton = 0;
        pollPads = 0;
        send_key_event(uinh, KEY_F4,1);
        usleep(50000);
        send_key_event(uinh, KEY_F4,0);

        system("shutdown -t 3 -h now");
        }

        btnLastTime=time(NULL);
        btnState = BTNSTATE_IDLE;
        btnPressCtr = 0;
        } else if (buttonState==HIGH ) {
        btnLastTime=time(NULL);
        btnState = BTNSTATE_PRESS;
        btnPressCtr += 1;
        }
        break;

        After compiling you have to makee sure that the just compiled version is used. Without calling the RetroPie script again, you can copy the new binary to /usr/local/bin/ and restart the service via sudo service SNESDev restart.
        For debugging purposes, you could also run SNESDev directly via sudo SNESDev 2& and simulate, e.g., a press of the “x” button. You should see the “x” in the console. Do not forget to kill the SNESDev process afterwards via sudo killall SNESDev.

      • Andrew says:

        I did everything laid out but still no luck. I went and tried to do the debug but since my button is only for escape and that doesn’t show up. I changed the key from KEY_ESC to KEY_R just for debugging with sudo SNESDev 2&. I noticed r really doesn’t show up with any consistency when the button is pressed. I did have a couple of times it showed up but that was it and in no way consistent. It shows up fine on the testButton script still though.

  22. Dave says:

    Here’s my SNES using the GPIO adapter. It’s still a work in progress but mostly functional.

  23. nate says:

    I have a rev 2 Pi and am having no luck getting the controllers to work. the (regular nes) controllers show up as connected to GPIO3 and 4 (pins 5 and 7) clock is at 19, latch at 23, power and gnd at 1 and 6. Emulationstation is fully operational w/ keyboard. but the controllers show no signs of life. What I need to know is how to configure the SNESDev and gamecon drivers for nes controllers. I managed to edit the /etc/modules to make the controllers register as NES (with the right amount of buttons in the /dev/joy0 test) I modified the arch config and blanked out l,r,x, and y and renamed select and start to buttons 2 and 3. I have yet to have any button or axis map to a key, I get no response in the terminal. i did short out 11 and get it to reboot also. What do i need to do to diagnose the problem? does rev 2 need a different clock/latch?

    • Florian says:

      The game pads do not produce any output on the console. When they are recognized by the jstest tool they will work with the emulators, if the configuration is correct. For RetroArch you can use the tool “retroarch-joyconfig” to obtain the button numbers for your game pads. With these numbers you can adapt the retroarch.cfg accordingly.

      With the gamecon driver installed you would use SNESDev only for polling a button on P11. You can set up SNESDev via the RetroPie script (in the setup menu).

      • nate says:

        when i use retroarch joyconfig, it says
        Found joypad driver: sdl
        Configuring binds for player #1 on joypad #0.

        A button (right)
        but no buttons do anything
        from the log

        18.352978] input: NES pad as /devices/virtual/input/input0
        [ 18.363678] NES pad data pin connected to GPIO1
        [ 18.375374] input: NES pad as /devices/virtual/input/input1
        [ 18.389085] NES pad data pin connected to GPIO4
        [ 22.700835] mmc0: missed completion of cmd 18 DMA (512/512 [1]/[1]) – ignoring it
        [ 22.711408] mmc0: DMA IRQ 6 ignored – results were reset
        [ 28.982775] input: SNES-to-Keyboard Device as /devices/virtual/input/input2

        gpio 1 is the pin number on the old revision, mine is a new revision board
        i will flip contoller 1 to pin 4(physical 7) and 2 to pin 1 (pin3)(physical 5) confused yet?

      • Florian says:

        If you’re using the gamecon driver I would suggest to ask this in the forum thread at http://www.raspberrypi.org/phpBB3/viewtopic.php?f=78&t=15787.

  24. Brandt says:

    Hi, I’m trying to implement just the button, and it looks like in your schematics, the button goes to pin 16, but everyone here is saying pin 11.

    https://petrockblog.files.wordpress.com/2012/11/retropiegpioadapter-schematics.pdf

    • Florian says:

      The pin numbers in the schematics are automatically created by EAGLE. These, however, do not correspond to the *physical* pins of the RPi. The button of the adapter uses the physical pin 11 of the GPIO pins of the RPi.

      • Brandt says:

        Thanks. I got it working on a breadboard..works great! I also ordered your GPIO adapter and just got it in the mail…unfortunately the button on the GPIO adapter isn’t doing anything….testButton isn’t seeing anything pressed. How can I troubleshoot your board?

      • Florian says:

        Do you have a revision 2 RPi? Maybe testButton has a bug related to revision 2 boards … I should better check this.

        I use an LED circuits to test the boards without any software involved. If you have the material you could do the same. Until now there were no hardware problems with the adapters after delivery so that I hope we can figure this out with software 🙂

      • Brandt says:

        Yes, I have many electronic components available to me. Maybe you could describe the circuit? Also, yes I have a Rev 2 board.

      • Brandt says:

        I was able to test continuity between vcc -> s1-2, s1-1 -> p1-11, p1-11 -> r7, GND -> r7, and GND -> p1-11 pulled down when button pressed

      • Brandt says:

        ok…I’m an idiot and shouldn’t be doing this at midnight….I had assumed the 2×5 headers faced outward on the RPi…..when I was testing I realized 3.3vdc is on the other side of the RPi….I flipped the board around with the 2×5 headers facing inward and all seems to be well with the button. I’m using USB controllers for now so I will not be abled to test the gamepad polling until a later time.

      • Florian says:

        That are great news!
        The program “testButton” is also working for you and indicating button presses now?

      • Brandt says:

        I suggest adding a picture of the GPIO adapter attached to the board on this blog for dummies like myself 🙂

      • Florian says:

        Adding such an image to the article might be a good idea to ease things up. Thanks for the hint 🙂

  25. brandt1981 says:

    Do you have a parts list of the board? Like What type of switch. Omron?

    • Florian says:

      I have to prepare the list. I could prepare a link list to the dealer I used here in Germany (which is not one of the big ones like Farnell or RS Components) or I could prepare a link list using a more internationally operating distributor. Do you have a preference here?

  26. Andy says:

    This is a good project. I recently bought a GPIO adaptor (pre-assembled), and installed all the software from the RetroPie-Setup script. And for the life of me, I can’t seem to get anything working from the controller. I can’t even get the jstest to work.
    I have a Rev 1 RPi, and have set the memory split to 128. What am I doing wrong? I have double and triple checked the pinouts, and all is as it ‘should’ be.
    What am I missing?

    • Florian says:

      Did you install the gamecon driver and/or SNESDev?
      Did you try to poll the button state via the testButton program in the supplementary folder of SNESDev?
      Do you have the possibility to test the connection between the game pad and the RPi with a breadboard (without the GPIO adapter on between)?

      • Andy says:

        Thanks for the reply Florian. I recompiled the source, and it seemed to work. Since then, I used the testButton program (sorry, didn’t see it before), and all is fine. Now I get a heap of warnings (cuts out of the game to command, and then back again) which says: RetroArch [WARN] :: [GL]: Stock GLSL shaders will be used.
        But the GPIO works fine! thanks!

  27. Pingback: An A to Z Beginners Guide to Installing RetroPie on a Raspberry Pi | Super Nintendo Pi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s