Raspberry Pi Arcade controls.

As I’m still not very mobile and jobs put of until I am,  I thought I’d get my Raspberry Pi out and have a play around with the GPIO headers to see if I could connect them to a few  arcade controls. I’ve not really used my Pi that much since the ‘AtarBerry project’ and now that my Ouya is taking care of  XBMC duties, said little Pi is a little redundant.

My first job was to format a spare 4GB SD card, download the latest copy of Raspian (wheezy) to start off with a fresh canvas. I was already to start after prepping the SD card  when sadly,  I hit my first snag of the day! No matter what I tried I simply couldn’t  get the Pi to boot…in fact, I couldn’t even get it to display anything on screen at all. The power light was lit and a very very dim green ‘OK’ light was lit.

I spent an hour browsing around the Raspberry Pi support forum and it appears that this is quite a common problem and points to either a failed Pi, a dodgy power supply or an iffy SD card (not much then!). Well, the power supply checked out o.k with the  meter and the SD card could be read/written to on my PC. I swapped out the power adaptor for another (I’m using a USB mains adaptor from my iPad) and I also tried a few other SD cards but still no joy.

I disconnected everything  apart from the power cable and tried again but I was still getting  nothing other than the Red power LED and the faint Green LED.

On close inspection I couldn’t see anything wrong with my PI until I took a closer look. There, stuck right at the back of the SD card slot next to one of the header pins was the tiniest piece of blue plastic. It’s the same colour plastic as my SD cards and I can only guess that whilst swapping between different SD cards (I tend to huse separate SD cards with different  O/S builds/functions) , a piece of plastic must has been shaved off. Maybe the slot is slightly misaligned?  Anyway, after removing the offending blighter with the help of a pin (it was that small!)  I switched my Pi on and it booted perfectly…yay!

After the initial setup via SSH  from my main PC, I  installed Mame4All and FTP’d over a few test roms to check the everything was good to go.

…..some time later (Phoenix is such a classic game!), I dug around in my spare box to see what I had to use.

Here’s what I came up with

  • A Bat topped Sanwa 4/8 way stick.
  • Two arcade buttons with clunky microswitches that were previously swapped out from my iCade. 
  • A fistfull of coloured wire taken from the remnants of an old Jamma arcade loom.
  • Female Lucar terminals.
  • A header block from an old PC that was used for connecting USB ports to the motherboard.

Here I’ve started cutting and crimping the cable ends and fitting them to the USB header block. I originally thought about reusing those two PC floppy drive cables instead but the USB header block was working out much better and with eight holes I’d only need to use the one block.  In total, I’ll need seven cables – four for the joystick controls, two for the buttons and one (daisy chained) common ground cable.

DSCF0099 (Custom)

 

The GPIO header pins are slightly different on each version of the Raspberry Pi. Mine is an early Model B board so the header looks like this. It so happens that there’s a nice line of pins (including a GND)  flowing in one straight line going from GPIO0 through to GPIO22. Perfect for my block.

Raspberry-Pi-GPIO-Layout-Revision-1

 

All looking good so far. Now to crimp and attach the control swtiches.

 

DSCF0105 (Custom)

 

It’s a bit messy at the moment but I’ll tie wrap these up later on.

 

DSCF0107 (Custom)

 

Back on the PI, i downloaded this rather handy program to help configure the pins so that they map to keyboard inputs. There’s also really handy guide that comes with it too – https://github.com/adafruit/Adafruit-Retrogame/archive/master.zip

Contained within the zip file is a sample config file that will need editing and  recompiling to suit your own wiring configuration if not using the defaults. There’s also a handy test program so that you can check that all is working o.k  I hit another snag though as  I struggled to get my controls to work at first and there was much in the way of  head scratching and coffee breaks.

Pi connected to the TV and nano via SSH to edit the config file.

DSCF0110 (Custom)

 

The original config file has a few lines that read like this –

{ 17, KEY_RIGHT },

Which basically means pin number 17 should map as cursor key right.

So all you have to do is change the pin numbers to reflect your own wiring and enter an appropriate keymap. Mine was changed to read –

{ 0, KEY_RIGHT }, – which is  is the red cable in the picture above.

 

Try as I might, when I tested again, the controls simply didn’t work.

As a test, I restored the config file to it’s original state and wired in only one control to the same pin header as listed in the file. Namely –

{7, KEY_LEFTALT},

It still didn’t work…….more coffee!

I tried again but this time I replaced ‘KEY_LEFTALT’ with a regular letter key. Namely ‘D’.

It flippin well worked this time!

So, using the old retro classic layout Q,A, O & P I changed the file and recompiled.

{ 0, KEY_P },
{ 1, KEY_O },
{ 4, KEY_Q },
{ 17, KEY_A },
{ 21, KEY_Z },
{ 22, KEY_X }

With Mame loaded, i went into the usual option menu and remapped the controls.

It all seems to be behaving really well now. I’m guessing this setup could now be used with other emulators.

DSCF0108 (Custom)

 

Now to think about a case….after one more game!

 

 

 

Advertisements

6 responses to “Raspberry Pi Arcade controls.

  1. Nice Job! As my time is getting shortet and shorter I only could take a quick look at ChameleonPi (http://chameleon.enging.com) and was quite impressed… not about the loading time, but about th emulators. The nex incarnation of Pi migh probably end up in my Arcadecab, instead of the old Xbox. 😉 I wish I had more time to tinker with all that stuff that piles up on my desk.

  2. Thanks mate, I’ve just been playing around with the control config files again and think I’ve got it working properly to KEY_LEFT, KEY_RIGHT etc I’m not sure why this wasn’t working yesterday – maybe a reboot? I can now navigate the MAME frontend menu with the joystick.

    I’ll be looking at Chameleon at some point as it’s one of those things i made a mental note to check after seeing some of the screenshots.

  3. Hello stiggyworld
    i become very mad with this utility, i’m not really good with linux.. i changed settings to this:
    { 25, KEY_LEFT },
    { 9, KEY_RIGHT },
    { 10, KEY_UP },
    { 17, KEY_DOWN },
    { 23, KEY_LEFTCTRL },
    { 7, KEY_LEFTALT },
    { 0, KEY_KP4 },
    { 1, KEY_KP6 },
    { 2, KEY_KP8 },
    { 3, KEY_KP5 },
    { 4, KEY_KPMINUS },
    { 5, KEY_KPPLUS }

    (you can see i added keypad mapping to have a second joystick connected for 2 players games)
    but i get a lot of errors, it compiled only one time but it didn’t work i do not know why :(((
    could you help me please?
    thank you in advance
    Juri

  4. Hey Juri,

    I always had difficulty getting special keys like CTRL and ALT to work when I first tried this myself therefore I used regular letter/numbered keys instead.

    Are you getting errors when compiling the file?

    Regard

    StiGGy

  5. hello, yes i don’t know, i’m not expert of linux world, maybe i’m missing some files.
    i tried replacing LEFT CTRA with normal keys but no success.
    i do not know why first time it compiled without errors (the resulting file did not work however) now it not compile anymore

  6. Hmm, something doesn’t sound right if it won’t compile at all, especially if you’ve only amended the key mapping and nothing else. Because it doesn’t take very long, is it not worth starting again with a fresh install of the o/s?

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s