Modern microcontrollers like the RP2040 and ESP32 are truly a marvels of engineering. For literal pocket change you can get a chip that’s got a multi-core processor running at hundreds of megahertz, plenty of RAM, and more often than not, some form of wireless connectivity. Their capabilities have been nothing short of revolutionary for the DIY crowd — on any given day, you can see projects on these pages which simply wouldn’t have been possible back when the 8-bit Arduino was all most folks had access to.
Thanks to the increased performance of these MCUs, hackers and makers now even have a choice as to which programming language they want to use. While C is still the language of choice for processor-intensive tasks, for many applications, Python is now a viable option on a wide range of hardware.
This provides a far less intimidating experience for newcomers, not just because the language is more forgiving, but because it does away with the traditional compile-flash-pray workflow. Of course, that doesn’t mean the more experienced MCU wranglers aren’t invited to the party; they might just have to broaden their horizons a bit.
To learn more about this interesting paradigm shift, we invited the fine folks at Adafruit to the Hack Chat so the community could get a chance to ask questions about CircuitPython, their in-house Python variant which today runs on more than 400 devices.
State of the Union
Limor “ladyada” Fried, Phil Torrone, and Scott Shawcroft covered so much ground during the chat that it ran twice as long as originally planned. As usual when Adafruit joins the Hack Chat, the event was simultaneously streamed to their YouTube channel, which brought in even more questions and comments. It was a bit like spending an hour drinking from a fire hose, but we’d say the end result was more than worth it.
The discussion started with some talk about current events, such as the ongoing development of USB Host mode, which would allow things like USB keyboards to be plugged directly into a board running CircuitPython. The team also talked a bit about the upcoming ESP32-based “My Little Hacker”, which was designed to be a drop-in replacement for the sound effect boards used in children’s toys.
We also heard a bit about Adafruit’s work to create a modern replacement for the legendary Bus Pirate. The chips used in the original design from Dangerous Prototypes are apparently no longer being produced, so Adafruit has come up with their own version of the electronics debugging tool using the RP2040. With the benefit of the chip’s native USB and Programmable I/O (PIO) hardware, plus the flexibility of CircuitPython, the new gadget promises to be a more than worthy successor. All that’s left is to figure out what to call it…
A Tale of Two Pythons
After bringing folks up to speed on what’s new in the world of CircuitPython, the team was hit with a fairly prickly question — why does CircuitPython exist in the first place? Those familiar with the situation may recall that CircuitPython is actually forked from MicroPython, and some have argued that Adafruit would have done better to support an existing open source project rather than pour development time and effort into what could be seen as a competitor.
In response, Scott and Limor gave a fascinating look at the origins of CircuitPython and the decision to spin it off into a separate project. The short version of the story is that the respective teams had some disagreements on how to handle certain things, chief among them being hardware APIs.
Specifically Adafruit wanted to be able to use the same libraries they had already ported over to standard Python, but that wouldn’t be possible under MicoPython, which had replaced some core low-level functions with versions that were modified in an effort to reduce how much space they would take up in flash. This also meant that MicroPython code wouldn’t necessarily work the same if it was run under the standard Python interpreter, which Limor found particularly troublesome. As such, it was decided to spin CircuitPython off into a clearly distinct project rather than just trying to get their changes approved.
That said, Adafruit continues to financially support MicroPython and does not internally consider them to be competing projects given their focus on the educational and hobby market. They also still consider CircuitPython to be downstream from MicroPython, that is, the intention is to eventually integrate new features and capabilities added to MicroPython into CircuitPython. Naturally, some in the chat asked if the projects might one day merge back into one. Scott said the idea comes up in discussions with the MicroPython team regularly, and while there are still some fundamental issues that would need to be resolved, the possibility is there.
Making CircuitPython Yours
With the existential debate over with, the conversation then moved on towards bringing new boards into the CircuitPython family. Namely, what an individual needs to do to make sure their own custom creation will work as expected in the environment.
The simple answer is that as long as you’re using one of the core chipsets they support like the ESP32, then getting the little details sorted out is relatively straightforward. There’s even an official guide from Adafruit on how to get your custom board added to the list of supported hardware.
Another topic brought up is the unique feature of CircuitPython that halts the currently running program and reloads it from the file once the USB mass storage file system sees that the source file has been saved. This was added specifically to make development as straightforward as possible, especially in educational settings where the computers in the classroom might not have any software installed more advanced than a simple text editor. To facilitate this feature, it was decided that halting the program should revert the system to a “clean slate” condition that doesn’t retain any state information from when the code was running.
The downside is that the same thing happens even if the program has been manually halted with Ctrl+C, which can frustrate more advanced users who are looking to debug their program by examining the state it was in when it was stopped. After some technical discussion, it was decided that it should be possible to optionally disable this feature for those who want more control over the execution of their code. Scott said he would be willing to lend a hand should somebody in the community wish to implement such a capability and submit it as a patch, and Limor commented that it could be officially merged into CircuitPython so long as it didn’t impact the default functionality.
Onwards and Upwards
As things started to wind down, several more topics were covered such as the adoption of TinyUSB within the industry, the challenges involved in supporting USB Mass Storage, and community-developed patches for new RF protocols such as Zigbee and ESP-NOW. There really is a wealth of technical information contained in the recorded live stream; if you’re interested in the nuts and bolts of CircuitPython, there’s certainly worse ways you could spend hour of your time than settling in and watching the whole thing.
Special thanks to Limor, Phi, and Scott for taking us on this whirlwind tour of where CircuitPython has been and where it’s going. It’s easy to get overwhelmed when there’s so much active development going on, so getting this type of insider perspective is immensely valuable for those who are looking to dip their toes into the fast moving waters of bare-metal Python.
The Hack Chat is a weekly online chat session hosted by leading experts from all corners of the hardware hacking universe. It’s a great way for hackers connect in a fun and informal way, but if you can’t make it live, these overview posts as well as the transcripts posted to Hackaday.io make sure you don’t miss out.