This article is a getting-started guide for the Raspberry Pi Pico W microcontroller board. It was built around the RP2040 chip, provides many GPIOs to connect peripherals, and can be programmed using C/C++ programming language or Micropython. Let’s explore the features of the Raspberry Pi Pico and learn how to run your first program.
Introducing the Raspberry Pi Pico
The Raspberry Pi Pico is a low-cost microcontroller board developed around the RP2040 chip by the Raspberry Pi Foundation. Unlike previous versions of the Raspberry Pi, the Raspberry Pi Pico is not meant to run an operating system. It is a microcontroller board like the Arduino, or ESP32, whose main purpose is to control electronic components through its GPIOs. If you’re familiar with the ESP32 or ESP8266 board, the Raspberry Pi Pico is not much different.
Variants of the Raspberry Pi Pico board
There are two main variants of the Raspberry Pi Pico board:
- Raspberry Pi Pico: no wireless connectivity (no Wi-Fi, no Bluetooth)
- Raspberry Pi Pico W: comes with wireless connectivity (Wi-Fi and Bluetooth)
You may also see those versions referenced with an H, like Raspberry Pi Pico H, or Raspberry Pi Pico WH, which means they come with soldered header pins.
Should you get a Raspberry Pi Pico or Raspberry Pi Pico W?
The Raspberry Pi Pico W comes with wireless connectivity, which is essential if you need to use Wi-Fi or Bluetooth in IoT or home automation projects. We recommend getting a Raspberry Pi Pico W, as the price difference is not significant and you’ll have the flexibility to use Wi-Fi or Bluetooth if needed.
Throughout this tutorial, we’ll use the Raspberry Pi Pico W, but everything also applies to the Raspberry Pi Pico, except the wireless connectivity features.
Where to Buy Raspberry Pi Pico?
The Raspberry Pi Pico W board is widely available on many different stores. Check the following link to compare its price on different stores:
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Raspberry Pi Pico W Specs
Here’s a list of the Raspberry Pi Pico W main specs:
- RP2040 microcontroller with 2MB flash
- CPU: Dual-core Arm Cortex-M0+ at 133MHz
- 264kB multi-bank high-performance SRAM
- 2MB onboard QSPI Flash
- 2.4GHz wireless interfaces (802.11n) using the Infineon CYW43439 (on the W models)
- Micro-USB B port (for power and programming)
- 3-pin ARM Serial Wire Debug (SWD) port
- 40 pins
Raspberry Pi Pico GPIO Interfaces
The Raspberry Pi Pico comes with 40 pins, 26 of which are programmable GPIOs that you can use to connect peripherals.
The Raspberry Pi Pico supports the following peripheral interfaces on its GPIOs:
- 2x UART
- 2x I2C
- 2x SPI
- 16x PWM channels
- 4x ADC pins (12-bit 500ksps)
The Raspberry Pi Pico GPIOs run at 3.3V.
Raspberry Pi Pico Pinout
The following picture shows the Raspberry Pi Pico pinout (which functions are supported by each pin). For a more detailed description of the Raspberry Pi Pico Pinout, check out this tutorial: Raspberry Pi Pico and Pico W Pinout Guide: GPIOs Explained.
The pins marked in red are power pins that output 3.3V. The black pins are GND pins. All pins in light green can be used as “regular” GPIOs (input and output) and all can generate PWM signals.
SPI, I2C, UART communication protocols, and ADC are supported on the pins with the corresponding labels.
How to Program the Raspberry Pi Pico?
The Raspberry Pi Pico can be programmed using C/C++ programming language (using Arduino IDE) or MicroPython. Currently, MicroPython is the most popular way to program the Raspberry Pi Pico and Thonny IDE is the recommended IDE to use with the Raspberry Pi Pico.
The Raspberry Pi Pico comes with a micro USB port that can be used for both power and programming. To program the Raspberry Pi Pico, you just need to use a USB cable to connect the board to your computer. Most Raspberry Pi Pico kits include the proper USB cable.
If you want to start programming the Raspberry Pi Pico using Arduino IDE instead, read the following tutorial:
If you want to use MicroPython, continue reading.
What is MicroPython?
MicroPython is a Python 3 programming language re-implementation targeted for microcontrollers and embedded systems. MicroPython is very similar to regular Python. Apart from a few exceptions, the language features of Python are also available in MicroPython. The most significant difference between Python and MicroPython is that MicroPython was designed to work under constrained conditions.
Because of that, MicroPython does not come with the entire pack of standard libraries. It only includes a small subset of the Python standard libraries, but it includes modules to easily control and interact with the GPIOs, use Wi-Fi, and other communication protocols.
Installing Thonny IDE
Thonny IDE is the recommended software to program the Raspberry Pi Pico board using MicroPython, and that’s the one we’ll use in this tutorial.
Thonny IDE can also be used to program the ESP32 and ESP8266 using MicroPython firmware. Learn more here: Getting Started with Thonny MicroPython (Python) IDE for ESP32 and ESP8266.
Go to this link https://thonny.org/ and click on the right link to download the package for your operating system.
Run the downloaded executable file and follow the installation procedure (use all the default settings).
Flashing MicroPython Firmware on Raspberry Pi Pico
Connect the Raspberry Pi Pico to your computer while holding the BOOTSEL button at the same time so that it goes into bootloader mode to flash the firmware.
It will open a new window on your computer as a new USB device, you can ignore and close that window.
Open Thonny IDE.
Go to Tools > Options. Select the Interpreter tab on the new window that opens.
Select MicroPython (Raspberry Pi Pico) for the interpreter, and the Try to detect port automatically for the Port. Then, click on Install or update MicroPython.
The following window will open.
Select the MicroPython variant accordingly to the board you’re using. In our case, we’re using the Pico W. Select a different option if you’re using the Pico.
Finally, click Install.
After a few seconds, the installation should be completed.
You can close the window. You should get the following message on the Shell, and at the bottom right corner, it should have the Interpreter it’s using and the COM port.
If it doesn’t recognize the device, and you have a message saying “no backend” on the bottom-right corner, it may be the case that it is not detecting the COM port automatically. If that’s the case, go to Tools > Options > Interpreter and select the COM port manually. After that, it should recognize the MicroPython device, and you should get the previous message.
Testing the Installation
Type help() in the Shell and see if your device responds back.
It should print some useful information about programming the Raspberry Pi Pico board using MicroPython.
Type the following:
It should print Hello on the Shell.
If you’ve followed until this step, you should have Thonny IDE successfully installed, as well as MicroPython firmware on your Raspberry Pi Pico board.
Running Your First Script
To get you familiar with the process of writing a file and executing code on the Raspberry Pi Pico board, we’ll upload a new script that simply blinks the on-board LED.
Blinking an LED Script
When you open Thonny IDE for the first time, the Editor shows an untitled file. Copy one of the following scripts to that file:
Raspberry Pi Pico
from machine import Pin
from time import sleep
led = Pin(25, Pin.OUT)
Raspberry Pi Pico W
from machine import Pin
from time import sleep
led = Pin('LED', Pin.OUT)
Running the Script
To run that script on your board, simply click on the Run icon on Thonny IDE.
The onboard LED will start blinking.
To stop the execution of the program you can hit the STOP button or simply press CTRL+C.
Important note: just running the file with Thonny doesn’t copy it permanently to the board’s filesystem. This means that if you unplug it from your computer and apply power to the board, nothing will happen because it doesn’t have any Python file saved on its filesystem. The Thonny IDE Run function is useful to test the code, but if you want to upload it permanently to your board, you need to create and save a file to the board filesystem. See the next section.
Saving the Script to the Raspberry Pi Pico Board
Stop the execution of the previous program by clicking on the Stop button if you haven’t already.
With the code copied to the file, click on the Save icon. Then, select Raspberry Pi Pico.
Save the file with the following name: main.py.
Note: When you name a file main.py, the Raspberry Pi Pico will run that file automatically on boot. If you call it a different name, it will still be saved on the board filesystem, but it will not run automatically on boot.
Finally, click OK to proceed.
Now, you can remove and apply power again to the board, or you can even power it using a different power supply that is not your computer. You’ll notice that the board will automatically start blinking the LED when it starts.
This tutorial was a quick introduction to the Raspberry Pi Pico board. The Raspberry Pi Pico is a cheap microcontroller board developed by the Raspberry Pi Foundation.
The board can be programmed using C/C++ programming language (using Arduino IDE) or MicroPython. The most popular method to program this board is using MicroPython firmware. In this tutorial, you learned how to run your first MicroPython script on the board and how to save it as a file.
If you also want to learn how to program the Raspberry Pi Pico using Arduino IDE, read the following tutorial:
You can check all our Raspberry Pi Pico projects and tutorials on the following link:
Thanks for reading