Is CircuitPython suitable for mechanical keyboards? Yes, absolutely! KMK firmware for mechanical keyboards is writen in CircuitPython and we use it of ANAVI Macro Pad 10 and Knobs.
1991 was a remarkable year for computer science and the open source movement. On February 20th, Guido van Rossum released the first version of Python and then, several months later on August 25th, then 21-year old Linus Torvalds announced the first version of what would become Linux. Now, 31 years later, both projects are more popular than ever!
Python is a general-purpose programming language. It supports both object-oriented programming and structured programming which makes Python suitable for a broad range of tasks. MicroPython and CircuitPython are Python 3 variants optimized for constrained devices, primarily microcontrollers. MicroPython appeared in 2014. Three years later, in July 2017, MicroPython was forked into another open source project called CircuitPython. There are some differences, most notably that each of them supports a different set of hardware devices.
CircuitPython is very simple to use. The idea is for it to be accessible to students and beginners. Its development is supported by Adafruit Industries. CircuitPython runs on Raspberry Pi RP2040 microcontrollers and, as you know from our previous update, ANAVI Macro Pad 10, ANAVI Knobs 3 and ANAVI Knob 1 all rely on the XIAO module from Seeed Studio with RP2040.
A classical mechanical keyboard consists of keys (mechanical switches with keycaps) wired to a microcontoller. There are a huge variety of models, variants, and manufacturers of mechanical switches. For example, the ANAVI Macro Pad 10 comes with Gateron red mechanical switches, but the hot-swap sockets allow you to actually use any other kind of Cherry MX compatible switch. Firmware on the microcontroller maps the keys to specific characters.
In general, a microcontoller has a limited number of GPIO (general-purpose input/output) pins, so the keys are most commonly organized in a matrix. For example, ANAVI Macro Pad 10 is designed with a three-by-three matrix which only requires six GPIO pins instead of nine. The role of the firmware is to detect when a key is pressed and then send a specific character or sequence of characters (i.e., a macro) to the computer.
Ease of use combined with the power of the RP2040 makes CircuitPython a very good programming framework for implementing mechanical keyboard firmware. Of course CircuitPython is not as fast as C. However this is not a problem for the RP2040 because it is a dual-core Arm Cortex-M0+ processor with a clock running up to 133 MHz. Furthermore RP2040 has 264kB on-chip SRAM – more than enough for keyboard firmware. Thanks to the powerful microcontoller, it is easy to get started and customize keyboard behavior directly by altering the CircuitPython source code. There is no need to install complex toolchains or to cross-compile the source code. With KMK, it is easy to edit the source code in CircuitPython on pretty much any operating system, no matter if you are a Microsoft Windows, MacOS or a GNU/Linux user.
Of course, since ANAVI Macro Pad 10, ANAVI Knobs 3 and ANAVI Knob 1 are entirely open source projects, you have the freedom to replace the default firmware with whatever you like, no matter if it is KMK, QMK or anything else!