Step 12: Joystick and buttons

The GPIO cobbler board allows the controls to be hooked up to the raspberry pi directly. Without going into too much detail because I'm no expert, the on/off signals from the controls are seen by the raspberry pi and with a programming script, the signals are mapped to specific keyboard functions so the controls act as a keyboard emulator. Adafruit have an excellent guide here http://learn.adafruit.com/retro-gaming-with-raspberry-pi/buttons.

It was a lot of trial and error but in the end I used this script which I modified to suit my button layout https://github.com/adafruit/Adafruit-Retrogame/blob/master/retrogame.c.

Here is my script change at line 87

//   Input    Output (from /usr/include/linux/input.h)
{ 22,      KEY_LEFT     },
{  2,      KEY_RIGHT    },
{  4,      KEY_UP       },
{  3,      KEY_DOWN     },
{ 27,      KEY_C        },
{ 23,      KEY_X        },
{ 11,      KEY_Z        },
{ 24,      KEY_A        },
{ 10,      KEY_S        },
{  9,      KEY_D        },
{  7,      KEY_5        },
{  8,      KEY_1        },
{ 25,      KEY_ESC      }

Each line in this table contains two elements. The first is a GPIO pin number (where a button or one direction from a joystick is attached), the second is the corresponding key code to be generated by this control. A list of valid key code names can be found in the file /usr/include/linux/input.h starting around line 178. Remember to enclose each pin/key pair in {curly braces} with a comma between them. Basically the controls can be programmed to do the job of any key on a keyboard. 

<p>could I just use jumpers (female with one end striped) to hook directly to the pi's gpio pins for the controls </p><p>(search breadboard jumper wires)</p>
<p>You could. google the arcade gpio for raspberry pi layout...</p>
<p>You could. google the arcade gpio for raspberry pi layout...</p>
Im new to the computer world lol but how do i get mame on the pi 2
<p>You need to download the retropie image and flash that to your sd card.</p>
<p>Are you able to use an old computer monitor for this project?</p>
<p>I may try to make a scaled up version that doesn't need a battery (120 volt power bar and transformers or a modified atx supply)</p><p>with a full sized cabinet with a fullsized screen</p><p>im copying the old galaga machine my dad owns for dimensions </p>
<p>could I use standard header hookups from a pc front (they fit in) or jumper leads</p><p>instead of the cobbeler</p><p>also im thinking of making my own amp to drive larger speakers (high-power darlington)</p>
<p>could this potently be scaled up to a full sized cabinet. (software wise)</p><p>also are the sticks hooked up to the gpio or are they hooked up to a usb headder</p><p>im researching this for construction class and it would be a cool project that could stay in the room</p>
<p>is it possiable to create a Arcade Machine with Raspberry Pi running RetroPie, and with a two player setup? will it need a power supply or should i consider another option.</p>
I've only been on instructables a day n checked out a couple of hundred so far of all kinds, this is definitely the coolest thing I've seen so far, something I'd have a crack at when I've got the time n tools. respect ?
<p>12V and -12V makes 24v lol (read about ATX power supplies for negitive voltage) should be marked 0V</p>
<p>a good game box! </p><p>but it's not easy for general people to make it.</p>
<p>Is there an instructions on how to connect the battery to the components? </p>
<p>Wow...cool....another one for on the wish to do list!</p>
just thinking can u attach the buttons to a GPIO extension cord? i am a noob when it comes to GPIO. i am planning to make a controller using arcade buttons and joystick to use with the pi. and then u can connect the pi to to a tv. thanks in advance
It is easy enough to lengthen the wires between the buttons and the GPIO. If you are making a controller unit (similar to a tankstick) the Pi can be neatly fitted into it. Check out <a href="http://m.instructables.com/id/MAMEFrame-The-battery-powered-MAME-system/" rel="nofollow">http://m.instructables.com/id/MAMEFrame-The-battery-powered-MAME-system/</a><br> The Pi has HDMI out which is the best way to connect to your TV otherwise the AV and speaker out jacks would also work too. Hope this helps.
Is that a car battery? It is a bad idea to power computers directly from car batteries.
could you provide maybe a video or complete tutorial on wiring the buttons and programming them for functionality? <br>
mate can you build me one of these, I will pay cash and postage + your time
How did you drill the holes fot the joystick and the buttons? I'm working on something similar and I'm worried about that <br> <br>Thanks!!!
I used a standard holesaw in a cordless drill and didn't apply pressure while it cut. The weight of the drill did the job. The trick is to not let the holesaw get hot and melt the acrylic.
Do you think that is better a hole saw than a forstner bit to drill the hole?
I'm no expert but the holesaw worked for me.
Looks really cool but it would cost to much for me to make
This is really cool. I'd like to make one but don't have a scroll saw and won't be in my budget for a while because of other projects I'm working on. If I had some of the dimensions I could out source laser cutting of the acrylic pieces.
I've been unable to get this answered by anyone. Can you tell me what version of mame piMAME is based off of?
I found that piMAME runs a version of 0.106
Mame4all uses 0.37b5 roms and advancemame uses 0.106 roms but some are not compatible so you have to try each rom to see if it will work.
Ah, thank you for clarifying that.
Wow, excellent stuff! <br> <br>Can we have links to the components please? <br> <br>:)
You should make a video of you playing it!
Incredibly well thought of, and all made using a scroll saw, and heat bending! Your work is an asset to FabLabers to inspire upon! :) <br>Blogged, of course: <br>http://faz-voce-mesmo.blogspot.pt/2013/08/prata-e-cera-em-3d-um-arduino-para.html
&quot;There is plenty more information that I could put in here.&quot; <br> <br>Please do. I think the point of these posts is to instruct, not just to show off what you made. Links to source the parts, or at least part numbers (not just descriptions), would be very helpful. <br> <br>More details are needed to make this truly something others could follow. <br> <br>It's a wonderful project, please make it a wonderful instructable.
How do you use a bandsaw to cut interior shapes? That does not work. A bandsaw blade is one continuous loop. The device you showed use of is actually a scroll saw (or table jigsaw).
Yes my mistake (amended)
This project should be called &quot;building an acrylic case for a Pi Arcade machine&quot; as you didn't really go into where you got your parts, the software setup at all, how you got games on it, how you interfaced the controls. It was a cool instructable, on how to build a case.
Hey can you post a video on how to install the components and buttons and joystick
Sorry I don't have a video of how its done but you could try here for reference http://www.slagcoin.com/joystick/mounting_layering.html
sweet project!
A &quot;coin&quot; button? Real coins are way cooler. (And they give you a way of keeping tabs on the amount of time you spend playing...)
very nice
Great job!!!
Well done. Great use of an old theme with new technology. Your concept could be well adapted for use as a training tool. You'd make any mum proud! karna.
Is there any additional information I need to know because I am wanting to build one and does it require roms
Yes you will need roms check out http://mamedev.org/roms/ they have some free public domain roms for non-commercial use

About This Instructable




More by krimmy:NaCade - The Naked Raspberry Pi Arcade MachineAll-in-One Solar Home EntertainmentSolar Powered Floor Lamp
Add instructable to: