8qn lab

MicroPython

A Python 3 implementation written in C, built to run on microcontrollers.

creator
Damien P. George
first release
3 May 2014
written in
C
license
MIT

overview

MicroPython is a software implementation of a programming language largely compatible with Python 3, written in C and optimized to run on a microcontroller. Ordinary Python needs an operating system and megabytes of memory to spare. A microcontroller has neither, so MicroPython is a cut-down Python built for that gap: it keeps the language and the familiar syntax, and drops what will not fit.

what it is

It implements Python 3.4 in full and much of 3.5, though not every feature added from 3.5 onwards, and it ships a subset of the standard library. Those libraries are smaller than their Python counterparts, with less used features removed to save memory. Alongside them are MicroPython specific modules such as machine, for talking to the hardware directly.

how it works

The project is two parts: a compiler that turns Python into bytecode, and a runtime that executes that bytecode. Code can be compiled on the microcontroller itself, or ahead of time on a computer into .mpy files. Firmware can even be built without the compiler, leaving only the virtual machine to run precompiled programs.

The board comes up with an interactive prompt, the REPL, reached over a serial connection. Individual lines of code run as they are typed, which makes it quick to try one part of a program and look at the result. A hardware abstraction layer sits underneath, letting code move between boards in the same family, or from a fast development board to a slower production one.