Stokes' ProjBlog

A journal documenting innumerable, mostly terminally in-progress undertakings. Nerdiness abounds.


Check Out my (Atari Key-)Pad, Part 3: Making it Work September 11, 2013

Filed under: The Atari Keypad Project — Stokes @ 11:13 am

Keypad HookupNote: for some reason, something in the combination of the code listings in this post, the syntax highlighter I’m using (Crayon), and my theme causes rendering problems in some browsers. I apologize if parts are difficult to read. I’m looking into it.

To recap: In part 1, I figured out how the CX85 keypad works and how it’s wired; in part 2, I made a change to the Arduino’s HID library that will give me more control over the keypad emulation. Now, to write a sketch to drive it!

Hooking the keypad up to an Arduino Leonardo was trivially easy. I used a male DB9 on a ribbon cable, the serial port from an old computer. A simple breakout board (the most complex part of the setup) just widens the 2×5 header connector enough to fit across the gap of a breadboard, DIP style. I wired it to the Arduino somewhat out of order:

DB9 Pin Name Arduino Pin
1 OUTA 3
2 OUTB 6
3 OUTC 4
4 OUTD 7
5 OUTE 5
7 VCC +5V
9 (No connection)

This order was simply the tidiest layout on my little breadboard; I didn’t bother getting the OUT* pins in sequence. The only critical pin is DATA_AV, attached to Arduino pin 2; an interrupt handler listening to changes on that pin does all the work. It’s worth mentioning that pins 3-5 are all part of the same port on an Arduino Uno (specifically, PORTD), which I used for my initial experiments. The Leonardo uses a different microcontroller with a weirder layout of ports, so I’m just reading the inputs with old digitalRead(), but the consecutive pins are still useful for iterating.

The Arduino sketch itself is moderately simple. As I mentioned earlier, it uses an interrupt handler (handleKeypress())attached to pin 2 to actually handles the key presses on the keypad and send the corresponding USB keyboard scan codes. Note that the values sent as the first argument to sendKey() are the codes that the keyboard uses to represent the keys, not the characters.

What’s next? On the hardware side:

  • Use a smaller microcontroller board, one that can fit inside the keypad’s housing. The 9-pin cable is attached by a form of spade connector, so if I can find similar connectors, the entire operation can be done non-destructively.
  • Use an entirely different microcontroller, one without the Arduino bootloader. The Arduino Leonardo was great for prototyping, but it is much larger and more powerful than I need — and, at $20, more expensive. I could use a microcontroller like AT90USB82 with LUFA. Since all I really need are eight GPIO pins (two for USB, six for reading the keypad), and the device doesn’t have to respond much faster than its human operator, I could use an even smaller/cheaper microcontroller with software USB emulation.

On the software side:

  • Tidy up the sketch. The code isn’t the cleanest. Seeing it here, I can spot a couple of things I’d have done slightly differently, but these are moderately trivial. Better to post code I know works.
  • Get the ‘Play/Pause’ key to work. Maybe this is just a Mac thing, but I’ve seen a couple of things that imply that some of the farthest ‘multimedia’ keys function somewhat differently than the normal ones.
  • Rewrite for a completely different framework, like LUFA. This would make at least the first point moot.

If/when I continue this project, I’ll continue posting my progress on the blog!


Leave a Reply

You must be logged in to post a comment.