Skip to content

Micropython

MicroPython is a subset of Python designed to run on microcontrollers, making Python’s ease of use available for embedded systems.

Here are some background information:

  1. History and Development: Created in 2013 by Damien George via Kickstarter, along with the pyboard, MicroPython has evolved significantly over the years. Sales of updated versions of the pyboard, available in the MicroPython store, support ongoing development.

  2. Python for Microcontrollers: By using MicroPython, developers can leverage their Python skills to write software for microcontrollers, traditionally programmed in C. While not as fast as compiled C programs, MicroPython offers ease of development. It implements Python 3.4, with select features from later versions, but has notable differences and limitations compared to CPython.

  3. Optimizations and Performance: MicroPython includes optimizations for low-resource devices, such as avoiding heap allocation for small integers and using string interning. Developers can pre-compile Python modules to .mpy files to reduce overhead on microcontrollers. Frozen bytecode is another optimization, reducing RAM usage.

  4. Supported Hardware and Platforms: It supports over 150 microcontroller boards, including ESP32, ESP8266, STM32 ARM Cortex-M, Microchip SAMD, Nordic Semiconductor nRF5 chips, and Raspberry Pi Foundation RP2040-based boards. MicroPython has also been ported to the Zephyr real-time operating system, expanding its hardware compatibility.

  5. Development Environment: MicroPython provides a read-eval-print loop (REPL) shell accessible via a serial connection. Tools like Thonny, Mu Editor, and Arduino Lab for MicroPython support firmware installation and code upload. Two key files, boot.py and main.py, are used for initialization and main program execution, respectively.

  6. Libraries: It includes reimplementations of Python standard library modules, MicroPython-specific functionality, and a repository of external libraries (micropython-lib) for additional features. The new package manager, mip, allows for easy library installation on network-capable boards.

  7. WebAssembly and Web Development: MicroPython can run in a web browser using WebAssembly, offering a smaller and faster alternative for web applications compared to Pyodide, as demonstrated in PyScript’s technical preview by Anaconda.

⇒ MicroPython is an accessible choice for programming microcontrollers, competing with platforms like Arduino (which requires C++ knowledge) and complementing other Python-based platforms like CircuitPython and Snek. Its suitability extends beyond microcontrollers to other constrained environments, including web applications via WebAssembly.

Page last modified: 2023-11-21 09:25:37