Built a USB foot pedal using the Arduino Uno

| geek

(W- and I are planning to go to the hacklab.to open house today. Hope to see folks there!)

This weekend was definitely an electronics hacking weekend. Whee!

It started when I found a three-way foot pedal at Active Surplus for the grand total of CAD 7.50. It’s the kind of foot pedal musicians use to control their equipment: metal, sturdy, and with an odd-shaped connector at the end. I’d been meaning to try foot switches as a way to control my computer (handy for transcription and for using multiple computers). I wanted to get into electronics, as W- enjoyed it so much. I was curious about the Arduino. I figured that making my own foot pedal would mean lots of learning, fun, and relationship-building time. Who knows, I might even get a productivity boost out of it.

USB foot pedal, then! I used my Kindle to look up which model of Arduino could be convinced to act as a USB keyboard. The Arduino Uno was the best bet, so I picked one up at Creatron, and W- got one too. With foot pedal and Arduino in hand, it was off to the house to see what I could make from it. First: figure out the switches. I’d forgotten to write down the labels from Active Surplus and the box had no information. No problem. I snipped the ends off the connector, stripped the wires, opened up the foot pedal, and started figuring out the circuit with the help of the 7-segment LED from the lab kit.

Programming the Arduino was straightforward. I’d already played around with debouncing buttons based on the sample code. I extended my code to debounce three buttons. I looked up Arduino USB keyboard resources (http://hunt.net.nz/users/darran/), reflashed the firmware on the USB chip (atmega8u2), looked up the USB keycodes to send, and wrote the code. I set it up so that left sends PageUp, right sends PageDown, and forward sends F13.

To clean up the circuit further, W- and I went to Active Surplus for the second time that weekend. I bought some headers so that I could solder the wires to them and slot them neatly into the Arduino Uno. I ran into people I know, and I found myself directing them towards the components they were looking for. I think we might be spending too much time at Active Surplus. ;) (But it’s fun!)

During the bike ride back, I was thinking about how to make the foot pedal even more awesome. W- had suggested differentiating between short and long presses, so I worked on that. I started getting confused with the different flags and variables I was using. I redid it as a finite state machine, and that was so much easier to write. (By golly, I did get to use that after all.)

So now I have a foot pedal that cost me around CAD 36.50, plus the time I spent learning how to make it. It doesn’t require a driver. It pretends to be a normal keyboard. Because I’m using function keys that don’t conflict with anything on my keyboard, I can use AutoHotkey to translate them to whatever I want: other keys, sequences of keys, commands, even context-sensitive shortcuts. I don’t have to reflash my firmware to change my keyboard settings – I just reload my AutoHotkey script.

It’s awesome. I’ve used it to flip through an e-book while eating lunch. I’m looking forward to using it while transcribing my presentations. I might remap it to other functions while drawing or programming.

One of the limitations is that the long presses can trigger key repeats. This is handy if you’re mapping it to something like down-arrow, but not so handy if you’re trying to use it as a keyboard shortcut prefix. I’d like to figure out how to control key repeat and key delay on a per-keyboard basis. If I can’t, I might either figure out how to selectively debounce the keys in AutoHotkey, or have a toggle that controls whether keys repeat.

Not at all bad for a weekend hack and my first electronic creation! I’ll ask the Powers that Be at IBM for permission to release schematics and code. (Ah, paperwork.) The circuit is basic (umm, switches), and I’m sure people will point out lots of ways it can be improved. In the meantime, here’s a picture:

C360_2011-08-21 22-16-23

Left: Foot pedal (it can rock forward or to either side), middle: really, really long USB printer cable (will replace with shorter one soon), right: Arduino Uno with the cable wired in and the program loaded.

I’m looking forward to catproofing it in my new project box. Not that anything can really be catproof in this house, but at least I can remove the temptation of wire strands and LEDs.

You can comment with Disqus or you can e-mail me at sacha@sachachua.com.