Home » Blog » Software Development » SNESDev-RPi: A SNES-Adapter for the Raspberry Pi

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:

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:

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.

Check Also

Python module for MCP23S17 for use with the Raspberry Pi

Some time ago I revised the hardware design of the ControlBlock and added test points …

%d bloggers like this: