What Is MicroPython?

MicroPython is a lean, efficient implementation of Python 3 designed to run on microcontrollers and embedded systems. It gives you the readability and ease of Python while running directly on hardware with as little as 256KB of flash and 16KB of RAM. If you already know Python, you can start building hardware projects without learning C or C++.

Supported boards include the Raspberry Pi Pico, ESP32, ESP8266, STM32, and many others. In this guide, we'll use the Raspberry Pi Pico W as our example board — it's affordable, widely available, and has built-in Wi-Fi.

Why Choose MicroPython Over Arduino's C++?

  • Faster iteration: No compile step. Write code, save, and it runs.
  • Interactive REPL: Type commands directly to the board in real time.
  • Familiar syntax: If you know Python, the learning curve is minimal.
  • Readable code: Projects are easier to share, maintain, and modify.

The trade-off is that MicroPython is slower than compiled C for timing-critical applications, and some advanced peripherals may lack MicroPython library support. For most prototyping tasks, though, it's more than capable.

Setting Up Your Environment

Step 1: Flash MicroPython Firmware

  1. Download the latest MicroPython .uf2 firmware for your board from micropython.org/download.
  2. Hold the BOOTSEL button on your Pico while plugging it into USB. It mounts as a USB drive called RPI-RP2.
  3. Drag and drop the .uf2 file onto the drive. The board reboots automatically with MicroPython installed.

Step 2: Install Thonny IDE

Thonny is the easiest editor for MicroPython beginners. Download it from thonny.org. Once installed, go to Tools → Options → Interpreter, select MicroPython (Raspberry Pi Pico), and choose the correct COM/serial port. You should see a MicroPython REPL prompt appear at the bottom of the screen.

Your First MicroPython Script: Blink an LED

Every embedded journey starts with a blinking LED. Here's how to do it on the Pico (the onboard LED is on pin 25):

from machine import Pin
import time

led = Pin(25, Pin.OUT)

while True:
    led.value(1)   # LED on
    time.sleep(0.5)
    led.value(0)   # LED off
    time.sleep(0.5)

Save this as main.py on the board. Any file named main.py runs automatically on boot — this is how you deploy standalone projects.

Reading a Sensor: Analog Input Example

Let's read a potentiometer or light-dependent resistor (LDR) connected to an analog pin (GP26, which maps to ADC0 on the Pico):

from machine import ADC
import time

sensor = ADC(26)  # GP26 = ADC channel 0

while True:
    raw = sensor.read_u16()  # Returns 0–65535
    voltage = raw * 3.3 / 65535
    print(f"Raw: {raw} | Voltage: {voltage:.2f}V")
    time.sleep(0.5)

This pattern — read, convert, print — forms the basis of most sensor projects. From here you can log data, trigger actions, or send values over Wi-Fi.

Key MicroPython Modules to Know

ModulePurpose
machineGPIO, ADC, PWM, I2C, SPI, UART control
timeDelays and timing (sleep, ticks_ms)
networkWi-Fi connection management (ESP32/Pico W)
urequestsHTTP requests — similar to Python's requests library
ujsonJSON encode/decode for APIs and config files
uosFile system operations on the board's flash storage

Next Steps

Once you're comfortable with GPIO and sensors, try these projects to level up:

  • Connect an OLED display over I2C and display sensor readings
  • Post temperature data to a free service like Adafruit IO using Wi-Fi
  • Build a simple HTTP server on the Pico W to display live sensor data in a browser
  • Control a servo motor using PWM for a robotics mini-project

MicroPython dramatically lowers the barrier to hardware prototyping. Once you can write Python, you can talk to the physical world.