Raspberry Pi joystick

After getting MAME going on my Raspberry Pi so that I could play old arcade games. I wanted to hook up a proper joystick. Back in the 80′s I had the excellent and ubiquitous Competition Pro 5000. As mine (foolishly) got sold with my Amiga stuff I got one on eBay, and it came in the original box:


The first step was to get it hooked up to the RPi general purpose input output (GPIO). I used a breadboard with my homebrew Pi Cobbler at one end and a similar connector at the other hooked up to an old PC serial card cable that has the right (male) DB9 connector for the joystick plug (female). It was then just a matter of adding some pull up resistors (10K) and some patch cables:

Since I was originally planning to use gpio-keys I used the joystick pinout to hook up to the RPi thus:

1. Up -> 11 (GPIO 17)
2. Down -> 13 (GPIO 22)
3. Left -> 15 (GPIO 23)
4. Right -> 16 (GPIO 24)
5. n/c
6. Fire -> 7 (GPIO 4)
7. n/c
8. GND
9. n/c

Blind Alley

Having already seen gpio-keys I thought I’d be using that, but when it came to the crunch I didn’t know where to start – I probably need a package of RPi kernel source. On reflection I probably really wanted gpio-mouse anyway.

After some digging around the Raspberry Pi Forums I found a comment about using Python to generate keystrokes. This got me headed in the direction of Python uinput, which is a module that can create keypresses.

sudo modprobe uinput
git clone https://github.com/tuomasjjrasanen/python-uinput
cd python-uinput
sudo python setup.py install --prefix=/usr/local

Smelling victory I knocked together some code that turns GPIO into keypresses. Sadly it seems that AdvMAME derives it’s input in such a way that completely ignores uinput for keyboard. Back to the drawing board.

The right(ish) approach

Digging around the examples for Python-uinput I found one for joystick, so I had a go at creating a GPIO connected variant, and with that saved as rpi-gpio-jstk.py it was a simple case of running:

sudo python rpi-gpio-jstk.py &

I tested using advj, and it showed input. When I fired up AdvMAME the joystick worked – horray – time for some gaming:)


Read More: Raspberry Pi joystick

About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation, and engineering. I have a clear and simple writing style and am skilled in using infographics and diagrams. I am a great researcher and is able to present information in a well-organized and logical manner.

Scroll to Top