SNESDev-RPi: A SNES-Adapter for the Raspberry Pi

You already might have heard of the Raspberry Pi. It is a credit-card sized PC from the Raspberry Pi Foundation and is going into mass production and distribution these days. There is a huge demand for “the Pi” and the first orders are limited to one per person. A few weeks ago I got my Pi delivered and started working on what I would describe as “universal console”. In this post I describe my initial thoughts about this project and present an adapter that allows you to use SNES controllers as input devices for the Raspberry Pi.

UPDATE: The ControlBlock is now available and provides an easy and safe way for connecting NES, SNES, and Arcade controllers to the RPi and it also provides a power switch functionality!

Being part of the 80ies generation I belong to the group of people that grew up with a whole bunch of 8- and 16-bit video consoles. Nowadays, you can find emulators for all kinds of these consoles and some time ago I got the idea that it would be nice to have a tiny PC that could just be switched on to play this or that good old game. When I read about the Raspberry I finally decided to start this project.

There are several things that have to be done for this:

  • Decide for a stable working Linux distribution that provides access to the video and sound hardware.
  • Make the emulator(s) work.
  • Build a launch menu that allows for selecting the console and or the video game.
  • Build a hardware controller interface that allows you to connect real video game controllers.
  • Build a case that contains the Raspberry and the connector(s) for the controller(s).

I know that you are now saying “Each of these five points is a project on its own.” and I agree! Let’s have a brief look at each of these points now:

The distribution The decision for a “good” distribution is tricky and I am not sure which of the available ones is best suited. Since the Debian distro will be the official distribution of the Raspberry, I think that this might be the best choice. But, currently, even the Debian distro provides an ALSA module only in alpha stage. This produces horrible audio outputs and leads us to the second point:

The emulators There is already work going on for tht point and ToadKing is doing fantastic work here. He is adapting the RetroArch emulator to the Raspberry currently and provides a public Github repository. There is also a thread about this work in the official forum. This is a central piece of this “universal console” and I really hope that the Raspberry port of RetroArch and of the emulator cores will be further developed.

The launch menu Maybe there already exists a launcher that can be compiled on the Raspberry. If you know such a thing, please tell me! Otherwise, I thought of a rudimentary (Python?) script that could be used for the beginning. Update: In the meantime, the front end “Emulation Station” has started to be developed. A lot of ideas are still being discussed and on the to-do list, but there is already a running version of it. A follow-up article presents the RetroPie setup script that automates the installation of emulators and front end.

The controller interface I think that an authentic retro-gaming device needs authentic input hardware. The Raspberry comes with two USB ports and one possibility would be to use some remakes of, for example, SNES controllers with USB connectors. In order to use original controllers, however, one needs to come up with an interface for these controllers. This is where the second part of this post comes into play: I built an adapter board that allows you to connect two SNES connectors to the GPIO pins of the Raspberry. I got the SNES connectors from two controller extension cables. This wiki article gives some more details about the GPIO pins of the Rasperry. A short C program reads the states of the two controllers and passes all button presses to a virtual keyboard that is implemented with the help of the uinput module. In the following, I explain some more details of this adapter, show some pictures of it, and, at the end, also a video demo.

Let us first talk about the hardware part. The idea of designing a PCB that could be used for connecting SNES controllers to a microcontroller or PC came up when I read about a project, in which an NES controller was connected to an iPad. In previous posts, I wrote about the first prototype, the SNES-adapter PCB, and a case for the adapter. For the connection to the Raspberry I used the following parts:

  • 1x SNES-adapter PCB
  • 2x SNES connectors (obtained from extension cables)
  • 2x Shrouded Pin Header, 2×3 pins
  • 2x Ribbon Crimp Connector, 2×3 pins
  • Ribbon Cable – 6 wire
  • 1x Ribbon Crimp Connector, 2×13 pins
  • Ribbon Cable – 26 wire

