Programming Raspberry Pi Pico with Python and MicroPython — The MagPi magazine (2025)

You can pick up a Raspberry Pi Pico from just $4 / £3.60, or free with the latest edition of HackSpace magazine.

Programs written for other MicroPython-compatible microcontroller boards will work on Raspberry Pi Pico, and vice versa – sometimes needing minor modification for different features between boards – giving Raspberry Pi Pico a healthy library of projects and tutorials beyond those developed by Raspberry Pi itself.

Meanwhile, the C/C++ SDK is fine-tuned to RP2040 and has all the headers, libraries, and build systems necessary to write programs in C,C++, or assembly language. Additionally, the C/C++ SDK provides higher-level libraries for dealing with timers, USB, synchronisation, and multicore programming, along with additional high-level functionality built using PIO such as audio.

Beginners looking to get started with the MicroPython port should start with the Raspberry Pi Pico Python SDK documentation and be sure to pick up a copy of Getting Started with MicroPython on Raspberry Pi Pico.

Programming Raspberry Pi Pico with Python and MicroPython — The MagPi magazine (1)

Get Started with MicroPython on Raspberry Pi Pico

For more physical computing projects to try on your Raspberry Pi Pico, grab a copy of the new book, Get Started with MicroPython on Raspberry Pi Pico. As well as learning how to use Raspberry Pi Pico’s pins as inputs and outputs, you’ll build a simple game, measure temperatures, save and load data to your Pico’s file system, and even make a burglar alarm for your room.

Get Started with MicroPython on Raspberry Pi Pico is available now from Raspberry Pi Press.

Programming Raspberry Pi Pico with Python and MicroPython — The MagPi magazine (2)

Makers looking to explore the C/C++ SDK should download the Pico C/C++ SDK documentation.

Raspberry Pi Pico data sheets

Make sure to read, and bookmark, these new Raspberry Pi Pico and 2040 data sheets.

Program Raspberry Pi Pico with MicroPython

Raspberry Pi Pico is set up, by default, for use with the C/C++ Software Development Kit (SDK). The C/C++ SDK is an extremely flexible and powerful way to interact with your Raspberry Pi Pico. However, there’s a more beginner-friendly method: MicroPython, a port of the Python programming language designed specifically for microcontrollers.

In this tutorial we’re going to switch the Pico firmware from C/C++ to MicroPython and create our first program, which flashes the LED on the board.

You'll need

Open Raspberry Pi Pico in boot mode

Take your Raspberry Pi Pico and a micro USB to USB-A cable, and connect the small micro USB end of Pico. Hold down the small button on your Raspberry Pi Pico marked ‘BOOTSEL’ and plug the larger USB-A cable end into your computer (we are using a Raspberry Pi).Wait a few seconds, then let go of the BOOTSEL button. You will see your computer mount a removable drive. Click OK in the ‘Removable medium is inserted’ window to open Raspberry Pi Pico’s on-board storage.

Programming Raspberry Pi Pico with Python and MicroPython — The MagPi magazine (3)

Flash the MicroPython firmware

Double-click the INDEX.HTM file displayed in Pico’s mounted storage. Your browser will open and display the ‘Welcome to your Raspberry Pi Pico’ webpage. Choose the ‘Getting started with MicroPython’ tab, and click ‘Download UF2 file’ to download the MicroPython firmware. It’s a small file, so it’ll only take a few seconds.

Open File Manager and locate the micropython-16-DEC-2020.uf2 file in the Downloads folder (the file name may have been updated with a later date). Drag-and-drop the UF2 file to the Raspberry Pi Pico’s removable drive (named ‘RPI-RP2’). After a few seconds, the drive will disappear as the new MicroPython firmware is recognised and installed.

Programming Raspberry Pi Pico with Python and MicroPython — The MagPi magazine (4)

Switching the back end

The best way to program in MicroPython on your Raspberry Pi Pico is with the Thonny Python IDE (integrated development environment). Open the Raspberry Pi menu and choose

Programming > Thonny Python IDE.

Programming Raspberry Pi Pico with Python and MicroPython — The MagPi magazine (5)

Thonny is normally used to write programs that run on the same computer you’re using Thonny on; to switch to writing programs on your Raspberry Pi Pico, you’ll need to choose a new Python interpreter. Look at the bottom-right of the Thonny window for the word ‘Python’ followed by a version number: that’s your current interpreter.

Click ‘Python’ and look through the list that appears for ‘MicroPython (Raspberry Pi Pico)’ – or, if you’re running an older version of Thonny, ‘MicroPython (generic)’.

Tip! Update Thonny

If you don’t see MicroPython (Raspberry Pi Pico) in the interpreter list, you’ll need to update Thonny. Open a Terminal window and type:

sudo apt update && sudo apt full-upgrade -y

Code Hello World in MicroPython

Writing a program for your Raspberry Pi Pico is a lot like writing a program for your Raspberry Pi. You can type commands in the Shell area at the bottom of the window to have them immediately executed, or you can write a program in the main part of the window to run on-demand.

Click in the Shell area, next to the >>>> symbols, and type:

print("Hello, World!")

