Starting Electronics needs your help! Please make a donation to help cover our hosting and other costs. Click the donate button to send a donation of any amount.

Easiest way to Start using a Raspberry PI Pico

Created on: 24 December 2021

Easiest way to start using a Raspberry PI Pico is covered in this tutorial. A new Raspberry PI Pico microcontroller board can be quickly and easily tested. This is done by switching and blinking the on-board LED using the Python programming language with MicroPython. A “hello world” program is also included in this tutorial.

Raspberry PI Pico Microcontroller Board

Hardware for Starting with the Raspberry Pi Pico

There is no need to do any soldering or circuit building when doing a quick test of the Raspberry PI Pico microcontroller board. The USB port powers the board and a program controls the on-board LED. Use the following hardware with this tutorial.

  • A Raspberry Pi Pico board.
  • A micro USB cable for powering and programming the board
  • A computer with free USB port for programming the board.

Quick Overview of this Raspberry PI Pico Tutorial

This is a summary of the more detailed steps on the easiest way to start using a Raspberry PI Pico microcontroller board. The steps are as follows with details in the next section.

  • Plug the Raspberry PI Pico board into a spare USB port of a computer using a micro USB cable.
  • The Pico board appears as a Flash drive after plugging it into the host computer.
  • Download the MicroPython file.
  • Copy the MicroPython file to the Pico Flash drive folder.
  • Download and install the Thonny MicroPython IDE on the host computer.
  • Write some Python programs using Thonny and load them to the Pico to test the board.

Easiest way to Start using a Raspberry PI Pico Tutorial Steps

Follow the tutorial steps below to easily start using the Raspberry PI Pico board. Program the board using the Thonny IDE running on the host computer, as described in the steps. “Host computer” refers to the computer used to program the target Raspberry PI Pico board in this tutorial.

1. Plug the Board into the Host Computer

Plug the Raspberry PI Pico board into a free USB port of the host computer using a micro USB cable.

Raspberry Pi Pico board plugged into a micro USB cable.
Raspberry Pi Pico Board Plugged into a micro USB Cable

After plugging the Pico board into the host computer, the board appears as a Flash drive. If it does not, then unplug the board from the USB port. Hold down the BOOTSEL switch found on top of the board and plug the board back into the USB port. After three seconds, release the BOOTSEL switch.

The Pico board opens in a new file manager window. On Linux Mint MATE the file manager opens as shown in the image below.

Raspberry PI Pico Flash drive folder on a Linux Mint MATE computer.
Raspberry PI Pico Flash Drive Folder on a Linux Mint MATE Computer

On a Windows computer the file manager opens as shown in the following image.

Raspberry PI Pico Flash drive folder on a Windows computer.
Raspberry PI Pico Flash Drive Folder on a Windows Computer

Leave the Pico board Flash drive window open. Download and copy a file to the Pico using the file manager window as explained in the next steps.

2. Download the MicroPython File

Download the UF2 MicroPython file from the Raspberry PI website. The Raspberry PI MicroPython page has a link to the same file.

3. Copy the MicroPython File to the Pico Board

Locate the UF2 file on the host computer downloaded in the previous step. At the time of writing the file name is rp2-pico-20210902-v1.17.uf2. This file will have a different date and version number if it is updated. Drag this file and drop it into the Raspberry PI Pico Flash drive folder that opened in the first step of this tutorial. This copies the file to the Pico board. After copying has finished, the Pico Flash drive folder disappears. The MicroPython interpreter is now running on the Pico board and the board is ready to be programmed using the Thonny IDE.

4. Download and Install the Thonny IDE

Visit the Thonny website to download the Thonny MicroPython IDE. Thonny is available for Windows, Mac and Linux. Scroll down the Thonny page to find download and install instructions. Follow the instructions and install Thonny on the host computer.

5. Test the Raspberry Pi Pico Board using Python

Thonny is the easiest way to start using a Raspberry PI Pico by programming the board using MicroPython. Change a setting in Thonny in the following steps to use Thonny with the Pico board.

5.1 Start the Thonny IDE

Start the Thonny IDE installed in the previous step. It is found in a Thonny folder on the Windows menu, and on the Programming menu of a Linux Mint MATE computer. After a default install, the Thonny IDE looks as follows when started.

Thonny IDE after a default install.
Thonny IDE After a Default Install

By default, the Thonny IDE is set up to use the Python interpreter that was installed with it. A setting must be changed to make it use the MicroPython interpreter that was installed to the Pico board in step three of this tutorial.

