Friday, January 5, 2024

Macro Keypad


Macro Keypad

As far as electronics projects go, a macro keypad is probably among the easiest. I was inspired by a friend of mine who built one, and since I'm always looking for a project I can actually complete, this seemed like the perfect one. It still took me over a year from start to finish, but in the end I did complete it. 

I have a real problem with starting projects, and never finishing them. Most of the time its because I over complicate it, and when I fail to realize my vision, I get discouraged and give up. I'm training myself to be more satisfied with "good enough". Because even good enough is better than incomplete.
 
Like I tell my engineers, "better is the enemy of done". And this project stands as a personification of that aphorism. 


So, why did it take so long to build something so simple? I built the case, soldered the switches, leds, and all the connecting wire. When it was time to program the thing, I could not find a HID library for the rp2040 pico that was written in C++, my language of choice. They had python libraries if you were using CircuitPython. But in my hubris, thought "No, Circuit python is for people that don't know how to program microcontrollers".

Hubris might be a virtue. But sometimes you're just wrong. And all the normal-person virtues are still worth something in the end. I switched to CircuitPython and within 30 minutes finished my macro keypad. It now sits on my desk, a symbol of my humility. 


Enclosure

I modeled the enclosure in Fusion360. It's very basic, with a hole for a USB cable, and a slot for access to the pico pin headers. I'm not sure I'll ever actually hook any thing to the gpio pins, but I have a slot if ever I change my mind. 

The holes in the top are designed to fit standard Cherry MX keys.


Electronics

The keypad is powered by an RPI2040 pico. One of the newer things to come out of the raspberry pi group. It's a microcontroller with quite a few peripherals, for a relatively low price. They even have a wireless version I own two of that are currently pending other projects. 

The keys themselves are soldered into these breakout boards from SparkFun: Link. I can't understate how cool these boards are. They really put a lot of time and attention into them.

The switches are soldered right onto it, it supports an LED and a diode, AND they can be soldered into a matrix for multiple keys. No only that, its fairly easy to offset the rows/columns of this matrix just like you would on a standard keyboard.  Each one costs around $2, which can definitely eat into the budget.

Firmware

As I mentioned in the intro, I resisted using CircuitPython for this. But when I could not find an alternative HID library, I finally broke down and installed it. I was very surprised at how cool it is.

It installs as firmware on the pico, and presents itself as removable media (Just like the bootloader does). But instead of expecting a compiled binary, it takes python files. It'll automatically restart the pico when a file save is detected, AND if you open up a serial connection to it, you'll get the python output/errors. It also comes with a substantial number of prebuilt libraries for various sensors, and other utilities.

It basically takes away all of the normal challenges faced with embedded development, and provides a really nice, polished, familiar development environment. While I feel a little guilty using something so slick, it's just too cool to repudiate.

The code for this was really simple: Github Gist

Next Steps

Right now  only three of the 6 buttons are programmed with a function. Volume Up/Down and Play/Pause. I'm struggling to come up with useful commands that I actually want to use.

My friend suggested a couple of cool ideas.... If you pair this keypad with some installed service (That is listening for key combinations) It actually opens a whole world of possibilities. Auto formatting JSON/HTML/XML/etc in the clipboard, running scripts, doing a git pull, opening a terminal with an established ssh connection. 

If you're reading this, and you happen to have some ideas for me, please send them along. The other three keys are longing for purpose in their current vestigial state.

No comments:

Post a Comment