At this point you should have one (or more) games playable from the keyboard. The next step is adding nifty controls…
If you’re aiming for a home TV gaming console feel, things are super easy: a variety of USB-compatible gaming controllers exist that’ll plug straight into the Pi and you’re done!
If aiming to simulate a particularly nostalgic console, chances are you can find an equivalent controller in USB format. Look around a site like NewEgg or just Google search for some options…I’ve seen classic-style controllers resembling the NES, Genesis, Playstation and more, as well as USB adapters if you’d prefer using actual original controls.
Pictured: Logitech F310
Arcade and Handheld Gaming Controls
Let’s look at arcade-style controls first, since they’re physically larger and thus easier to work with…
Just as there are USB console-style controllers, so too are there USB arcade-style setups. They’re often a bit costly though…also, nearly all of them are laid out for 1990s fighting games. If the ready-mades meet your needs, fantastic. But maybe you want something simpler, or may have ergonomic preferences (I’ve always prefered right-handed joysticking, for example). Making your own control box (or even a whole cabinet) is a satisfying DIY project!
This is where things take a creative turn. There’s no One Right Way™ to arrange controls that can cover every game. Instead, pick a few favorites and devise a layout that handles the most frequently-used inputs well. For everything else, you can still use a keyboard.
You’ll also need to build your control panel using the materials and tools best suited to your own skills. I’m fortunate to have access to a laser cutter that can work with acrylic, but that’s a tall order for most. Scrap plywood or a metal project box are viable materials (a cigar box works great too!), while a drill, hole saw, Dremel tool or wood rasp are all reasonable tools for making holes. Improvise!
We have a nice assortment of arcade-style controls in the shop…
Our Small Arcade Joystick is the gamer’s equivalent of the IBM Model M keyboard — clicky and built like a tank!
This is an 8-way “digital” joystick. Most classic games are designed for this type of stick, and it’s easy to interface…the Raspberry Pi can’t read proportional “analog” joysticks directly.
Our 30mm Arcade Button is available in six different colors and is similarly industrial-grade. Any momentary push-type button (“normally open” contacts) will also work.
A classic Atari or Commodore joystick can also be used, since these are just passive switches internally. Most later gaming consoles used serial protocols for their controls…unfortnately those won’t work here…but as mentioned previously, USB clones exist for most.
The controls will be wired to the 40-pin GPIO (general-purpose input/output) header on the Raspberry Pi board.
Early model Raspberry Pi boards had a 26-pin header…same idea, just with fewer spots to connect things.
Each pin on this header has a unique “GPIO number” …not in-order, but we provide a map below for translating. Buttons and a joystick (each of 4 directions) will connect between any available GPIO pin and a ground (GND) pin.
This map is turned 90- degrees from the photo above…so the 5V pins are nearest the corner of the board, while GPIO21 is nearest the USB connectors:
- All of the green pins are fair game for connecting buttons.
- Yellow pins may or may not be available for controls, depending what hardware features are enabled on the system:
- GPIO2 and GPIO3 are off-limits if using any I2C peripherals (for example, most real-time clock boards).
- GPIO14 and GPIO15 are off-limits if using the TTL serial port (for example, with a serial console cable, or thermal printer).
- If using one of our PiTFT displays (as most of our portable gaming projects do), another seven GPIO pins are out of commission: GPIO7-GPIO11 and GPIO24-25.
- Our I2S audio amplifier board needs GPIO pins 18, 19 and 21.
- Avoid red pins, these carry power and aren’t suitable for controls.
- Black pins are ground points. The other leg of each button (and the “common” pin from a joystick) will need to connect to one of these. There are several scattered around…if you need more, one of our small Perma-Proto boards can be used to provide a single large “ground rail” where one side of all the buttons can be connected. Alternately, if you have extra unused GPIO pins and just need a couple extra ground connections, we’ll show a software work-around for this.
Most any “passive” joystick or buttons should work — that is, they’re internally just mechanical switches. This is the most common type. There are some higher-end sticks and buttons using optical sensors that require power and output inverted logic, but our Retrogame software doesn’t handle these.
Do I need Pull-up or Pull-down resistors?
You do not need external pull-up resistors for the buttons or arcade controller…they can wire direct to the GPIO pins and grounds. The Raspberry Pi has its own “internal” pull-ups.
Just as the layout and build technique of the control panel requires creative interpretation, so too will you need to decide on your own wiring methodology. We have some parts that can help. Aside from the aforementioned Perma-Proto board, there are quick-connect wires that work with the buttons and jumper wires in various lengths that can be used with a joystick or plug directly into the GPIO pins (without a Perma-Proto board). Options abound! You’ll likely need some combination of these, and may need to solder some connections.
Here’s a pinout diagram for our arcade stick. Only one wire needs to go to GND, then each of the other four goes to a different GPIO pin.
These directions apply when the stick is oriented with the header at the top. It’s fine to install the stick in a different orientation, you’ll just need to adapt the wiring connections to match.
If using quick-connect wires for buttons: the end plug tends to block adjacent pins on the GPIO header. You can trim it down a bit using an X-Acto knife or Dremel tool, or cut the plugs off and solder the wires to a Perma Proto board, or simply plan out your wiring to avoid nearby pins…
- Joystick UP: GPIO10
- Joystick DOWN: GPIO17
- Joystick LEFT: GPIO25
- Joystick RIGHT: GPIO9
- Button A (one contact): GPIO23
- Button B (one contact): GPIO 7
- Joystick Ground, Button A & B second contacts: GND (theres a bunch of GND pins available)
(This works fine with just HDMI TV output, but not with PiTFT displays which require several pins for their own use…you’ll need to work out a different pin mapping in that case.)
Here’s a basic no-soldering wiring setup we use for TV gaming with one joystick and two buttons, using 5 female-to-female jumpers (small white squares) for the joystick and two unmodified quick connects (larger white rectangles) for the buttons. Notice how the quick connects each span a GPIO and adjacent ground pin.
It’s a pretty basic layout, but sufficient to accommodate quite a few classic games. For the remaining seldom-used functions (coin insert, start game), a regular USB keyboard is kept nearby.
An example case I made from laser-cut acrylic, but any workable material will do. A cigar box makes a great fit!
The case should be at least 50mm (2 inches) deep to accommodate the buttons and solderless connectors.
The shelf at the top holds a small USB keyboard. This is a catch-all for seldom-used functions (e.g. coin or game start). Only the essential controls were assigned to arcade buttons…but keep adding others if you like!
I no longer have the vector files for this laser-cut case. To be honest, it’s pretty crude and minimal, and I would encourage you to design your own with all the controls you like, in whatever materials you’re most comfortable working with.
Adding More Buttons
Here’s an example layout if we want to add six buttons plus a joystick, using the same button quick-connects:
This layout avoids most of the peripheral pins (e.g. I2C), but does use pins that would be required for a PiTFT display…so this is only viable if using HDMI or composite video out.
This is mostly due to the size of the button quick-connect plugs. Trimming the flanges off with an X-Acto knife, you can probably create a more compact arrangement.
“A”, “B”, “X” and “Y” here refer to the controller button names used in EmulationStation, not necessarily the keys to which they’re assigned.
Sharp-eyed readers will notice the “Y” button is connected between GPIO 5 and 6, rather than 5 and GND. On the “Configuring Retrogame” page, we’ll explain how one or more GPIO pins can work as makeshift GND connections.
Example: A Mini Portable Gaming Handheld
For handheld projects, the principles are the same as above, just squeezed into a very constrained space. Smaller components are used and the connections are a bit more challenging.
You’ll find examples in our PiGRRL, PiGRRL 2, Pocket PiGRRL, PiGRRL Zero and Super Game Pi projects.
Most of these use a PiTFT display, so there’s a set of GPIO pins that are off-limits. Otherwise, it’s all the same idea…buttons wired to GPIO and ground pins.
The Raspberry Gear project uses a different approach…a microcontroller acts as an intermediary to the Pi’s USB port.
In earlier projects, we’d hack apart an actual game controller to repurpose the buttons and circuit boards. More recently, we’ve started producing custom gamepad PCBs to which buttons and wires can be soldered:
Text editor powered by tinymce.