
In this article we will learn how to program Raspberry Pi Pico with microPython. This might have been the fastest ever I took to blink an LED on any board. It only requires a few simple steps and you are up and running. MicroPython is a subset of the Python language, so loved and widely used around the world.
It allows embedded devices like microcontrollers to run an interpreted language, which allows modifications on the fly. That means no more compilation, the code is simply saved on the device’s flahs memory then executed in real time. Instead of the traditional “Write code -> compile -> flash -> test -> go back to writing code”, now you can “Write code -> save it to the board” and tha’s all.
Micropython for embedded devices has what is called a REPL. That means Read, Evaluate, Print, Loop, essentially saying that no more compilation is necessary, everything is on the go. You can run MicroPython on a bunch of microcontrollers these days, including STM32, ESP32 and Raspberry Pi Pico.
I will show you how to create your first code in Micropython using the Raspberry Pi Pico, but the same applies to the Pi Pico 2 and even ESP32.
You are going to need:
- Thonny IDE, which is a software for both Linux and Windows
- Computer (Desktop/laptop)
- Raspberry Pi Pico ot Raspberry Pi Pico 2
- An LED (any color)
- A resistor (between 1k ohm and 4k7 ohm)
- Breadboard
- Jumper wires
There is the official guide from the foundation for the Raspberry pi Pico, very similar to what we will do here. Start be installing the Thonny IDE from here. It is a simple to use and lightweight software that allows programming many boards in MicroPython.
As a first step, we will supply/flash the microPython firmware to the Pico board. This is necessary since these boards generally come with Arduino firmware and support. Press and hold the BOOTSEL button of the Pico while connecting its USB cable to the computer. Once the cable is connected to the computer, release BOOTSEL. You will see a new drive in your file explorer (e.g. Windows explorer).
So for example you normally have a “C:\” in your file explorer, now a second or third (essentially a new one) drive will show up. Download the UF2 file from this source. This is the file responsible for transforming your board into one capable of running Micropython. Drag such file to the new drive that show up in the last paragraph, which is the Pico board. It will reboot automatically and you are good to go.
With the Pico board connected to the computer, open the Thonny IDE and go to “Tools > Options > Interpreter”. Select “Micropython (Raspberry Pi Pico” and the COM port that represents your Pico (there will ideally be only one, select it). If you don’t know which COM port your Raspberry Pi Pico became, press the Windows button and type “Device manager”.
Under “Com Ports” there will be a new device called Raspberry Pi Pico or something similar. Close the device manager window, go back to Thonny IDE, select the COM port you just saw and click “OK”.
There is a console in the bottom of the Thonny IDE, which (if the above steps were successful) wil show something like this.
MicroPython v1.22.2 on 2024-02-22; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
I have connected a LED to pin 18 of my Pico, with a series resistor of 1k Ohm. You can also use its onboard LED on pin 25.
The code
The code below will blink an LED every 0.5 seconds, using time.sleep(). Most hardware interactions in microPython will happen via the “machine” package. That package contains most IOs management like SPI, I2C and GPIO.
from machine import Pin
import time
led = machine.Pin(18, machine.Pin.OUT)
while True:
led.high()
time.sleep(0.25)
led.low()
time.sleep(0.25)
After typing the above code, click the green arrow on top of the screen. You will see the LED blinking. Try and change the output pin (in our case was 18) and the time (in our case, 0.25 seconds) to see what happens.
Here is a quick and short video with the experiment executed:
More articles about the Raspberry Pi Pico are to follow, I want to explore it even more. Meanwhile, explore the ESP32-S2 with microPython in this post.






Pingback: I bricked my Raspberry Pi Pico, how to solve? - FritzenLab electronics
Pingback: Read a button with Raspberry Pi Pico and microPython - FritzenLab electronics
Pingback: BlinkWithoutDelay with Raspberry Pi Pico and microPython - FritzenLab electronics
Pingback: Falling and rising edge input detector with microPython - FritzenLab electronics
Pingback: how many Raspberry Pi models exist? - FritzenLab electronics
Pingback: Raspberry Pi Pico temperature sensor - FritzenLab electronics
Pingback: New Raspberry Pi Pico 2 with RP2350 - FritzenLab electronics
Pingback: Getting started with Raspberry Pi Pico 2 - FritzenLab electronics