Our Blog

Making an Arcade Cabinet Without Soldering, Part 1: the Keyboard Encoder

A while back I went to the Game On exhibit at the Ontario Science Centre, and fell in love with the form factor of cocktail arcade cabinets. These are the arcade machines where players sit across from each other and play vertical games, where the screen flips orientation depending on whose turn it is.

I planned to use my arcade cabinet for demo-ing games at game jams, for teaching kids (I find they like to hit buttons more than just mouse and keyboard), and for playing lots of Burgertime.

It’s worth noting that all of this can equally apply to making a USB “GO” button for QLab or any other theatre playback software. There will, though, be a separate tutorial for that, because in theatre you want physical redundancy.

If you’re reading this, then you probably already know what MAME is. I figured I’d just cut open an IKEA table (the <$10 Lack), wire some joysticks to an old usb keyboard, and plug it in to an old Windows XP computer running MAME. Simple. Mame table v1

Well, I did that, and ended up with a coffee table with a hole in it and an unreliable controller. Not that it didn’t work, but it was messy. I also burned out the display driver on the lcd monitor somewhere in the assembly process.

Soldered to Keyboard matrix
I soldered an old hard drive cable to the circuit board of a keyboard, then broke that out to screw terminals.
The thing about keyboards, is they use matrices, so rather than each key having a “hot” wire and a common ground, they all share from two different “axes” of wires, meaning I had to first figure out which combinations made which keys, and then sort out the wiring for all the buttons.
Spaghetti

So, here’s round two, with a little less hacking, and no soldering.

Instead of the old keyboard, I’m using an Arduino Leonardo. You could also use an Arduino Micro (note: not Nano) or a Teensy. All of these boards come with the ability to emulate a mouse or keyboard (or in the case of the Teensy, also a joystick or midi keyboard) without any additional firmware flashing. Unlike the keyboard hack, with these microcontrollers, you can wire one input to each button, and have them all share a ground, for much easier wiring. They also have built-in pull-up resistors, so no additional hardware is needed either. I bought a header cable with the same spacing as the arduino inputs, and crimped on a female to the loose ends.

Here’s my Arduino code. It’s a slightly modified version of the Keyboard and Mouse Control example script.

int buttonPins[] = {2,3,4,6,7};          // input pin for pushbutton
char keys[] = {KEY_UP_ARROW,KEY_DOWN_ARROW,KEY_LEFT_ARROW,KEY_RIGHT_ARROW,' '};                
#define NUMBUTTONS sizeof(buttonPins)
int previousButtonStates[] = {HIGH,HIGH,HIGH,HIGH,HIGH};   // for checking the state of a pushButton

void setup() {
  // make the pushButton pin an input:
  for (int i=0;i<NUMBUTTONS;i++){
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
  // initialize control over the keyboard:
  Keyboard.begin();
  Keyboard.releaseAll();
}

void loop() {
  
  for (int i=0;i<NUMBUTTONS;i++){
        // read the pushbutton:
        int buttonState = digitalRead(buttonPins[i]);
        // if the button state has changed, 
        if ((buttonState != previousButtonStates[i])
          // and it's currently pressed:
        && (buttonState == LOW)) {
            Keyboard.press(keys[i]);
        }
        else if ((buttonState != previousButtonStates[i]) 
          // and it's currently pressed:
        && (buttonState == HIGH)) {
            Keyboard.release(keys[i]);
        }
        // save the current button state for comparison next time:
        previousButtonStates[i] = buttonState;  
  }
  delay(20);
}

First, we set up an array for the input pins, an array for the output characters (note: single quotes for characters, double quotes for strings).
We loop through the inputs and set them to INPUT_PULLUP.
Note that because we’re using USB communication, pins 0 and 1 are not available for use.
Then, every iteration of the main loop, we loop through all of the inputs, check if they’ve changed state since last time, and if so either send the corresponding character, or release the key. We use Keyboard.press as opposed to Keyboard.write so that keys can be held down.
There’s a 20 millisecond delay as a crude debouncer. Adjust as you see fit (i.e. as low as possible without false positives).

That’s it for the software. Plug your Arduino into a computer (or android or whatever) and go nuts.

Up next, Part 2 will talk more about the enclosure I made.

Comments ( 0 )