What is MicroPython?
MicroPython is a lightweight, efficient implementation of Python 3 designed to run on microcontrollers and embedded devices with limited memory and processing power. It brings Python's readability and ease-of-use to hardware programming, making it accessible to beginners while remaining powerful enough for advanced projects.
Created by Damien George, MicroPython runs directly on microcontrollers without needing a full operating system. This makes it ideal for low-power, real-time embedded systems like sensors, robots, and IoT devices.
Key features
MicroPython includes many Python 3 features while optimizing for constrained hardware:
- Python 3 compatibility: Core Python data types (strings, integers, floats, booleans), data structures (lists, dictionaries, sets), classes, exceptions, generators, and list comprehensions
- Interactive REPL: Run Python code interactively on the device—type commands and see immediate results, perfect for testing and learning
- No compilation needed: MicroPython runs entirely on the microcontroller—no need to compile code on a computer first
- Hardware access: Control GPIO pins, I2C, SPI, UART, PWM, ADC, and other hardware features directly from Python
- Small footprint: Optimized to run on devices with as little as 256KB RAM and 1MB flash storage
- Extensive libraries: Built-in modules for hardware control, file I/O, networking, and more
MicroPython vs Python
While MicroPython aims to be compatible with Python 3, some differences exist due to hardware constraints:
What's the same
- Core language syntax and features
- Basic data types and structures
- Functions, classes, and modules
- Exception handling and control flow
What's different
- Standard library: MicroPython includes a subset of Python's standard library, optimized for embedded systems
- Performance: MicroPython is slower than CPython (desktop Python) but fast enough for real-time control
- Memory management: More manual memory control to fit in limited RAM
- Hardware modules: MicroPython adds modules like
machine,pyb, andnetworkfor hardware access
Learning MicroPython means learning Python—the skills transfer directly. Code you write in MicroPython often runs on desktop Python with minimal changes.
Use cases
MicroPython excels in embedded systems and hardware projects:
- Rapid prototyping: Test hardware ideas quickly without compilation delays
- Education: Teach programming and electronics simultaneously with interactive feedback
- IoT devices: Build sensors, data loggers, and connected devices
- Robotics: Control motors, servos, and sensors with high-level Python code
- Wearables: Create low-power wearable tech with real-time responses
- Home automation: Build custom smart home controllers
Supported platforms
MicroPython runs on many microcontroller boards:
Raspberry Pi Pico
Raspberry Pi Pico (based on the RP2040 chip) is officially supported by MicroPython. It's one of the most popular MicroPython platforms due to its low cost, extensive GPIO, and beginner-friendly design.
micro:bit
The BBC micro:bit runs MicroPython by default, making it a popular choice for education. It includes built-in sensors, LEDs, and buttons.
ESP32 and ESP8266
These Wi-Fi-enabled microcontrollers support MicroPython and are widely used for IoT projects.
PyBoard
The original MicroPython board, designed by Damien George, optimized specifically for MicroPython.
Others
MicroPython also runs on STM32, nRF52, and various other microcontroller families. Check the MicroPython downloads page for supported boards.
Get started with MicroPython
- Get compatible hardware: Raspberry Pi Pico, micro:bit, or ESP32/ESP8266
- Flash MicroPython firmware: Download the firmware for your board and flash it (usually drag-and-drop or via a tool like Thonny)
- Install an editor: Thonny IDE (recommended for beginners) or use a terminal for REPL access
- Connect to the board: Plug in via USB and open a serial connection
- Try the REPL: Type
print("Hello, MicroPython!")and see immediate results - Write a script: Create a
main.pyfile to run code automatically on boot
For Raspberry Pi Pico, Vilros offers kits with everything you need to get started, including the book "Get Started with MicroPython on Raspberry Pi Pico."
Ready to try MicroPython?
Shop Raspberry Pi Pico kits at Vilros or explore the MicroPython official site.