Since Python is a popular, easy to learn, open source programming language, it has been adapted to fit all sorts of niches. In this article, we’ll discuss how CircuitPython (a fork of MicroPython) is gaining traction for microcontroller programming among makers, students, hobbyists and tinkerers.
In a previous article on Python’s role in the IoT, we discussed MicroPython: a port of the Python 3 interpreter which runs on microcontrollers and thus allows embedded developers to use the peripherals and processing capability of those chips from Python.
Even though MicroPython supports the Python language (with a few deviations from standard CPython 3), only a small subset of the standard library is supported. The main reason for this is the fact that the amount of RAM, non-volatile storage (e.g. flash memory) and processor clock speed on most microcontrollers is a few orders of magnitude less than any desktop, laptop or tablet made within the last five years.
Despite those constraints, MicroPython is still able to bring Python’s ease of development to the type of microcontroller-based boards which are popular among makers and hobbyists. It’s no wonder that a vendor popular in that space, Adafruit, would take MicroPython a step further and create their own version of MicroPython: CircuitPython.
CircuitPython vs. MicroPython
While MicroPython supports several different microcontroller chips, CircuitPython actively supports the SAMD21 MCU (which is the brains of many of their boards) and the ESP8266, another popular chip they use which has built-in WiFi. These chips are more powerful than the slower-clocked, 8-bit AVR MCUs from Atmel (now part of Microchip, the maker of PIC series of MCUs which are very popular with hobbyists) which form the heart of almost all the Arduino boards.
Both MicroPython and CircuitPython make the board appear as a USB storage device when the board is connected to a computer. The Python program is written in a simple text file which can then be drag and dropped onto the board. The CircuitPython code isn’t compiled before being uploaded, which eliminates errors at compile time (but of course not runtime errors). The Arduino platform, on the other hand, requires all programs (called “sketches”) to be compiled on the development computer before being uploaded to the board.
The Arduino language is basically C/C++ with a lot of helpful macros and libraries which abstract away much of the low-level memory management, pin configuration and board-specific differences. Using the Arduino language and IDE is like making brownies from a box mix you bought at a store. Programming MCU boards with CircuitPython, however is like buying a brownie directly from your local pastry chef.
Even as CircuitPython gains popularity though, Arduino will still be the go-to platform for code which requires very tight timings and the fastest possible execution speed available on the target hardware.
Python: Expanding Markets and Possibilities
According to its official documentation, CircuitPython aims to be “an education friendly open source derivative of MicroPython” which “supports use on educational development boards designed and sold by Adafruit”. The fact that Python is both free (as in “freedom”) software and open source (the source code for the interpreter and the modules is available for anyone to view) allows merchants like Adafruit to create these derivatives which benefit both their bottom line and those learning to combine programming and electronics through their dev boards and associated add-ons like motor drivers and displays.
CircuitPython is a great example of how foundational tech like Python can not only be a useful tool for solving immediate problems like powering cloud-based file sharing and collaboration, but also an easy to cross bridge into software and hardware engineering for tinkerers of all ages.
Copyright © Python People