Raspberry Pi Pico Micropython Tutorial | Beginners Guide
Raspberry Pi Pico Micropython Tutorial – Learn to code Raspberry Pi Pico using Thonny and Micropython. Step by step getting started guide.
Last Updated: April 8, 2026 | MicroPython v1.28.0 | Applies to Pico, Pico W, Pico 2, and Pico 2 W
The Raspberry Pi Pico is a low-cost ARM-based microcontroller that you can program in MicroPython or C/C++. Unlike a full Raspberry Pi, it has no operating system — it runs your program directly on the chip, making it fast, predictable, and ideal for hardware control projects. This guide walks you through installing MicroPython on your Pico, setting up Thonny, and running your first two programs: a Hello World and a blinking LED.
Table of Contents
- Which Pico Do You Have? — Important Before You Start
- Installing MicroPython on Your Pico
- Setting Up Thonny
- Example 1 — Hello World
- Example 2 — Blinking the Onboard LED
- Where to Go Next
New to the Pico entirely? Read our full introduction first: Raspberry Pi Pico Beginner’s Guide — it covers what the Pico is, how it compares to other boards, and what you can build with it before you write a single line of code.
1. Which Pico Do You Have? — Important Before You Start
There are now several Pico variants and each one needs a different MicroPython firmware file. Using the wrong one causes silent failures or missing features. Check the top of your board — the chip model is printed on it.
- Raspberry Pi Pico / Pico H — the original board, RP2040 chip, no wireless. Mass storage drive appears as
RPI-RP2when in bootloader mode. - Raspberry Pi Pico W / Pico WH — same RP2040 chip but with built-in WiFi and Bluetooth via CYW43439. Also appears as
RPI-RP2. Needs a different firmware file than the non-W version. - Raspberry Pi Pico 2 — newer board, upgraded RP2350 chip, dual Cortex-M33 cores at up to 150 MHz, 520 KB SRAM, no wireless. Drive appears as
RP2350. - Raspberry Pi Pico 2 W — RP2350 chip with WiFi and Bluetooth. Also appears as
RP2350. Needs its own specific firmware.
Critical: Do not use the Pico firmware on a Pico W or vice versa. On the Pico W, GPIO pin 25 connects to the wireless chip — not the onboard LED. Using pin 25 directly (as many older tutorials instruct) will not work on the Pico W and may cause unexpected behaviour. The correct method for all boards is shown in Example 2 below.
2. Installing MicroPython on Your Pico
MicroPython is not pre-installed on any Pico. You need to flash it once using a UF2 file — a special firmware format that the Pico accepts when in bootloader mode. You only need to do this once; after that, MicroPython stays on the board until you overwrite it.
Step 1 — Download the Correct MicroPython UF2 File
Go to micropython.org/download and download the UF2 for your specific board:
- Pico (RP2040, no WiFi) → micropython.org/download/RPI_PICO
- Pico W (RP2040, with WiFi) → micropython.org/download/RPI_PICO_W
- Pico 2 (RP2350, no WiFi) → micropython.org/download/RPI_PICO2
- Pico 2 W (RP2350, with WiFi) → micropython.org/download/RPI_PICO2_W
Always download the latest stable release from each page. As of April 2026, the current version is MicroPython v1.28.0 (released April 6, 2026).
Step 2 — Enter Bootloader Mode
Locate the BOOTSEL button on your Pico — it is the small white button on the top of the board near the USB connector.
Press and hold BOOTSEL, then plug the micro USB cable into your Pico and into your computer. Keep holding BOOTSEL until the drive appears on your computer — then release the button.
- On Pico / Pico W (RP2040): the drive appears as
RPI-RP2 - On Pico 2 / Pico 2 W (RP2350): the drive appears as
RP2350
Step 3 — Flash MicroPython
Drag and drop the UF2 file you downloaded onto the drive that appeared. The Pico will automatically reboot after the file copies — the drive will disappear from your computer. This is normal and means MicroPython has been installed successfully. Your Pico is now running MicroPython and ready to connect to Thonny.
3. Setting Up Thonny
Thonny is a beginner-friendly Python IDE that has built-in support for MicroPython on Pico. It is available free for Windows, macOS, and Linux at thonny.org. Download and install the latest version — as of 2026 this is Thonny 4.x. The old instruction to specifically get v3.3.2 for Windows no longer applies; the current version works on all platforms.
Connecting Thonny to Your Pico
- Make sure your Pico is plugged into your computer via USB (not in bootloader mode — just plugged in normally after MicroPython is installed)
- Open Thonny
- Click the interpreter selector in the bottom-right corner of the Thonny window — it will currently show something like “Local Python 3”
- Select MicroPython (Raspberry Pi Pico) from the dropdown
- Thonny will automatically detect the connected Pico and show a Shell panel at the bottom with a
>>>prompt — this is the MicroPython REPL (Read-Eval-Print Loop)
If Thonny does not detect your Pico automatically, go to Tools → Options → Interpreter, select MicroPython (Raspberry Pi Pico), and manually choose the correct COM port (Windows) or /dev/ttyACM0 (Linux/macOS).
If Thonny says “device is busy” when you try to connect, click the Stop/Restart button (the red stop icon) first. This stops any currently running program on the Pico and frees the connection.
4. Example 1 — Hello World
With Thonny connected to your Pico, you can run code in two ways: directly in the Shell (one line at a time) or by writing a script and running it. For a quick Hello World test, use the Shell.
Running in the Shell (Quick Test)
Click in the Shell panel at the bottom of Thonny where you see the >>> prompt. Type the following and press Enter:
print("Hello World")
You should immediately see Hello World printed below. This confirms that MicroPython is installed correctly and Thonny is communicating with your Pico.
Saving as a Script File
For a program you want to run repeatedly or save permanently, write it in the main editor panel (the top white area in Thonny) rather than the Shell:
- Click in the main editor panel
- Type
print("Hello World") - Click File → Save (or press Ctrl+S)
- Thonny will ask whether to save to This computer or to Raspberry Pi Pico — choose Raspberry Pi Pico
- Name the file
hello.py(the .py extension is required) - Click the green Run button (or press F5) — you will see the output in the Shell panel below
Files saved directly to the Pico’s internal flash storage will remain there even when the power is disconnected. If you save a file named main.py on the Pico, it will run automatically every time the Pico is powered on — even without a computer connected.
5. Example 2 — Blinking the Onboard LED
Blinking an LED is the hardware equivalent of Hello World — it confirms that your code can control physical pins. Every Pico variant has a green onboard LED, and you do not need any additional components for this example.
Important 2026 update: Older tutorials (including the original version of this article) used
Pin(25)to control the onboard LED. This only works on the original Pico (RP2040, non-W). On the Pico W, pin 25 connects to the wireless chip — not the LED — soPin(25)will not blink the LED. The correct way to control the onboard LED on all Pico variants is to use the string"LED"instead of the pin number. This works on Pico, Pico W, Pico 2, and Pico 2 W.
Step 1 — Create a New File
In Thonny, click File → New to open a blank editor panel. Make sure your Pico is connected and Thonny shows MicroPython in the bottom-right corner.
Step 2 — Import the Required Libraries
MicroPython comes with built-in libraries for hardware control. You need two: Pin from the machine library to control GPIO, and time (or utime) to add delays between blinks.
from machine import Pin
import time
Step 3 — Create the LED Object
Create a Pin object that represents the onboard LED. Using the string "LED" works correctly on all Pico variants — the MicroPython firmware maps it to the correct pin or wireless chip GPIO automatically:
led = Pin("LED", Pin.OUT)
led.off() # Ensure LED starts in the off state
Step 4 — Write the Blink Loop
A while True loop runs forever — which is exactly what you want for a hardware control program that should keep running until you stop it or remove power:
while True:
led.toggle()
print("Toggling LED")
time.sleep(1)
led.toggle() switches the LED from on to off or off to on each time it runs. time.sleep(1) pauses execution for one second before the loop repeats. The print statement outputs “Toggling LED” to the Thonny Shell each cycle so you can confirm the loop is running even when looking at the screen instead of the board.
Step 5 — The Complete Code
Your complete blink script should look like this:
from machine import Pin
import time
led = Pin("LED", Pin.OUT)
led.off()
while True:
led.toggle()
print("Toggling LED")
time.sleep(1)
Step 6 — Save and Run
- Press Ctrl+S to save
- Choose Raspberry Pi Pico when asked where to save
- Name the file
blink.pyand click OK - Click the green Run button (or press F5)
The onboard LED will begin blinking once per second, and you will see “Toggling LED” printed every second in the Shell panel. To stop the program, click the red Stop button in Thonny or press Ctrl+C in the Shell.
Tip: If you want the blink program to run automatically every time the Pico is powered on (without needing a computer), save the file as
main.pyinstead ofblink.py. MicroPython automatically runsmain.pyon boot.
Prefer to Use Arduino IDE Instead of Thonny?
If you are already familiar with Arduino IDE, you can program the Pico using it instead of Thonny and MicroPython. The Arduino IDE supports the Pico via the arduino-pico community board package — you write C++ sketches exactly as you would for an Arduino board. Full setup guide here: How to Program Raspberry Pi Pico Using Arduino IDE.
Not sure whether to use MicroPython with Thonny or C++ with Arduino IDE? The short answer is: MicroPython is faster to start with and better for interactive experimentation. C++ via Arduino IDE is better for performance-critical projects or if you already have an Arduino codebase you want to reuse. For more on the differences between the Pico and Arduino, see: Arduino vs Raspberry Pi — Which One For Your Project?
6. Where to Go Next
- Raspberry Pi Pico Beginner’s Guide — full introduction to the board, specs, and what you can build
- Program Pico Using Arduino IDE — alternative to Thonny if you prefer C++ and Arduino
- RP2040 Microcontroller Guide — deep dive into the chip that powers the Pico and Pico W
- All About the RP2040 — PIO, dual-core, programmable I/O, and what makes it different
- GPIO Control on Raspberry Pi — if you want to move to a full Pi for more complex GPIO projects
- Arduino vs Raspberry Pi — choosing the right board for your next project
Written by Jithin at RootSaid. Last updated April 8, 2026. Verified with MicroPython v1.28.0 on Raspberry Pi Pico and Pico W. The LED code has been corrected from the original article to use Pin("LED") which works correctly on all Pico variants including the Pico W. Questions or issues? Drop them in the comments.