5.2 Select the MicroPython Interpreter in Thonny

On the top menu bar of the Thonny IDE, select Tools → Options… to open the Thonny options dialog box. Click the Interpreter tab in the dialog box. In the drop-down box on the Interpreter tab, select MicroPython (Raspberry Pi Pico) as shown in the following image.

Thonny options dialog box with MicroPython for the Raspberry PI Pico Selected
Thonny options dialog box with MicroPython for the Raspberry PI Pico Selected

Click the OK button to close the dialog box. If a message is displayed at the bottom of the Thonny window that says that it couldn’t find the device automatically, then first unplug the Pico board from the USB port. Close the Thonny application window. Plug the Pico board back into the USB port. Finally start Thonny again. The following image shows the message that appears in the bottom Shell pane of Thonny after Thonny connects to MicroPython that is running on the Pico board, a message is shown in the bottom Shell pane, as shown in the image below.

Thonny Connected to MicroPython on the Pico Board
Thonny Connected to MicroPython on the Pico Board

Note in the image that MicroPython (Raspberry Pi Pico) appears at the bottom right of the Thonny window. If this is not selected, go back and change it using the Thonny options dialog box. If there are any other problems connecting to the Pico board from Thonny, then try restarting the host computer. This includes problems when following the remainder of this tutorial.

5.3 Test the Raspberry PI Pico On-board LED

Enter the following line of code in the bottom Shell pane of Thonny to set up the pin connected to the on-board LED as an output pin.

led_onboard = machine.Pin(25, machine.Pin.OUT)

Switch the LED on by entering the following.

led_onboard.toggle()

Check that the green LED next to the micro USB port of the Raspberry PI Pico board switches on, as the next image shows.

On-board LED Switched On using Python and Thonny
On-board LED Switched On using Python and Thonny

Enter the above line of code again to switch the LED off. Entering the same code again after the LED is off switches it on again. Press the keyboard up arrow key to bring up the last line of code typed. This avoids having to type the line of code over again. After the line of code appears in the window, press the Enter key to run it. The following image shows what the bottom Shell pane of Thonny looks like after toggling the on-board LED on and off a few times.

Toggling the Raspberry PI On-board LED On and Off using Thonny
Toggling the Raspberry PI On-board LED On and Off using Thonny

Raspberry Pi Pico Board Hello World Program

It is easy to write a one line “hello world” program for the Raspberry PI Pico using the bottom interactive Shell pane in the Thonny IDE. Simply enter the following line of code at the prompt in the bottom Shell pane.

print("Hello, world!")

Running the above line of code results in the message between double-quotes being printed in the bottom shell pane below where the code was entered. The following image shows the result.

Raspberry PI Pico Hello World Program in MicroPython
Raspberry PI Pico Hello World Program in MicroPython

The image shows that the print() command was entered below the previous commands. The result is printed back to the Shell window by MicroPython running on the Pico board.

Raspberry Pi Pico Board Blink Program

In the previous code examples, the interactive Shell window was used to run code on the Pico board. A Python program can be entered into the top script pane of Thonny and saved to the Pico board. Enter the following code into the top script pane of Thonny.

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

When entering the code, use the Tab keyboard key to indent the last two lines of code. Only the second last line actually needs to be indented using the Tab key. When the Enter key is pressed after the second last line, then Thonny IDE automatically indents the next line of code.

After entering the above code, save the file using the Ctrl + S keyboard keys. Alternately, select File → Save using the top Thonny menu or the Save toolbar icon. A dialog box prompts to save either to the host computer or to the Pico board, as the following image shows.

Prompt Dialog Box when Saving a Script in Thonny
Prompt Dialog Box when Saving a Script in Thonny

Click Raspberry Pi Pico in the Where to save to? dialog box. In the save dialog box that opens, enter a file name of blink.py in the bottom File name field. Click the OK button when done. This saves the script entered into Thonny as a file called blink.py in the Pico board memory.

To run the script, click the Run current script icon on the top toolbar (the green icon). Hover the mouse cursor over the toolbar icons so that the tool tip pops up to show what each item is. If the script was entered correctly and the board is working, the LED should start blinking or flashing at a slow rate.

Click the red STOP icon to stop the script from running.

New Book: Explore ATtiny Microcontrollers using C and Assembly Language

Explore ATtiny Microcontrollers using C and Assembly Language book Ultimate Arduino Uno Hardware Manual

As an Amazon Associate I earn from qualifying purchases: