Getting Started with MicroPython
1. Setting Up the Development Environment
To begin programming the Raspberry Pi Pico with MicroPython, you need to set up your development environment.
1.1 Install Required Software
Option 1: VS Code + MicroPython Plugin
- Install Visual Studio Code from code.visualstudio.com.
- Install the MicroPico and Raspberry Pi Pico extension for MicroPython. The extensions can be fund on the left sidebar. Open the extensions by clicking on it and in the search bar type pico. Installing MicroPico extension may automatically can install the Raspberry Pi Pico extension too.

- Connect your Pico and open a new terminal in VS Code.

Key Features of VS Code:
-
Support for Multiple Programming Languages
- VSCode supports the most popular programming languages (e.g., Python, C/C++, Java, JavaScript, etc.)
- Additional languages can be enabled via extensions
-
Intelligent Code Completion (IntelliSense)
-
Provides real-time suggestions while coding
- Speeds up development and reduces errors
-
Integrated Terminal
-
Built-in terminal eliminates the need to switch between the editor and command line
- Can be opened with the shortcut Ctrl + `
-
Version Control (Git Integration)
-
Built-in Git support allows tracking changes and facilitates teamwork
-
Extensibility (Extensions)
-
Thousands of extensions are available via the Extensions Marketplace
- Includes language support, formatting tools, and debugging utilities
Option 2: Thonny IDE (Recommended for Beginners)
Thonny is a simple and beginner-friendly IDE with built-in MicroPython support.
- Download and install Thonny from thonny.org.
- Open Thonny and go to Tools → Options.
- Select the Interpreter tab and choose MicroPython (Raspberry Pi Pico).
- Connect your Pico via USB and click Stop/Restart Backend to verify the connection.
Option 3: Command-Line Interface (CLI) (Recommended for this course)
This course uses mpremote — the official MicroPython remote tool:
- Install Python 3 (if not installed already).
- Create a virtual environment and install
mpremote: - Connect your Pico and verify:
- Open the REPL:
Remember to activate the environment (
source ~/pico-env/bin/activate) each time you open a new terminal.
See the mpremote cheatsheet for the full command reference.
2. Installing MicroPython on Raspberry Pi Pico
To use MicroPython, you need to flash the MicroPython firmware onto your Pico.
Steps:
- Download the latest MicroPython firmware for Pico 2 from the official website.
- Hold down the BOOTSEL button on the Pico while plugging it into your computer.
- The Pico will appear as a USB mass storage device.
- Copy the MicroPython .uf2 file to the Pico.
- The Pico will reboot automatically into MicroPython mode.
3. Running Your First MicroPython Script
3.1 Using Thonny
- Open Thonny and select MicroPython (Raspberry Pi Pico) as the interpreter.
- Type the following code in the editor:
- Click Run.
- You should see
Hello, Raspberry Pi Pico!in the output window.
3.2 Using REPL (Read-Eval-Print Loop)
The REPL allows you to interact with MicroPython directly. 1. Open Thonny or a terminal. 2. Connect to the Pico and enter the REPL prompt:
3. Type: 4. Press Enter to see the output.4. Blinking an LED (First Hardware Interaction)
Let's blink the built-in LED on the Pico to test MicroPython.
MicroPython Code:
from machine import Pin
from time import sleep
led = Pin("LED", Pin.OUT) # Onboard LED on Pico/Pico 2
while True:
led.toggle()
sleep(0.5)
Steps:
- Copy and paste this code into Thonny or a VS Code file.
- Click Run.
- The onboard LED should blink every 0.5 seconds.
Now that you have set up MicroPython and tested your first script, explore.