Learn MicroPython

Four steps: a board (or an emulator), firmware, a REPL, then a file that runs on boot.

1. Pick something that runs

If you have no hardware, open the Pico playground and type at the REPL. If you are buying, a Raspberry Pi Pico or Pico W is the usual start. ESP32 is the usual start when you need Wi-Fi on the same board.

2. Flash firmware

Official UF2 and .bin images are at micropython.org/download. Pico-family boards appear as a USB drive named RPI-RP2 (or RP2350) when you hold BOOTSEL; drop the UF2 on it. ESP boards use esptool. Device pages repeat the exact steps.

3. Open the REPL

The REPL is a serial port (USB CDC on Pico and many STM32 boards, UART on some ESP modules). 115200 baud is the default. Thonny, mpremote and any serial terminal work. WebREPL is a wireless extra on some ports.

>>> print('hello')
hello
>>> import machine
>>> machine.freq()
First lines at a MicroPython REPL

Tab completion and paste mode (Ctrl-E / Ctrl-D) are built in. Ctrl-C interrupts a running script; Ctrl-D soft-resets and re-runs boot.py then main.py.

4. Files that run themselves

boot.py runs first (connect Wi-Fi, set the clock). main.py is your program. Both live on the board’s flash filesystem. mpremote cp blink.py :main.py is the usual way to install a script.

from machine import Pin
from time import sleep

led = Pin('LED', Pin.OUT)  # Pico; use Pin(2, Pin.OUT) on many ESP32 boards
while True:
    led.toggle()
    sleep(0.5)
Blink — Pico onboard LED

What to read next