MicroChorder

I hacked together an Arduino Micro firmware that is a drop-in replacement for a Spiffchorder, long version and code below the fold.

My old Spiffchorder board is no longer enumerating on USB, so I decided I needed to replace it. I figured the right thing to do was replace with a more modern microcontroller that has an integrated hardware USB stack instead of VUSB and some zenier diodes, most likely an Atmega 32U4 because they’re about the right size, familiar, and available on nice cheap breakout boards (usually as “Arduino Micro” or similar).

While I was reading up, I saw that in the interim the original Spiffchorder folks had designed themselves FeatherChorder, which uses an Adafruit Feather Bluatooth LE to construct a Bluetooth 7-key chorder. The Feather BLE is, helpfully, a 32U4 Arduino with a Bluetooth module hardwired to the SPI pins.

So, the obvious solution is to grab the keyer-handling code from FeatherChorder, replace the Bluetooth HID functionality with USB HID functionality, and call it a day. In principle this is straightforward because USB and Bluetooth use the same scan codes (PDF Warning) and data format for HID devices, and there is a first-party USB Keyboard library for 32U4 based Arduinos. In actual fact, it’s a little annoying because the Arduino Keyboard library is easy instead of simple; the functions all take ASCII characters or #define’d magic numbers instead of scan codes, then beats them up to generate scan codes.

At this point I compared alternatives:
1. Try to hack it to work with the Keyboard library
2. Try to do it directly with the HID library
3. Make a modified version of the Keyboard library to match FeatherChorder’s expectations
4. Make a modified version of the Keyboard library that matches the USB HID spec
5. Just start from scratch

I gave (1) a quick pass and determined it would never work right for the whole keyboard, (2) would be ugly and involve a bunch of things that would be easier to do under (3), and (4) and (5) would be too more work than I wanted right now.

So (3) was the most pleasant/useful, and Keyboard_RAW which does modifier keys and such in a convenient-but-nonstandard way to match the FeatherChorder functions was born. It was still a small pain in the dick because C++ is a terrible language, but nothing out of the ordinary.

The library code is attached in case someone else wants to use it, but I’m not posting these things somewhere source-control-y because it’s an ugly hack to minimize the work between FeatherChorder and a working USB device rather than a quality general-purpose library, and I still like to imagine I can avoid contributing to the world being built on top of crap. The “right” solution is probably to add some raw functions to the keyboard library upstream.

A couple bucks to get whatever random 32U4 based Arduino Micro compatible knockoff was available cheapest with Prime shipping and two days later, MicroChorder.

Right now I just have my old keyer plugged in to [PRMINCF]=[8765432] with an 8th pin the Gnd adjacent to 2, which is nicely hardware minimal. I do still want to make a more presentable keyer sometime, likely with lighter switches, MX Browns feel good but are a little too fatiguing.

If anyone wants to build their own, here are the Keyboard_RAW library and MicroChorder Arduino sketch. They aren’t works of art (or mostly my code), and have some missing bits (no media key support), but are tested in that I typed most of this post on one.

This entry was posted in Computers, DIY, Electronics, General, Objects. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *