How to Set Up and Program Raspberry Pi Pico

Aniket Arya
Analytics Vidhya
Published in
5 min readFeb 13, 2021

Raspberry Pi Pico is a miniature marvel, putting the same technology that underpins everything from smart home systems to industrial factories in the palm of your hand. Whether you’re looking to learn about the MicroPython programming language, take your first steps in physical computing, or want to build a hardware project, Raspberry Pi Pico and its amazing community will support you every step of the way.

(Image source — Aniket Arya)

Raspberry Pi Pico is known as a microcontroller development board, meaning simply that it’s a printed circuit board housing a special type of processor designed for physical computing: the microcontroller. The size of a stick of gum, Raspberry Pi Pico packs a surprising amount of power thanks to the chip at the center of the board: an RP2040 microcontroller.

RP2040 Controller

It features a dual-core Arm Cortex-M0+ processor with 264KB internal RAM and support for up to 16MB of off-chip Flash. A wide range of flexible I/O options includes I2C, SPI, and uniquely Programmable I/O (PIO). These support endless possible applications for this small and affordable package. Raspberry Pi Pico is a low-cost, high-performance microcontroller board with flexible digital interfaces.

From controlling appliances to operating a light display, Raspberry Pi Pico puts the technology that underpins countless everyday operations into your hands.

Programmable in C and MicroPython, Pico is adaptable to a vast range of applications and skill levels, and getting started is as easy as dragging and dropping a file. More experienced users can take advantage of Raspberry Pi Pico’s rich peripheral set, including SPI, I2C, and eight Programmable I/O (PIO) state machines for custom peripheral support.

How to Set Up the Raspberry Pi Pico

  1. Push and hold the BOOTSEL button on the Pico, then connect to your computer using a micro USB cable. Release BOOTSEL once the drive RPI-RP2 appears on your computer.
(Image Source - Aniket Arya)

2. Open the RPI-RP2 drive that appears in the Drives tab, click open the INDEX.htm file, it will open the raspberry pi website in the browser.

3. Here you can see two ways in which pico can be programmed, MicroPython and C/C++.

(Image — Raspberry Pi website)

4. Download the MicroPython UF2 file from the MicroPython tab.

5. Drag and drop the UF2 file on to the RPI-RP2 drive. The Raspberry Pi Pico will reboot and will now run MicroPython.

To write your own program you will need software to communicate with pico and write programs on it, for MicroPython we will use Thonny, go through the following steps to get started with pico programming using Thonny IDE.

  1. Download and install Thonny for your OS (Windows, MAC, or Raspbian OS). You can grab it for free from the Thonny website.

2. Connect the Raspberry Pi Pico to your computer and in Thonny go to Tools > Options and click on the Interpreter tab. From the interpreter dropdown list, select MicroPython (Raspberry Pi Pico). The port dropdown menu can be left to automatically detect the Pico. Click Ok to close.

3. when you plugin the pico Board, A firmware installation tab will appear for raspberry pi pico, click on Install, this will install the necessary files to communicate Thonny with pico.

4. After successful installation, the MicroPython version and Raspberry board will appear in the Python Shell (also called REPL, Read, Eval, Print, Loop) will now update to show that the Pico is connected and working.

5. To test we can write a quick print function to say “Hello World.” Press Enter to run the code.

print(“Hello World”)

When you hit enter you can see the program is being executed using the pico board in real-time and output is visible in Python Shell.

Writing a blink program for the onboard LED of pico

Writing program for pico is similar to writing a python program, you need to import some files that will be used to configure pins and use the functions from which hardware will work.

  1. Copy the Below code and paste it in the Editor tab.
from machine import Pin
import utime
led = Pin(25, Pin.OUT)
led.low()
while True:
led.toggle()
print("Toggle")
utime.sleep(1)

2. Save the program in pico and give a unique name (avoid using main.py or info.py)

3. The program will run and you can see the LED toggling in the board as well as the output in the Python shell.

We have successfully tested our Raspberry Pi Pico and we can now move on to another project. Such as learning how to use sensors with the Raspberry Pi Pico.
Stay connected, I will post more on the PICO programs.

--

--

Aniket Arya
Analytics Vidhya

An enthusiastic and ambitious Electronics Engineer. | Freelance Content Writer