The SNES-adapter board really does nothing but to provide a clean wiring for the connectors. You could also connect a SNES connector with the 26-wire ribbon cable directly. Besides the cleaner look, the nice thing of the adapter board is that it provides the possibility to connect two controllers without the need for manually splitting the 5V line. If you are interested in the adapter board, send me a mail, I would be happy to share this! To get the SNES connectors I ordered two SNES extension cables and just used the female connectors of them. The SNES and ribbon crimp connectors are wired as following:

You can also see some resistors in the picture – these are actually for LEDs and a button and are not used here. A more detailed description for the assembly is given here. This is a diagram of the pinout of the adapter board:

The GPIO pinout of the Raspberry and of the corresponding 26-wire ribbon cable are shown here:

The connection between the GPIOs and the adapter board is as following:
  • GND to P6
  • VCC to P2
  • DATA 2 to P15
  • LATCH to P16
  • CLOCK to P18
  • DATA 1 to P22
This is how it should look after the assembly:

Here is another picture with the adapter attached to the Raspberry:

Having finished the hardware part I started with the software implementation. I decided for a C program to have the possibility to keep the CPU load as low as possible. Basically, the program has to do two things: First, it has to read the state of each button. A very good source for information about the NES/SNES controllers is also the documentation of the Uzebox. Second, it has to pass button events to a virtual keyboard. The uinput kernel module can handle the input subsystem from within the user space. I stumbled across a very informative article about the uinput kernel module. It is a two-parts article with part 1 here and part 2 here. The uinput module has to be manually loaded with this command:

[gist id=3051580]

To access the GPIO pins from within a C program you need to download and install the Broadcom BCM 2835 library. These commands download and install this library:

[gist id=3051568]

I called the program SNESDev and created a Github repository for it. You can find it at https://github.com/petrockblog/SNESDev-RPi. Here is a demo of everything working together for a quick game of a famous kart game:

This leads us to the end of this post. So far, I did not speak about a case yet. Having some experience with other laser-cut cases I already started to design a case for the Raspberry that also contains ports for two SNES connectors. When this is finished I will write about it in another post. UPDATE: You can now find a shell script in my Github repository that automatically installs all needed packages for RetroArch and various emulator cores, as well as SNESDev.

Certainly, I left out some information that you would be interested in. So, if you have any questions, comments, or questions, just send me a mail or write some comments below – I would be happy about any contributions!

Some obligatory legal stuff: The Raspberry Pi is a trademark of the Raspberry Pi foundation.

