Site menu KMK: run Python in your keyboard

KMK: run Python in your keyboard

As a long-time aficionado of mechanical and custom keyboards, every aspect of a keyboard is a valid target for tinkering. Running a open-source firmware on upgradable keyboards is a great thing already.

But what about using a powerful microcontroller, running a firmware written in a language easier than C, no toolchain needed? This is possible today, with CircuitPython, Adafruit boards and KMK.

In case you prefer listening to reading, I put together a video about KMK.

Video about KMK and using the project in a custom mini keyboard

Most if not all keyboards use an 8-bit microcontroller. Upgradable mechanical keyboards tend to use an AVR, given the availability of tools for AVR-based Arduinos, and of course the availability of open-source firmware projects like TMK and QMK. Such projects are written in C. This technology package just works, but we are in 2019. There are better microcontrollers out there.

One problem with AVR is the small memory. Both flash and RAM are scarce. They are enough for a plain keyboard, but keep adding fancy features and you will feel the cramp. The C language is difficult, and even more so with the AVRisms and macros found throughout TMK/QMK.

In my opinion the biggest problem is the toolchain: installing compilers and flashing tools can be messy even for experienced developers who are not into embedded programming. Debugging may take some wire soldering and buying an FTDI serial adapter.

The KMK firmware is written in CircuitPython. This is a variant of MicroPython (which is a variant of Python language) maintained by Adafruit Industries, and runs on Arduino-style boards sold by Adafruit.

Unless you want to do advanced development, you don't need to install any toolchain to develop for CircuitPython. Plugg the board to a PC, and it shows up as a pendrive. Just copy a Python program into the pendrive, and it runs. The Python REPL command line, in which you can run immediate commands as well as debug running code, is available over a virtual serial device over USB.

KMK is in active development, the maturity lies somewhere between alpha and beta, and it still lacks some features. But it is perfectly usable as of today.

Hardware support is limited to a couple Adafruit boards which can run CircuitPython and have enough memory and I/O ports: Feather M4 Express and ItsyBitsy M4 Express. Trying to use any other board is asking for trouble, at least for now. (On the other hand, if you are looking for some open-source project to collaborate, that’s your ticket!)

As of now, there is no mechanical keyboard kit with a Python-compatible microcontroller. In the near future the KMK project is going to publish a PCB layout. Meanwhile, the easiest way to get you hands dirty is by soldering wires between an existing keyboard and a supported CircuitPython board.