Getting Started with Raspberry Pi Pico (and Pico W)

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.

Getting Started with Raspberry Pi Pico and Raspberry Pi Pico W

You may also like: Learn Raspberry Pi Pico with MicroPython (eBook)

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.

Raspberry Pi Pico W board

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)
Raspberry Pi Pico Family
Raspberry Pi Pico, Pico H, Pico W, Pico WH (Image source)

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

Raspberry Pi Pico Processor 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.

Raspberry Pi Pico Pinout
Image source: raspberrypi.com
Raspberry Pi Pico W pinout

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 Logo

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.

Download Thonny IDE

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.

Raspberry Pi Pico Bootloader Mode

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.

Thonny IDE Tools Options

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.

Thonny IDE Select Interpreter

The following window will open.

Install MicroPython Raspberry Pi Pico Thonny IDE

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.

Installing MicroPython Raspberry Pi Pico Thonny IDE

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.

running executing MicroPython Raspberry Pi Pico Thonny IDE

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.

Raspberry Pi Pico Thonny IDE MicroPython help

It should print some useful information about programming the Raspberry Pi Pico board using MicroPython.

Type the following:

print('Hello')

It should print Hello on the Shell.

Thonny IDE Testing 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)
while True:
  led.value(not led.value())
  sleep(0.5)

Raspberry Pi Pico W

from machine import Pin
from time import sleep
led = Pin('LED', Pin.OUT)
while True:
  led.value(not led.value())
  sleep(0.5)

Running the Script

To run that script on your board, simply click on the Run icon on Thonny IDE.

Thonny IDE Run File

The onboard LED will start blinking.

To stop the execution of the program you can hit the STOP button or simply press CTRL+C.

Thonny IDE Stop button

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.

Thonny IDE Save File to 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.

Raspberry Pi Pico W onboard LED on

Wrapping Up

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’re serious about learning about the Raspberry Pi Pico, make sure you check our eBook:

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:

Most MicroPython scripts for the ESP32 and ESP8266 boards should also be compatible with the Raspberry Pi Pico with a few modifications on the pin definition.

You may also like:

Thanks for reading



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

18 thoughts on “Getting Started with Raspberry Pi Pico (and Pico W)”

  1. Hi Rui & Sarah,
    Thank you for your tutorial on RasPi Pico W. I recently purchased some of these, including some of the hats for them, with the intent of learning about them. Your tutorial is right on time and gives me a great starting point.
    Best regards,
    Joe

    Reply
  2. Problem with this processor is that : a non-script program written in C++ (PlatformIO) will not restart on a power failure. Only scripts written with a ‘.com’ will.
    This Processor is of no real use except for a learning tool, real life processors must reboot in case of a power failure.
    Purchased (10) what a waste of money, looked so good on paper but nothing like the ESP32 or ESP8266/85 this is the same as a ESP32-S2

    Reply
  3. I had a problem with updating micropython – the error message was “urllib.error.URLError: ” and after a lot of searching(thanks Stack Overflow and github/thonny), found the Thonny does not recognize LetsEncrypt as a certificate issuer. To get around this bug, i downloaded and ran https://letsencrypt.org/certs/lets-encrypt-r3.der. After installing this certificate, everything worked fine.
    This is not a new bug, it seems to have been a problem since about 2018.
    Thanks for the tutorial.
    Dan

    Reply
    • Hi.
      What do you mean?
      In what stage did you get the error?
      Can you better explain that issue? I never faced that problem before.
      Regards,
      Sara

      Reply
      • Sara,
        This error occurred in installing the update to micropython. As I mentioned, it was fixed by installing a certificate.
        Dan

        Reply
  4. A very simple Web Server in C/C++ would be great! There is a Python example, but I’m having to work in C – a level below Python :-(. Doesnt have to be asynch

    Reply
  5. Can anyone help me please?
    I am trying to get Thonny to detect my pico W. I follow the instructions above and in Thonny I select Tools > Options > Interpreter and open the list, but “Micropython (Raspberry Pi Pico)” is not in the list. Can anyone suggest what is wrong?

    Reply
    • Did you flash micropython firmware?
      You need to put the board into flashing mode. Connect it to your computer while holding down the BOTSEL button.
      Regards,
      Sara

      Reply
      • Thanks Sara but I’ve tried that.
        I’ve now installed the latest version of Thonny and set the interpreter to raspberry pi pico but it still cannot detect the pico when I plug it in, either with or without BOTSEL pressed.

        Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.