Learn MICROPYTHON with Real Code Examples

Updated Nov 21, 2025

Explain

MicroPython allows Python code execution on resource-constrained devices like ESP32, ESP8266, STM32, and RP2040.

It provides direct access to hardware peripherals, including GPIO pins, PWM, ADC/DAC, I2C, SPI, and UART.

Ideal for embedded prototyping, IoT projects, and educational applications.

Core Features

Runs on resource-constrained microcontrollers

Direct access to hardware and peripherals

Filesystem access via onboard storage or USB

Event-driven and procedural programming support

Interoperable with MicroPython libraries and extensions

Basic Concepts Overview

Modules for hardware access (machine, network, uos, etc.)

REPL for interactive experimentation

boot.py and main.py for startup scripts

Event-driven and polling mechanisms for sensors

Support for networking protocols (HTTP, MQTT, WebSockets)

Project Structure

main.py - primary script executed at boot

boot.py - optional initialization script

lib/ - user or third-party MicroPython libraries

data/ - storage for logs or configuration

assets/ - optional resources such as images or fonts

Building Workflow

Flash MicroPython firmware to the board

Write scripts using Python syntax

Test peripherals interactively with REPL

Use libraries for sensors, actuators, and network modules

Deploy main.py to execute automatically on boot

Difficulty Use Cases

Beginner: simple LED or buzzer control

Intermediate: sensor data collection with storage

Advanced: controlling multiple peripherals with event handling

Expert: networked IoT devices with automation

Enterprise: small-scale embedded prototypes or custom devices

Comparisons

More general-purpose than CircuitPython, supports more boards

Requires slightly more setup and programming knowledge

Smaller abstraction for beginners compared to CircuitPython

Higher flexibility for advanced embedded applications

Optimized for performance and memory on constrained devices

Versioning Timeline

2013 – MicroPython created by Damien George

2014–2016 – Expansion to STM32 and ESP8266 boards

2017–2019 – Stable releases and library expansion

2020–2023 – Support for more microcontrollers (RP2040, ESP32, etc.)

2025 – Mature ecosystem with active community and libraries

Glossary

main.py - primary script executed on boot

boot.py - optional initialization script

REPL - interactive Python shell

machine module - hardware access API

Pin - microcontroller I/O interface