Keyboard Encoder for MAME Arcade

97K12735

Intro: Keyboard Encoder for MAME Arcade

Here I will show you how to make an encoder for a MAME arcade (or similar) from an old USB keyboard that you most likely will have laying around in that pile of stuff you'll never use (I've got 3)

I recently made and published an instructable on a home made arcade machine using a raspberry pi as the brains. I had a couple of questions about the keyboard encoder that I used. Initially I had planned to write a program that would boot to a list with a selection of games to play and the user would use the joystick and buttons to toggle through the list and select a game.

This turned out to be a hell of a lot trickier than I first thought, mainly due to the fact that the keyboard encoder I bought wasn't spitting out any thing that I could easily read in Linux. So I decided to "build" an encoder that would.

STEP 1: What You'll Need

An old USB keyboard

Lots of different coloured wires

Soldering iron and solder (optional I'll explain later)

Some sand paper (150grit or higher is ideal but use whatever you have)

Multimeter (optional, but highly recomended, again will explain later)

General tools (screw driver, wire cutters, scissors etc.)

STEP 2: What Is the Encoder

Inside every keyboard there will be a little circuit (the encoder) that takes key presses, turns it into a signal the computer understands then shoots it down a wire so the computer can use it. It does this by using a matrix type setup. The way I think about this type of setup is that it's one that has multiple grounds (that are independent of one another) and multiple highs (which are also independent of one another), they are linked together in a way that produces many different combinations. the advantage is you don't need many I/O's to have a large array (say something like all the keys on a keyboard) of switches. This is probably an inaccurate description of how it works but it helps me wrap my head around it and understand it.

STEP 3: Getting to the Encoder

You will nee to dismantle the keyboard by removing every screw you can find. Sometimes electronics snap lock clips, if so pry it gently with a screwdriver until you've taken it apart. The encoder will be located usually in the top right hand corner (or wherever the lights are for caps etc).

STEP 4: Mapping the Keys You Need

Ok this is where I recommend you use a multimeter as doing it by eye can be damn near impossible (well not impossible but just really really really really annoying) you could also use a battery, wires and a light for this but the multimeter makes life really easy.

Inside the keyboard you'll also notice that there are  two bits of plastic film that kind of look like a PCB separated by another bit of film (usually stuck to one of the others).

There should be dots and lines all over it and you'll need to identify which dots correspond to which keys. the easiest way to do this is to count. So the A key on my keyboard 4 down, 2 across (ESC being 1, 1). so get the position of the keys and then count the dots.

Then use a multimeter to find out where these keys joined up to the contacts. Set your multimeter to conductivity mode (set the beep if you can) place on of the terminals on the dot (say for the A key) and run the other terminal along the contacts until it beeps or acknowledges conductivity. Make a note of which contacts they are. I labeled mine 1 - 13 and A - N and just wrote it down. it also helps to mark out the keys with a marker so you don't forget any.

STEP 5: Prepping the Encoder

There is sometimes black conductive stuff over the metal of the PCB. This will need to be removed CAREFULLY with sand paper. Once the metal is exposed clean it up with some paper towel as best you can. You should then go along and tin these with a small amount of solder. You will then need to prep your wires in the same way, i.e strip them then tin them

place the tinned wire on top of the tinned contact and press the soldering iron on it gently, wait until the solder liquefies, remove the iron and hold the wire as steady as you can until id hardens again.

If you're not confident in soldering and don't want to do this you could always use conductive adhesive (eg. WireGel). But I reckon solder would be the better and quicker option as most contact adhesives need to cure overnight.

STEP 6: Finished Product

I probably wen a little bit overboard with the wires but I do plan to run a number of buttons and controls. you really only need wires for buttons you intend to use.

In the case of mame up, down, left right for directional controls, Z,X,C,V can be used for buttons and Tab so you can get into options (you might also wanna put in a button for credits)

now all you need to do is hook it up to your buttons as you would a regular encoder. For more information on that you can look here at step 3



29 Comments

A programming problem:

I needed a bunch of inputs for a Escape Room program I created. I built the keyboard and attached contacts for letters a thru z. The problem is simultaneous keystrokes need to be decoded...keyboard keys don't debounce and therefore reading several simultaneous keystrokes presented a huge programming problem.

In the end buying a few off the shelf MAMEs was the easiest solution. Each MAME provides 12 buttons and Windows individually identifies each unit via hidusb.sys as a HID (Human Interface Device) with letter designations: A, B, C, etc. Polling inputs are performed by assigning hex values to each EG: 1, 2, 4, 8, 16, 32, 64, 128, 256, etc to each button and decoding the result. If the resulting input for MAME "C" is 7 then buttons 1, 2 and 4 are currently making contact on MAME "C". EZ-peazzy

I have a question, I wanted to know how to wire up the microswitches like I have A8 B5 for A and A7 B5 for W, so do I draw multiple wires from B5?

Hey so im fairly new to electronics and stuff so sorry if question is dumb

but where does the ground wire go?? im honestly not sure.

On this specific setup, there is no ground... The IC on the controller has this. Instead, the pins are split up into sections on 13 on the left and 13 (sometimes 12) on the right. (depending on the IC and or keyboard). Just get yourself a naming convention and stick with it. I named all the pins on the left "A" and "B" for the right. Now short out any of "A" with any of "B" and see what button is pressed. A nice tool is www.keyboardtester.com. It highlights a key once pressed so slide short all the wires that look at the screen and see which buttons are marked green. If it;s green, the combination works, if its white, then something didn't make contact... So in my case "A8" + "B10" = up... etc...

don't have the keyboard plastic parts, only the actual pcb and usb cable, is there a way to determine which point is which?

you can probably just do the "read" function and start shorting one trace to another

I found this indestructible and found it helpful as it provide me with the idea that this is a solution. That being said I wish I would have none that you can accomplish the same thing using an arduino keyboard emulator software like shown here http://hackaday.com/2012/06/29/turning-an-arduino-...

... just wanted others to know other possibilities exist. Hope someone else finds this information helpful.

Cheers!

Yeah the arduino HID way is a nice way of going about it. But the idea of this was to up-cycle things you have laying around or can acquire for a few dollars. Thanks for the link too, it might help some people.

Great idea and well explained!

Wonderful !!! Great Job :D

This is a great re-use of old keyboards. For those with less time and more money, there are a few other ways to get an arcade keyboard for an emulator: the tried and trusted iPac: http://www.ultimarc.com/ipac1.html (downside - PS2 connector - although for dls3491 that's actually an advantage...); the MakeyMakey http://www.makeymakey.com/ and the many bluetooth devices from ion which can often be found very cheap http://www.ionaudio.com/products/details/icade (Ignore the $99 price, look around for closeouts or used ones. You just want the controller board)

There are also some newer Chinese encoders for $10 to $20 that I haven't seen myself but look to be what's needed - https://www.google.com/#q=NO+Delay+USB+Encoder+PC+to+Joystick+Arcade+MAME&tbm=shop or

https://www.google.com/#q=Xin+Mo+Arcade+to+USB+controller+2+player+MAME+Multicade+Keyboard+Encoder&tbm=shop

Thanks I am planning to use it on a pc that has a ps/2 connector
do you know if this will work with a ps/2 keyboard ?
It should do, can't see any reason why it wouldn't. Of course you'll need to use an adapter if you want to use it via USB, but otherwise it should be fine.
Hi Spartan - I see one of the plastic films only has 8 lines, does that mean you can only use 8 different keys?
I note in your MAME instructable, you only use a total of 8 keys/buttons/letters.
Is that correct?
Thanks
No you can use more than 8, you can use as many as there are inputs on the keyboard I suppose.

I did use only 8 buttons for play (up, down, left, right, b1, b2, b3, b4) but there are now buttons on it for start, coin/credit and when I stop being lazy and put a second set of controls for another player there will be 1 player and 2 player buttons too.

This webpage does a better job than I do explaining how a matrix works.

http://pcbheaven.com/wikipages/How_Key_Matrices_Works/

Hope it helped if you need more info just pm me
Wait, why did you do it like this and not just wire it all up, open a word document, and figure out what each key was mapped too?
Is it just because some inputs aren't valid so you have to map it to a valid input?
Pretty much, there's no point really in using a word doc to find out where up down left righ and ctrl are for example. you can use cmd or terminal etc. and the read command (or equivalent) but it's a lot of messing around. Also you don't need to solder on as many wire as I did to be honest I went a little over the top, so it's probably best to get a whole heap of keys you'll be using and just solder the ones needed. Cheers.
More Comments