When you press ENTER at the end of the line, you’ll see your Raspberry Pi Pico respond. Try typing the same line again, but in the main part of the Thonny window – then click the Run icon. You’ll be asked whether you want to save your program to ‘This computer’ or ‘Raspberry Pi Pico’. Click on ‘Raspberry Pi Pico’, give your program the name hello_world.py, then click OK to save and run your first program.

Create a program that blinks Raspberry Pi Pico's LED

While Raspberry Pi Pico can run Python programs like the one above, its true power comes from interfacing with external hardware like buttons and LEDs. You can start programming a physical computing project without any extra hardware, too, thanks to an on-board LED (assigned to the non-broken-out GP25 pin).

Click the New icon and type in the blinky_led.py code. Click Run, save the program to your Raspberry Pi Pico, and watch the LED on Raspberry Pi Pico: it will turn on for one second, then off for one second, thenrepeat.

import machineimport utimeled_onboard = machine.Pin(25, machine.Pin.OUT)while True: led_onboard.toggle() utime.sleep(1)

Programming Raspberry Pi Pico with Python and MicroPython — The MagPi magazine (6)

Programming Raspberry Pi Pico with Python and MicroPython — The MagPi magazine (2025)

FAQs

What is the best programming language for Raspberry Pi Pico? ›

A Raspberry Pi Pico responds to a variety of coding languages, including C, C++, and MicroPython. MicroPython is a more lightweight and simple version of traditional Python, and it is the most common language used by Raspberry Pi Pico hobbyists.

Can Raspberry Pi Pico be programmed in Python? ›

MicroPython is a full implementation of the Python 3 programming language that runs directly on embedded hardware like Raspberry Pi Pico. You get an interactive prompt (the REPL) to execute commands immediately via USB Serial, and a built-in filesystem.

How can you create a software PWM on the Raspberry Pi Pico using MicroPython? ›

Wrapping Up

To wrap up, to output PWM signals on the Raspberry Pi Pico GPIOs, we can use the machine. PWM class. First, you create a PWM object on a GPIO of your choice. After that, you can use the freq(), duty_u16 and deinit() methods on the PWM object, to set the PWM frequency, duty cycle, and stop PWM, respectively.

How to run Python script on Raspberry Pi Pico? ›

Open and Run Script Directly
  1. Open Thonny IDE and plug the Pico into your computer with a micro USB cable and click on the “MicroPython (Raspberry Pi Pico). COMxx” interpreter in the bottom right corner.
  2. Open Script. For example, grayscale_2_get_value.py . ...
  3. Run the Script. ...
  4. Stop Running. ...
  5. Save or Save as.

What is better than the Raspberry Pi Pico? ›

The Arduino NANO Every is the board closest to the Pico's form factor so it is a worthy comparison. The NANO has 22 GPIO pins, 8 of them analog input pins and 5 PWM pins. The NANO has two ground pins, one on each side, and 3.3V and 5V power pins.

What is the difference between MicroPython and Python? ›

The key difference between Python and MicroPython comes from the fact that they are designed for different purposes. Python is used to write code that runs on powerful processors, whilst MicroPython was designed to be compatible and power microcontrollers and microprocessors.

Does Raspberry Pi run Python or MicroPython? ›

You can build and run MicroPython on a Raspberry Pi 4, but only the generic Unix version.

What IDE is used for Raspberry Pi Pico? ›

A Pi Pico can definitely be programmed from the arduino IDE (it can also be C/C++ programmed using a C toolchain involving make which is quite laborious to install (on Linux anyway) and which Rasp Pi explains in various tutorial pdfs).

How to put MicroPython on pico? ›

Add the MicroPython firmware
  1. Press the BOOTSEL button and hold it while you connect the other end of the micro USB cable to your computer. ...
  2. This puts your Raspberry Pi Pico into USB mass storage device mode. ...
  3. Click on the Python version and choose 'MicroPython (Raspberry Pi Pico)':

What software does Raspberry Pi Pico use? ›

MicroPython firmware for Raspberry Pi Pico. The Thonny Python IDE.

What is the maximum PWM frequency for Raspberry Pi Pico? ›

Raspberry Pi Pico – PWM Channels

The frequency of the PWM signal can range between 8Hz and 62.5MHz, while the microcontroller is running at a frequency of 125MHz.

What coding language does Raspberry Pi Pico use? ›

MicroPython is a version of the Python programming language for microcontrollers, such as your Raspberry Pi Pico W.

What Python IDE does Raspberry Pi use? ›

IDLE has been with Raspbian for generations as the default editor. As such, many introductory Python tutorials out there still show screenshots with IDLE. That being said, IDLE is little more than a text editor and a terminal window.

What is the most efficient language for Raspberry Pi? ›

Python. Python takes the crown as the most widely used with Raspberry Pi programming language. It is the go-to language for developing web applications, machine learning algorithms, and electronics projects. Python's simple and intuitive syntax makes it a favorite among students, developers, and Pi users.

Can Raspberry Pi Pico run C++? ›

Raspberry Pi Pico C/C++ SDK

Our official C SDK can be used from the command line, or from popular integrated development environments like Visual Studio Code, Eclipse, and CLion. To get started, download our C/C++ SDK and Examples, and take a look at our 'getting started' documentation to get going.

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 5727

Rating: 4 / 5 (51 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.