Python MicroPython for Embedded Systems — Core Concepts
What MicroPython Actually Is
MicroPython is an independent reimplementation of Python 3 designed to run on microcontrollers — processors with as little as 256 KB of flash storage and 16 KB of RAM. Created by Damien George in 2013, it passes most of the Python 3.4 language specification while fitting into a footprint thousands of times smaller than CPython.
It is not a library you install with pip. It is a complete interpreter that you flash onto a board as firmware. Once flashed, the board boots into a Python environment where you can run scripts interactively or from stored files.
Supported Hardware
MicroPython runs on dozens of boards, but the most popular families include:
- ESP32 and ESP8266 — Inexpensive Wi-Fi-enabled boards from Espressif. An ESP32 board costs around three to five dollars and has built-in Wi-Fi and Bluetooth. This is the most popular MicroPython target.
- Raspberry Pi Pico (RP2040) — A microcontroller board (not to be confused with the full Raspberry Pi). Dual-core ARM processor, no built-in wireless on the base model, excellent documentation.
- STM32 boards — The Pyboard, MicroPython’s original reference hardware, uses an STM32 chip. These are common in industrial and hobbyist projects.
- nRF52 series — Nordic Semiconductor chips popular for Bluetooth Low Energy projects.
How Development Works
The typical workflow has four steps:
- Flash the firmware. Download the MicroPython binary for your specific board from micropython.org and flash it using a tool like
esptool.pyfor ESP boards or drag-and-drop for Pico. - Connect via REPL. Once flashed, you connect to the board over USB serial. You get a live Python prompt (the REPL) where you can type commands and see results instantly.
- Write scripts. Create a
main.pyfile on the board’s tiny filesystem. MicroPython runs this file automatically on boot. - Use hardware APIs. Import modules like
machineandnetworkto control GPIO pins, I2C, SPI, Wi-Fi, and other hardware interfaces.
Key Differences from CPython
MicroPython is Python, but with constraints:
- Limited standard library. Modules like
os,sys, andjsonexist in stripped-down forms. Heavy libraries likenumpyorrequestsare not available. - No pip. You install packages manually or use
mip, MicroPython’s lightweight package manager. - Memory matters. With 256 KB of RAM, a large dictionary or list can crash the interpreter. You think about memory in ways desktop Python developers never need to.
- Hardware-specific modules. The
machinemodule provides direct access to GPIO pins, PWM, ADC, I2C, SPI, and UART — none of which exist in standard Python.
Common Misconception
Many people confuse MicroPython with running regular Python on a Raspberry Pi. They are completely different. A Raspberry Pi (the full-sized one) runs Linux and uses standard CPython. MicroPython runs on bare-metal microcontrollers with no operating system. The Pi Pico is a microcontroller that runs MicroPython, but a Raspberry Pi 4 is a full Linux computer.
Practical Example: Blinking an LED
This is the embedded equivalent of “Hello, World”:
from machine import Pin
import time
led = Pin(2, Pin.OUT) # GPIO pin 2, output mode
while True:
led.on()
time.sleep(0.5)
led.off()
time.sleep(0.5)
Three lines of setup, a simple loop, and the LED blinks. Compare this to the equivalent in C for Arduino — the Python version is readable by anyone.
When to Use MicroPython
MicroPython shines for prototyping, education, and projects where development speed matters more than raw performance. If you need microsecond timing or every byte of RAM, C is still the right choice. But for sensor reading, data logging, home automation, and learning embedded systems, MicroPython removes enormous barriers to entry.
One thing to remember: MicroPython brings Python’s readability to microcontrollers, trading raw performance for dramatically faster development and a gentler learning curve.
See Also
- Python Behavior Trees Robotics How robots make decisions using a tree-shaped rulebook that keeps them organized, like a flowchart that tells a robot what to do in every situation.
- Python Bluetooth Ble How Python connects to fitness trackers, smart locks, and wireless sensors using the invisible radio signals all around you.
- Python Circuitpython Hardware Why CircuitPython makes wiring up LEDs, sensors, and motors as easy as plugging in a USB drive.
- Python Computer Vision Autonomous How self-driving cars use cameras and Python to see the road, spot pedestrians, read signs, and understand traffic — like giving a car human eyes and a brain.
- Python Home Assistant Automation How Python turns your home into a smart home that reacts to you automatically, like a helpful invisible butler.