BC Robotics

Programming the Raspberry Pi Pico with MicroPython


When one thinks of programming a Raspberry Pi, Python immediately springs to mind. This popular programming language is relatively easy to use and excellent for beginners. So, it is unsurprising that the first Raspberry Pi microcontroller can be programmed using MicroPython. One of the easiest methods of programming the Pico with MicroPython is using the Thonny IDE. This simple development environment is available on a wide variety of operating systems.  In this short tutorial we will go through setting up Thonny with the Pico!

Why use the Pico? This is the Raspberry Pi Foundation’s first attempt at an extremely low cost, highly capable, microcontroller. It packs a powerful dual-core processor, plenty of RAM, and numerous multi-function IO pins that make it a popular choice in the microcontroller category. We manufacture a variety of Raspberry Pi Pico add-on boards to extend its functionality. 

The Parts Needed:

This tutorial will need a few different parts:

  • Raspberry Pi Pico (any version)
  • USB A – USB micro cable  
  • Computer / Laptop / Raspberry Pi capable of running the Thonny IDE

Step 1 - Install The Thonny IDE

Depending on which operating system you are using, the steps here will vary slightly. If you are using Windows, Mac, or Linux (Other than Raspberry Pi OS) simply proceed to https://thonny.org and click the appropriate download link. Once downloaded, run the installer. 

If you are using the Raspberry Pi OS, Thonny is already installed. You may need to update it using the following code in a terminal window (CTRL + ALT + T)

					sudo apt update && sudo apt upgrade -y

Step 2 - Plug In Your Pico

With the software installed on the computer, we now need to install the firmware on the Raspberry Pi Pico for MicroPython. This only needs to be done the first time you use a Pico with MicroPython.

Hold the BOOTSEL button down while connecting your Pico to your computer. Depending on your computer / operating system you may be notified that a new USB Drive has been detected. 


Step 3 - Setting Up Thonny

If Thonny is not open already, open the program. In the bottom right corner of the window the currently selected version of Python is viewable. This textbox can be clicked on to change the version of Python you are using. 


Step 4 - Selecting Python Version

Click the version in the bottom right corner, and select ‘MicroPython’ (Raspberry Pi Pico)’  from the menu that appears. If this option is not available in the list, it may mean that the Pico is not plugged in, or it was plugged in without the ‘BOOTSEL’ button pressed. 

When the correct version is selected, A new window should pop open prompting a firmware installation. 


Step 5 - Installing MicroPython Firmware

In the window that has now appeared, click ‘Install’ to install the MicroPython firmware onto your Raspberry Pi Pico. 

Once the installation has completed, click ‘Close’. 


Step 6 - Write A Quick Test Program

In the top window of Thonny, copy the following code. Just like Python, MicroPython is sensitive to whitespace, so ensure it is formatted exactly as pictured. 

There is a small difference in design between the Raspberry Pi Pico W and the standard Pico with regards to the built-in LED. On the Pico, it is connected to GPIO 25 per normal. With the Pico W, the built-in LED is actually connected to the wireless chip and cannot be accessed through GPIO 25, instead you will want to use “LED” in place of 25 for the address. 

					from machine import Pin
from time import sleep

led = Pin(25, Pin.OUT) #If using a Pico 
#led = Pin("LED", Pin.OUT) #If using Pico W


Step 7 - Save To Your Pico

Click the green “Play” button in the toolbar to test out the code. This will prompt you to save the file to a location. Select “Raspberry Pi Pico” and enter a filename. Once saved, it will run the program on your Pico. The built-in LED should flash once every second. 

If you ever need to stop the program or the Pico will not respond, you can force it to stop by hitting the red “Stop” button in the toolbar. Pressing the button one more time will reconnect Thonny to your Pico.

Thonny and your Pico are now ready! 


3 thoughts on “Programming the Raspberry Pi Pico with MicroPython”

Leave a Reply

Your email address will not be published.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
  • Attributes
  • Custom attributes
  • Custom fields
Click outside to hide the comparison bar