148 thoughts on “SNESDev-RPi: A SNES-Adapter for the Raspberry Pi

  1. Djoni Weschenfelder says:

    Hi, im trying to build a retropie inside a snes, using SNESdev-RPI or gamecon_gpio_rpi. Well, the first one (I think that one you had developed) installs correctly, runns as well but it aparently needs the PCB adapter, and I’m in Brasil (unfortunately), so I can’t buy the adapter. The second – gamecon_gpio_rpi – gives errors on installing, aparently something with the new raspbian kernel 4.4.11 v7, and simply doesn’t install, when i try to configure the map it says ‘module gamecon_gpio_rpi not foud’…. It in case of installing via terminal, because the nevest retropie setup script don’t has the gamecon neither the snesdev modules, and the old scripts gives errors installing like via terminal. Also your’s script .sh on github (didn’t found the link righ right now) dont work, gives errors like ‘unexpected “(” ‘ and something like. Can you give-me some light?

  2. Chris says:

    Hi,
    I just assembled the adapter and connected a NES controller. It is not working.

    I took a look at the SNESDEV code. Actually there is a differentiation between NES and SNES controllers that is never used because you can not setup that you are using a NES controller. Is that correct?
    In line 175 of SNESDev.c it says: if (strcmp(confres.gamepad1_type,”nes”)==0) {
    gpads[0].type = GPAD_TYPE_NES;
    Which is never true.

    So is the script supposed to work with NES controller or not?

    regards,

    Chris

  3. Stefan Flores says:

    does that Pi have any capability of running n64 emulators? Love your project, just want to possibly make my own that is n64 oriented.

  4. PiLover says:

    So am I able to hard wire two snes controllers to the GPIO pins such that both controllers clocks go to ping18, along with the rest of the pin out?

  5. Guest says:

    Is there any way to reset the controller settings? I connected a USB NES controller, and it did not setup the controller correctly so I cannot use it.

  6. daniel voigt says:

    There are some games that could be played with more than 2 players. Is it possible to build a 4-controller interface (much like the snes multitap) for RaspberryPi with this? I hope so, because I plan on building a 4 player arcade cabinet and the raspberryPi together with your adapter-pgb would make it cost a lot less money.

    • Miles Carter says:

      There is a GPIO joystick driver kernel module that supports up to six mix and match controllers, all sorts. See raspberry pi forums. Another cheap option is atmega OVR usb adapter, see raphnet.de the chips are ~$1.50 and you only need a handful of components. Diode, resistors, crystal

  7. suciarlak says:

    Hi Florian, when i connect the Snes controller to Pi i get an unlimited serie de characters in the command line, It stops if i disconnect the controller. I installed your Snesdv trough the RetroPie-Setup script, and all connections to GPIO ports seems be ok.

    Any ideas? How can i reconfigure or reinstall Snesdv cfg?

    • Florian says:

      Have you connected one or two controller(s)? If one, which pin out are you using?
      I have seen your request in the issues section of the Github repository – I will have a look at this tomorrow.

      You can connect to the Pi via ssh and disable the autostart n boot via the RetroPie script again. You could also do this manually via “sudo service SNESDev stop”.

  8. randyrobRob says:

    Very Nice, Just what many people are after.
    One question I have is. It doesn’t look like you’d be able to get this to run in Rasbmc because you need root access to install dependencies?

    Many Thanks Rob.

      • randyrob says:

        For those looking this is how you add uinput to startup

        SSH in to your Pi as root

        cd /etc
        sudo nano modules
        add the text “uinput” then press “ctrl+x” and “y” then “enter” to save changes
        sudo reboot

  9. Patrick says:

    Hey Florian, everytime I try to start SNESDev I get an Error:

    szsaq
    -bash: xzsaqw: command not found

    $ ERTYUIOPCBFV

    first I thought, I have to reconfigure the keyboard layout back to standard to fix this problem, but the error still exists. Have you any idea?

  10. Daniel says:

    Hey Florian, I am soooo close to get everything working perfectly. You got no idea how much I appreciate your work. Keep up this kind of stuff.

    Right now I got one thing. Your script got the option to put emulationstation into autostart. Is there a possibility to automatically start SNESDev aswell? (I mean “~/RetroPie/SNESDev-Rpi/bin/SNESDev &”) because just putting emulationstation into autostart does not make my controllers work ;)

  11. Chad Johnson says:

    I cannot get my snes games to run. I have checked everything and followed this all to a T! How do you actually run the games? Do you just type emulationstation? This only brings up Atari 2600 the list is empty!
    I have two snes roms in my roms snes folder and all lowercase .smc files. I have everything connected correctly but I can start a game but my controller is not working. I have everything soldered correctly. What are the exact steps to actually run a game with a snes controller on the GPIO pins. Can you write a description of this. I have searched all over the blog and for some reason I just cannot figure it out!

    Thank you,

    Chad

    • Florian says:

      Hi Chad! Are you using SNESDev (https://github.com/petrockblog/SNESDev-RPi) or the GPIO kernel module that can also be installed by the RetroPie setup script?

      If you use SNESDev, you have to start it with “~/RetroPie/SNESDev-Rpi/bin/SNESDev &”. Eventually, you have to make the binary executable before (with chmod +x ~/RetroPie/SNESDev-Rpi/bin/SNESDev). The ampersand starts the program in the background and you can start an emulator afterwards. When everything is set up correctly, pressing a button should lead to simulated key presses in the command shell.

      The GPIO kernel module can be tested with the command “jstest /dev/input/js0” or “jstest /dev/input/js1”

      I hope this helps!?

      • Chad Johnson says:

        Hello,

        Everything works as you mentioned but the command jstest /dev/input/js0 just returns invalid directory. The command jstest alone works so I know its installed. Do I run the & program in one window then open another terminal to type in emulationstation? When I type sudo ~/RetroPie/SNESDev-Rpi/bin/SNESDev & I just get initializing Pad and then I can push buttons on my controller and it shows up in the terminal but what do I do from here? Emulationstation is finally seeing my roms and I can start one but no controller still?

      • Florian says:

        Ok, so you are using SNESDev. This means that a virtual keyboard is emulated and not a game pad, which, in turn, means that we do not need “jstest”. If you are seeing the output in hte terminal when pressing a button on the controller the hardware part is working!

        >> Do I run the & program in one window then open another terminal to type in emulationstation?
        No, if you start SNESDev with & at the end, you can just press ENTER a second time when the program started and you should get back your cursor.
        BTW: You must not run X, when using EmulationStation!
        Since the D-pad of the controller is mapped to the arrow keys of the keyboard you should be able to move the cursor with the keypad. If not, you are maybe holding the second controller in your hands.
        Try to start a ROM without EmulatoinStation first. You can run a SNES rom by calling “retroarch -L /home/pi/RetroPie/emulatorcores/pocketsnes-libretro/libretro.so /home/pi/RetroPie/roms/snes/nameofyourrom.smc”.
        Press some buttons and compare the output in the terminal with the keyboard input configuration in /etc/retroarch.cfg.
        Really, as long as you see button presses as output on the terminal it is “just” a matter of software configuration now …

      • Chad Johnson says:

        Hello,

        Yes I am sorry I have been on vacation away from my Raspberry Pi. I figured out two things of importance I was doing wrong. I had one controller soldered to the Raspberry Pi and found out that the diagram for your one controller setup isn’t quite right. The Pins should all be the same but instead of Data 2, connect to Data 1 on the one controller setup. This made my controller work instantly and made me feel quite dumb that I was doing everything right but couldn’t figure out what I was doing wrong. Also, I was running emulationstation in X. Once I ran emulationstation at boot and used your advice to initialize the controller before running emulationstaion, everything worked flawlessly!

        Thank you very much for your time and help and such a great product! For your Time and effort can I send you my new Moldy Pi Plate http://www.moldypi.blogspot.com, a creation for myself but based upon your creation of this SNES to GPIO on the raspberry Pi. I can send you the board for free for helping me.

        Thank you again,

        Chad

      • Florian says:

        Hi Chad,

        Good to hear that you finally got it working!
        Sorry for the not-so-clear description of the one-controller assembly guide. I have added two more sentences to the description and hope that it became clearer now.
        Your Moldy Pi Plate really looks interesting and motivates further tinkering for this project :-) Thank you very much for your offer to send me a board! Since I know the prices of small scale PCB manufacturing I really appreciate your offer. I could send you a Petrockblock Pie case in exchange – if you are interested?
        I would suggest to send me a mail via the “contact” site for everything else.

  12. cocopelao says:

    Great Work! i have been searching all over the web and your the guy in the center of the Pi emulation. Quick question i look at amazon for the snes extension cables, but there are so many I don’t want to get the wrong ones. The plan is to set it up with the case you designed, so I want the cut outs to match you think you can point me in the right direction?

  13. Tim says:

    In reference to your launcher project, there definitely is – Adavanced Launcher, which is a plugin for XBMC that is specifcally designed to launch emulators to extend your media center to include games. I see this as a fantastic way to integrate your great work for the raspberry pi because raspbmc is debian based that exists solely to launch XBMC and run on the rpi. My goal is to get your work working on raspbmc and launch the emulators through Advanced Launcher.

    • adam says:

      Any joy with this dude? I’m currently deciding between a windows-based mini-HTPC with XBMC running ZSNES (which I’ve got running perfectly on my windows laptop) or a RPi running RaspBMC, but have no experience with linux etc so no idea what emulator I’d use!

      • Florian says:

        Be prepared for a steep learning curve if you decide for the Linux approach. It is worth every second though.

  14. IIIBossonsIII says:

    Just a quick question guys… So if I got one of the modern USB copies of a snes controller (we had a megadrive II in our house :P) Will it still work okay with the emulator? I’m not actually a coder just a bit of a geek :D Thanks :)

    • Florian says:

      Yes, the USB-controller should be recognized as a joystick/game pad on the Raspberry. Maybe you need to enable the joydev module and export SDL_NOMOUSE=1 to make RetroArch work with it.

      • Alan says:

        would I run into any problems using 2 usb controllers(like the generic ones for playing games on your pc)

  15. imwussie says:

    Awesome work! Thanks for the script! I’m going to try it out later. I have a question though, I’m putting my Pi into an NES and using Raspbmc for my media duties, as well as rom management for emulators. Will retroarch work with XBMC? Also, I’m looking at the work you did for the controllers, what would I need to do to replicate that using the NES controller ports?

  16. Chris says:

    This might sound like a daft question but i’m assuming I just run SNESDev as a background process? I’m fully confident RetroArch is fine and is getting the correct config file.

      • Chris says:

        Yes I’am. For example I press start on the pad it throws out number 8 which is the 8th command on the button list form the code. Everything works fine for second controller data.

      • Florian says:

        Did you manage to solve the problem? One solution for this would be to adapt the key map from RetroArch. When I wrote the SNESDev I had the buttons from the first controller mapped to the number keys 1 to 8, but the current version in Github has the same mapping as RetroArch expects it to be for the first controller …

  17. Folkert says:

    Wow, that’s a nice project! You might consider using an old SNES as a casing, since it already has the two controller ports and it looks awesome.
    I was wondering if the emulator you use is run on top of an X-server? Or are you using a hardware accelerated framebuffer?

    • Florian says:

      Cool idea with the SNES case!

      The emulator is running directly from the console without X. I am not sure if any kind of hardware acceleration is used right now – ToadKing could probably tell you more about this.

  18. Shawn Busker says:

    Would this work for NES controllers too? If not what modifications would need to be done? I am currently planning on making a case for my Raspberry Pi from an NES, so I would like to be able to use NES controllers with it using the original connectors.

    Shawn

    • Florian says:

      Hi Shawn,

      this would also work for NES controllers. From what I read so far, the code from my Github repository should work out of the box. The BES and SNES controllers have (nearly) the same polling protocol.

  19. Miles says:

    This is amazing, I am looking at modifying it for a Raspberry Pi installed in a Gameboy, I need the GPIO pins tied to individual buttons, there are only 8 buttons. I thought of using a NES controller IC I have here, but I would prefer to just wire the buttons to the GPIO pins.

    I assume that if I edit the code I can get it to accept 1 pin as one input instead of reading a serial chip.

    Looking forward to any plans to emulate a standard USB gamepad for compatibility with a wide range of programs.

    • Florian says:

      Hi Miles,

      thank you! I like the idea with the Gameboy – do you plan to use the Gameboy as a case only or do you even plan to attach an LCD display to the RPi? Take care for the voltages – it just happened that the SNES controllers can be polled with the voltages provided by the RPi.

      I will continue the work on the SNESDev-RPi code in the next days and include a gamepad functionality.

      Hope to hear more from your Gameboy project!

  20. Matt says:

    Is this something you plan on building and selling once it’s complete? I’m a classic games collector and player, and I agree there’s nothing quite like playing with a real controller on a television in a living room. Problem is, I have so many consoles and games that having them all hooked up at once is a huge mess of cables and a real fire hazard.

    I’ve bought a handheld device called a Dingoo which can output to a TV, but the emulation isn’t always perfect, and you can’t use real controllers. Having a single console, not having to dig through my bins of games, and only swapping out controllers is something I would be willing to pay real money for, and I doubt I’m alone.

    Do you have a website or something where I can follow your progress and make a purchase in the future?

    • Florian says:

      Thanks a lot for this encouragement! There is still a lot to do before something like “a product” would be reached here. However, I plan to continue the work on this and any progress will be posted in this blog. So, I recommend to subscribe to the RSS feed ;-)

    • Florian says:

      Actually, I am not that deep within the RetroArch architecture. Without looking at the source code I would have a guess, but I do not want to say something wrong here. I assume that ToadKing could tell you a lot more about this.

  21. Daniel says:

    Hi. Congratulations for the nice work. You could also try testing MESS. MESS is a sister-MAME project which attempts to emulate several old computers, consoles and videogames that ever existed. It shares a lot of code with MAME, which it is gets its basis from, it is command line driven, good for integrating into frontends and works in Linux. http://www.mess.org/

  22. Smikey says:

    Great work!
    But I have one question. You wrote you use RetroArch. Do you use the Pocketsnes-libretro Port or the snes9x-Port? MarioKart works well on my Rpi, but Kirby’s Dreamland 3 runs slowly as hell ;)
    So I’m working on the exactly same thing, an ultimate retro-console-thing :)

    • Squarepusher says:

      Kirby’s Dreamland 3 goes into pseudo-hi res mode at specific levels (Level 1-2 for instance) – that on-top of an additional 10Mhz co-processor to emulate (Kirby’s Dreamland 3 using the SA-1 co-processor). This is processor-intensive.

  23. pikachu says:

    Cool! Would it work for a Sega Genesis gamepad?
    BTW, Buffalo already has USB versions of NES and SNES gamepads (search for buffalo classic gamepad in amazon.co.jp).

    • Florian says:

      The software would have to be adapted to the protocol of the Sega Genesis controller. I do not plan to do this, but you could add this functionality to SNESDev :-)

  24. Scott (@ScottsCreations) says:

    Hello, my brother and I are currently making snes ports with the gpio ports, nes power on / off and reset buttons as well as a GUI launcher for any emulator in Qt which is done and working. I am hoping a decent x driver comes out within the months but if not a qtEmbedded version of my GUI will come and so we dont have to run X. Watch the rasp pi blog we will be making a post about it soon. I think they like that stuff.

  25. Red1 says:

    I realize this wouldn’t be nearly as geeky or cool, but you could always just use a Retrode connected to the RasPi for controllers. I don’t think you necessarily have to be using a game cart in it for the controller part to function as well.

  26. Marcel Unbehaun says:

    hi! Today I commited a major code rewrite of my linux program/emulator launcher “typhon”.
    I don’t have a raspberrypi yet, but I’m sure it will work on it. (requires sfml2 master, tinyxml, opengl and/or some optional stuff for p3t ps3 themes or videos).
    To be updated (when 2.0 is ready) homepage with older vids, screenshots and themes:
    http://www.frostworx.de/?p=1
    google code project page with latest code:
    http://code.google.com/p/typhon-launcher/

      • Marcel Unbehaun says:

        great to hear you want to try it :)
        although the (re-)write of the current state took a lot of time, the commit itself didn’t.
        unfortunately I just found out that you need to build typhon with debug enabled (or better say not optimized cflags), else you only see the commandline help. sry for inconvenience. apart from that it should work just fine i hope…

  27. jwk says:

    This is pretty great – I’d been thinking about using a Raspberry Pi as a game console to replace my getting-flaky SNES. Nice touch using the original controllers instead of an adapter!

  28. Waterbury says:

    So, you are powering the SNES controllers with 5v? If so are the GPIO pins sending the controllers a logic high of 3.3v to Latch and clock, or are you just relying on them to pull the pins low? I’m also guessing that the resistors on that board are for interfacing the data pins to GPIO ins or are those for the LEDs you speak of?

  29. Fritiof (Sweden) says:

    Nice work! However, I may have noticed an issue with your code. Since you use the same clock for both controllers BUT the code isn’t aware of that you can lost some events, specially if you are using NES mouses that send their relative position since last poll. The controllers will count any poll signal, so even if you’re only looking on B the A controller will reset as well.

    Keep up the good work!

Leave a Reply

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.