MicroPython Environment and Development Tools
Summary
This chapter walks you through everything you need to start writing MicroPython programs on a real microcontroller: downloading and installing the Thonny IDE, flashing the MicroPython firmware onto your Pico, and using the interactive REPL to run code instantly. You will learn how to transfer files between your computer and the Pico using Thonny's file manager, mpremote, and rshell, and how boot.py and main.py control what runs at startup. The chapter also introduces the MicroPython standard library modules — uos, utime, and sys — that your programs will use throughout the course.
Concepts Covered
This chapter covers the following 20 concepts from the learning graph:
- MicroPython
- MicroPython REPL
- MicroPython Firmware
- Flashing Firmware
- Thonny IDE
- VS Code IDE
- Thonny File Manager
- mpremote Tool
- rshell Tool
- File Transfer to Pico
- MicroPython Interpreter
- Interactive Mode
- Script Mode
- Boot.py File
- Main.py File
- MicroPython Modules
- MicroPython Standard Library
- uos Module
- utime Module
- sys Module
Prerequisites
This chapter builds on concepts from:
- Chapter 1: Python Basics — Programs, Variables, Data Types, and Operators
- Chapter 2: Collections, Control Flow, Functions, and Error Handling
Welcome to Chapter 3
It is time to leave the code editor and talk to a real microcontroller! In this chapter you will set up your development tools, put MicroPython on your Pico, and run your first program on real hardware. This is one of the most exciting steps in the whole course. Let's build something amazing!
What Is MicroPython?
MicroPython is a small, efficient version of Python 3 designed to run on microcontrollers. A regular computer has gigabytes of RAM and a fast operating system. A microcontroller like the Raspberry Pi Pico has only 264 KB of RAM and no operating system at all. MicroPython fits Python into that tiny space by leaving out features that microcontrollers do not need (like file sorting and web frameworks) while keeping everything that matters for hardware control.
MicroPython includes a MicroPython interpreter — the program that reads your Python source code and runs it directly on the microcontroller. You interact with it in two ways: interactive mode (one command at a time) and script mode (a complete program stored as a file).
What Is an IDE?
An IDE (Integrated Development Environment) is a software application that combines everything you need to write, run, and debug code in one place. Instead of juggling a separate text editor, a compiler, and a terminal window, an IDE wraps them together in a single graphical interface so you can focus on writing code rather than managing tools.
For MicroPython, a good IDE connects to your microcontroller over USB, lets you write and save programs, opens a REPL window for quick experiments, and helps you copy files to the board. Four tools are widely used for MicroPython development:
- Thonny — the best choice for beginners; one-click setup and a built-in MicroPython REPL, no configuration needed.
- VS Code + MicroPico — a professional-grade editor with Git integration; best for growing projects.
- Mu Editor — a clean, uncluttered editor with a built-in serial plotter for visualizing sensor data.
- Wokwi Simulator — runs entirely in a browser; lets you simulate circuits and MicroPython code without any physical hardware.
The infographic below compares all four side by side across cost, skill level, operating system support, MicroPython features, debugger capability, and best use cases.
Setting Up Thonny IDE
Thonny is the recommended editor for this course. It was designed specifically for learning Python, and it has built-in support for MicroPython and the Pico. Download it free from thonny.org and install it on your computer.
To configure Thonny for MicroPython:
- Open Thonny.
- Go to Tools → Options → Interpreter.
- Select MicroPython (Raspberry Pi Pico) from the dropdown.
- Click OK.
VS Code with the MicroPython extension is an alternative for students who already know VS Code. It offers more advanced features but has a steeper setup. For beginners, stick with Thonny.
Flashing the MicroPython Firmware
Before your Pico can run MicroPython, you must install the MicroPython firmware — a single .uf2 file that replaces the factory software. Flashing means copying this file onto the Pico.
Follow these steps exactly:
- Hold down the BOOTSEL button on the Pico.
- While holding BOOTSEL, plug the USB cable into your computer.
- Release the BOOTSEL button. The Pico appears as a USB drive called RPI-RP2.
- Download the latest MicroPython firmware from micropython.org/download/RPI_PICO.
- Drag the
.uf2file onto the RPI-RP2 drive. - The Pico restarts automatically. The USB drive disappears — that means it worked!
Monty's Tip
If the RPI-RP2 drive does not appear, try a different USB cable. Some cables are charge-only and carry no data. A data cable is required for flashing firmware.
The MicroPython REPL — Interactive Mode
After flashing, connect the Pico to Thonny. At the bottom of the Thonny window you will see the MicroPython REPL (Read-Evaluate-Print Loop). The REPL shows the >>> prompt, which means it is waiting for your next command.
The REPL works in interactive mode: you type one line of Python, press Enter, and the Pico runs it immediately. This is perfect for quick experiments:
1 2 3 4 5 6 7 | |
Interactive mode is great for testing ideas and exploring what the hardware can do — no need to save a file first.
Diagram: REPL Workflow Diagram
REPL Workflow Interactive Diagram
Type: diagram
sim-id: repl-workflow
Library: p5.js
Status: Specified
Bloom Level: Understand (L2) Bloom Verb: explain Learning Objective: Students can describe the Read-Evaluate-Print Loop cycle and distinguish interactive mode from script mode.
Canvas layout: - Center: four labeled boxes arranged in a cycle: "Read" → "Evaluate" → "Print" → "Loop back to Read" - Below the cycle: two side-by-side columns: "Interactive Mode" vs "Script Mode" - Each box is clickable
Visual elements: - Four rounded rectangles in a circular arrangement with arrows between them - "Read": "You type a Python line and press Enter" - "Evaluate": "The MicroPython interpreter runs the code" - "Print": "The result appears on the >>> prompt" - "Loop": "The prompt reappears, waiting for the next command" - Color: active step highlighted in teal; others gray
Interactive controls:
- Clicking any box reveals a pop-up with a concrete example (e.g., clicking "Read" shows >>> 2 + 2)
- A "Next Step" button cycles through the four stages with highlighting
- Two toggle buttons: "Interactive Mode" and "Script Mode" — each shows a brief description in a side panel
Instructional Rationale: The four-step cycle with click-to-reveal makes the REPL loop concrete. Toggling between modes clarifies the difference between one-shot commands and stored programs.
Implementation: p5.js with four clickable rounded rects; state machine cycles through steps; createButton() for Next Step and mode toggles.
Script Mode — Writing Complete Programs
In script mode, you write a complete program in Thonny's editor, save it, and run it all at once. Use File → New to open an editor tab, write your program, then click the green Run button (or press F5).
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Script mode is how you write every real project in this course.
Transferring Files to the Pico
When you run a script in Thonny, it runs once and stops. To make a program run every time the Pico powers on, you need to transfer it to the Pico's internal flash memory. There are three ways to do this.
Thonny File Manager
In Thonny, go to View → Files to open the file manager. It shows two panels: your computer on the left, and the Pico on the right. Drag files from left to right to copy them onto the Pico.
mpremote
mpremote is a command-line tool. You install it with pip install mpremote, then use it from a terminal:
1 2 3 | |
rshell
rshell is another command-line tool with a shell-like interface:
1 2 | |
| Tool | How to use | Best for |
|---|---|---|
| Thonny File Manager | Drag-and-drop in GUI | Beginners |
| mpremote | Short commands in terminal | Everyday file management |
| rshell | Shell-like commands | Scripted deployments |
Managing Files with mpremote
mpremote is MicroPython's official command-line tool for working with your Pico from a terminal. It lets you list files, copy programs, create folders, and run quick tests — all without opening Thonny. As your projects grow, mpremote becomes one of your fastest and most useful tools.
Install mpremote once on your computer by opening a terminal and typing:
1 | |
Finding Your Pico's Port
When you run an mpremote command, it automatically scans your USB ports and connects to the first MicroPython device it finds. You do not need to know the port name — mpremote finds the Pico by its USB ID.
If you want to see which port your Pico is using, run:
1 | |
You will see output like this:
1 2 3 | |
If you have more than one Pico plugged in at the same time, auto-detection picks the first one it finds. To target a specific board, add connect and the port name before your command:
1 2 3 | |
For most students with a single Pico, auto-detection works every time and you never need to type the port name.
The Colon Rule — Pico vs. Your Computer
mpremote uses one simple rule to tell the two sides apart: any path that starts with a colon (:) points to the Pico. A path without a colon is on your computer.
| Path | Where it is |
|---|---|
main.py |
your computer |
:main.py |
the Pico |
:lib/ssd1306.py |
the Pico, inside the /lib folder |
Monty's Tip
The colon is easy to forget! If mpremote says "file not found" when you know the file is there, check your colons. No colon = your computer; colon = the Pico.
Listing Files on the Pico
1 2 | |
Copying Files to the Pico
1 2 | |
You can also copy the other way — from the Pico back to your computer. Just reverse the colon:
1 2 | |
Running a Script Without Saving It
Use mpremote run to send a script to the Pico and run it right away, without saving it to flash memory. This is great for quick tests:
1 | |
Loading Drivers into the /lib Folder
MicroPython searches the /lib folder for driver libraries. When your code says from ssd1306 import SSD1306_I2C, MicroPython looks for /lib/ssd1306.py on the Pico. You must create the /lib folder before you can copy drivers into it:
1 2 | |
After copying, your program can import the driver by name:
1 | |
Loading All Drivers for a Hardware Kit
When you set up a new kit, you often need to load several drivers at once. Run each command in order:
1 2 3 4 5 | |
You only need to do this once per Pico. The /lib folder and its drivers stay in flash memory even after you unplug the power.
Installing Packages with mip
MicroPython 1.19 added mip, the built-in package installer. mpremote downloads the package from the internet through your computer and copies it straight to the Pico — so the Pico itself does not need a Wi-Fi connection.
The two packages you will use most in this course are umqtt.simple for sending data over the internet and ntptime for setting the clock on a Pico W:
1 2 | |
Other useful packages from the MicroPython library:
1 2 | |
Most hardware drivers in this course — such as ssd1306.py for OLED displays and hcsr04.py for distance sensors — are plain .py files that you copy with mpremote cp, not packages you install with mip. Use mip when a project needs a networking or protocol library that does not come built in to MicroPython.
To see all available packages, browse the MicroPython package library at github.com/micropython/micropython-lib.
The table below summarizes the most common mpremote commands:
| Command | What it does |
|---|---|
mpremote ls |
List files in the Pico root folder |
mpremote ls :lib |
List files inside /lib |
mpremote cp file.py :file.py |
Copy a file from your computer to the Pico |
mpremote cp :file.py backup.py |
Copy a file from the Pico to your computer |
mpremote run test.py |
Run a script on the Pico without saving it |
mpremote mkdir :lib |
Create the /lib folder on the Pico |
mpremote mip install name |
Download and install a package |
boot.py and main.py — Startup Files
When the Pico powers on, MicroPython automatically looks for two special files:
- boot.py — runs first, every time. Use it for hardware setup, Wi-Fi connection, and configuration that must happen before your program starts.
- main.py — runs second, every time. This is where your main program lives.
1 2 3 4 5 6 7 8 9 | |
Key Idea: main.py Runs Forever
Unlike programs on your laptop that finish and exit, a Pico program usually runs in an infinite while True: loop. The Pico has one job — keep blinking, keep reading sensors, keep controlling motors — and it does it until you unplug it or reset it.
The MicroPython Standard Library
MicroPython includes a set of built-in modules — the MicroPython standard library. These modules give you ready-made functions for hardware control, time, the file system, and system information. You will use three of them in almost every project.
utime — Timing Functions
The utime module provides time and delay functions:
1 2 3 4 5 6 | |
uos — Operating System / File System
The uos module lets you work with the Pico's file system:
1 2 3 4 5 6 | |
sys — System Information
The sys module gives you information about the MicroPython environment:
1 2 3 4 5 6 | |
The following table summarizes the three standard library modules:
| Module | Purpose | Key functions |
|---|---|---|
utime |
Time and delays | sleep(), sleep_ms(), ticks_ms() |
uos |
File system | listdir(), mkdir(), remove() |
sys |
System info | version, platform, exit() |
You Can Do This!
Setting up hardware tools for the first time is often the trickiest part of any course. If your Pico does not show up, if Thonny gives a connection error, or if the firmware flash did not work — that is normal. Take it one step at a time, and check the troubleshooting tips in the debugging chapter. Every maker hits these bumps at the start.
Key Takeaways
- MicroPython is Python 3 designed to run on microcontrollers with very little RAM.
- Flash the firmware once by holding BOOTSEL while connecting USB.
- The REPL runs one command at a time (interactive mode).
- Script mode runs a complete saved program.
- Copy programs to the Pico using Thonny's file manager, mpremote, or rshell.
- boot.py runs first; main.py runs second — both run automatically on power-up.
utime,uos, andsysare the three standard library modules you will use most.
Your First Real Hardware Step!
You have set up your tools, flashed your Pico, and run code on real hardware. That is a huge milestone — welcome to the world of physical computing! In Chapter 4 you will learn all about the microcontroller hardware itself: pins, power, memory, and the amazing features of the RP2040 chip inside your Pico. You've got this, maker!