In a recent discussion with Scott Shawcroft, an engineer at Adafruit, I got really excited. He was explaining their transition into using CircuitPython on their products, as well the benefits such a transition would provide. One major benefit is that you simply plug in the device and it shows up as USB storage, then you drop your code onto it. There is no need for an IDE. This isn’t the first time I’ve seen this feature, but the fact that Adafruit’s selection of cutting edge prototyping tools are going to have this got me extremely excited.

What is CircuitPython?

CircuitPython is a microcontroller firmware based on MicroPython that makes it easier than ever to program hardware. Unlike Arduino, a user’s code is not stored in the firmware itself, but rather on a tiny filesystem in the chip or on the board. As a result, programming with CircuitPython is as simple as plugging the board into a computer and editing a file on the drive that appears. No additional software is needed to get started.

Arduino revolutionized embedded by removing the need for expensive flashing tools when changing code. CircuitPython goes one step further by removing the need for specific drivers and software.

If you had to summarize it in the simplest way possible, how would you describe CircuitPython?

I think the simplest version doesn’t involve recognizing CircuitPython or Python as separate at all. It simply unifies software and hardware. Plug a device in, open the drive, and edit the code on it to hack. Saving the file automatically causes it to reload. Eject it like a thumb drive and take it with you. The code is part of the device.

Why have you chosen to implement CircuitPython in Adafruit’s products?

For me, its simply that its easier than anything else out there to use. CircuitPython has a very low barrier for entry because it works without special drivers (except for serial on older Windows). It doesn’t require any one program to program it as any plain text editor will work. Any serial program can connect to it. No internet connection is required to program it either.

That low barrier to entry makes it perfect for Adafruit because we thrive on teaching beginners to create and experiment with hardware. CircuitPython’s ability to unify code with hardware makes it more hackable than ever. Its no longer an issue of emailing someone code separately and then getting them set up with a specific piece of software. It just works.

Will the products still work with the Arduino IDE? 

Yes! New products based on the SAMD21 Cortex-M0+ mcu that support CircuitPython are also supported by Arduino IDE and Microsoft MakeCode. We think teaching beginners initially with MakeCode and then advancing to CircuitPython and Arduino IDE is a great way to help young coders grow with their project complexity.

Why wasn’t this method done sooner? Or if it was, who should we thank for laying the foundations?

Running Python on embedded has been tried before with projects like Python-on-a-Chip and Owl. However, those projects didn’t find a broad audience. MicroPython finally did however when they launched a Kickstarter. MicroPython developers, including Damien George and Paul Sokolovsky, deserve credit for laying the foundation for CircuitPython. They did the hard work of reimplementing Python 3.4 on a microcontroller and editing the code over USB mass storage. We’ve simply built on their work to make it work on our hardware and polish the experience.

What kind of difficulties are involved in porting your products to CircuitPython in the first place? Is this complicated? Easy? No big deal?

Porting products to CircuitPython largely means moving them to 32 bit microcontrollers. CircuitPython doesn’t support 8-bit microcontrollers, so moving away from the at328p and 32u4 to the SAMD21 makes this possible.

Conversely, MicroPython didn’t have existing support for the SAMD21 (which is the chip used on all of our M0 boards). Adding SAMD21 support to MicroPython lead to our creation of CircuitPython. MicroPython had an existing notion of “ports” which roughly lines up with microcontroller families such as the STM32 family and SAMD families. Each family features a similar Cortex M core, but the peripherals which implement protocols such as USB, I2C, and SPI vary widely. So, the challenge of adding support for a new microcontroller family is in the peripheral support.

We’ve done a lot of work to make this easier in the future by establishing a clear, function oriented hardware API. This new API makes it easy to add hardware support piecemeal to a new port while helping ensure existing drivers will still work. In the future, as we expand to new microcontrollers, we plan to make adding ports even easier.

 Were hardware changes necessary to make CircuitPython work on your products?

Adafruit Feather M0 express

Having a 32 bit microcontroller is a requirement, but prior to CircuitPython we already had a diverse set of SAMD21 based Feathers. Initial development of CircuitPython was done on the Feather M0 Basic and the Arduino Zero. The CircuitPlayground, Metro, Gemma, and Trinket have been updated to the SAMD21, which enables CircuitPython on those platforms too.

For a better CircuitPython experience, we have introduced the Express line of boards. These boards feature external SPI Flash chips which are used to store Python code externally, instead of on the microcontroller. This means that more code can be stored (2MB instead of 64KB) and the firmware itself can expose more functionality. These were also the first boards to feature a status RGB LED. The newer non-Express Gemma M0 and Trinket M0 also have the RGB LED but do not have the extra flash.

Are there any disadvantages to CircuitPython that people should keep in mind as they develop?

The biggest trade-off of CircuitPython (and Python in general) is the decision to prioritize development speed over memory footprint and execution speed. The impact is that, depending on the project, one may hit a memory limit or speed limit that they wouldn’t hit with a compiled solution like Arduino. For example, a NeoPixel strip animation may not refresh the pixels as fast on CircuitPython as Arduino. Or a project that depends on many libraries may not be able to have as much functionality compared to code that can be optimized by a compiler.

That’s not reason enough to avoid CircuitPython though. The development speed is so much faster than a compiler based solution like Arduino that its best to try a project all in CircuitPython and optimize later as needed. Typically it will run fast enough because people underestimate how fast computers are.

Optimization after the code is written can be done in three primary ways:

1) in the Python code itself
2) by adding additional C functionality into the CircuitPython firmware as needed to use from Python
3) buying faster hardware (Moore’s law is still influencing microcontroller CPU speeds. The SAMD21 is 48mhz but similarly sized microcontrollers run at 200+ mhz.)

So, while there are trade-offs, CircuitPython is usually the right place to start.

Where can someone begin learning CircuitPython? I assume learn.adafruit.com, but is there anywhere else?

Currently, the best place to start is the product specific guides for Feather M0 Express and Gemma M0. There are a variety of projects on the Learn system that leverage CircuitPython already (arcade button box, MPR121 touch controller, and LIS3DH guide are three). Tony is also going to update his older MicroPython guides to CircuitPython, but thats in the works. This guide, for example, will be updated. Our API docs are also a great place for lots of tiny examples. Lastly, general Python tutorials are very useful for getting started with all of the non-hardware sides of CircuitPython.

How do you feel this move will impact your community?

I think the move towards CircuitPython will expand the existing Adafruit community. It will bring more beginners on board because of its lower barrier to entry. It’s a perfect match with the built-in versatility of a board like the CircuitPlayground Express. This ease of use will also enable more people to contribute back to our community through projects and libraries.

Existing members of our community will continue to see us create innovative products and projects. CircuitPython is just one step in improving the experience of open source software and hardware.

Its also the first core platform Adafruit has sponsored (versus Arduino and Raspberry Pi which have separate core development teams). This gives us an opportunity to set the tone for a new core development community, which is very exciting. All of our new projects have the Contributor Covenant as the Code of Conduct, which is important in helping preserve the friendly, welcoming and supportive Adafruit community as we expand into more open source development. The Rust language community has been a huge inspiration for how an open source project can be run well. Emily Dunham has a number of great talks about them as well.

Hopefully, this effort will lead to a more diverse set of contributors to CircuitPython, CircuitPython libraries, and Learn guides.