Getting Started with Raspberry Pi Pico : RP2040 Microcontroller Board – Pinout, Schematic and Programming Tutorial

Learn how to set up the Raspberry Pi Pico board on your computer and write and compile programs with C/C++ SDK and Arduino IDE.
Getting-Started-with-Raspberry-Pi-Pico-Pinout-Schematic-and-Programming-Tutorial-CIRCUITSTATE-Featured-Image-01-2
Getting started with Raspberry Pi Pico

Raspberry Pi Pico is a development board based on the RP2040 microcontroller from the Raspberry Pi Foundation. RP2040 is the very first microcontroller designed by RPi. It is a dual-core ARM Cortex-M0+ processor with 264KB on-chip SRAM and supports up to 16MB of off-chip Flash memory for program storage. The microcontroller runs at 133 MHz and comes in a single QFN-56, 7×7 mm package. The best things about RP2040 are its extensive set of GPIO pins, internal peripherals, SRAM size, core count, clock speed, and price. The RP2040 costs just $1 or Rs.80 in India. Pico is a small minimal development board that combines everything needed to get an RP2040 working. After almost a year and half of release, RPi recently announced a new version of Pico with Wi-Fi and Bluetooth features. The new board is called Pico W (along with a WH version with soldered headers). Another model similar to Pico is the Pico H which has a connector for the SWD interface and does not have the castellated holes.

In this post, we will show you everything you need to know about Pico boards, from setting it up to running your first sketch on it. We will be using the Pico H board on a Windows 11 computer.

Things You Need

  1. Any Raspberry Pi Pico board. We are using Pico H.
  2. A micro USB cable.
  3. Windows 10/11 computer.
  4. Internet connection.

Where To Buy?

Raspberry-Pi-Pico-and-H-RP2040-Microcontroller-Board-Top-View-CIRCUITSTATE-Electronics-01
Raspberry Pi Pico with header and without one

You can buy Raspberry Pi Pico boards from any of the official vendors in your country. If you are in India we suggest the following sellers. You can also purchase a micro USB cable from the stores.

  1. Robu.in
  2. Silverline Electronics
  3. Robocraze

What is RP2040?

Raspberry-Pi-Pico-RP2040-Microcontroller-Chip-CIRCUITSTATE-Electronics-01
RP2040-B2

RP2040 is an ARM Cortex-M0+ microcontroller. It is a dual-core microcontroller. That means you have two separate processors inside the package that can execute your code parallelly. It’s like having two microcontrollers for the price of one. Both cores run at 133 MHz and they could be even overclocked! Cortex-M0+ is a series of ARM microcontrollers that are optimized for power consumption. Like all ARM Cortex microcontrollers, RP2040 also has a 32-bit core, which means it can execute complex 32-bit instructions at a time. It is also a RISC processor which can execute a single instruction in just 1 clock cycle.

Let’s see a comparison between RP2040 and the popular ATmega328P, which is used on the Arduino Uno. Only a few features are compared.

PropertyRP2040ATmega328P
Core TypeARM Cortex-M0+8-bit AVR
Instruction TypeRISCRISC
Instruction Size32-bit8-bit
Core Count21
Maximum Clockspeed133 MHz20 MHz
SRAM264 KB2 KB
Flash Size16 MB32 KB
GPIO Count3023
ADC Resolution12 bit10 bit
PWMAll GPIO pinsLimited GPIO pins
InterruptAll GPIO pins2 GPIO pins
UART21
SPI21
I2C21
USBYesNo
Price$1$2.7
Working Voltage1.8 to 3.3V1.8 to 5.5V
Comparison between RP2040 and ATmega328P

There are more differences between the two and features that make the RP2040 a really good choice for your projects and products. RP2040 was designed by Raspberry Pi’s own engineers and uses a 40 nm node for fabrication. It is available in a 56-pin QFN package with 7×7 mm size. This is probably the only caveat for using RP2040. It can be a little difficult to hand-solder it.

Specifications

  • Dual ARM Cortex-M0+ @ 133MHz
    • On-chip PLL allows variable core frequency
  • 264kByte high-performance SRAM in six independent banks
  • Support for up to 16MB of off-chip Flash memory via dedicated QSPI bus with eXecute In Place (XIP)
  • DMA controller
  • Fully-connected AHB crossbar
  • Interpolator and integer divider peripherals
  • On-chip programmable LDO to generate the core voltage
  • 2 on-chip PLLs to generate USB and core clocks
  • 30 multi-function General Purpose IO (4 can be used for ADC)
    • 1.8-3.3V IO Voltage (NOTE: Pico IO voltage is fixed at 3.3V)
  • 12-bit 500ksps Analogue to Digital Converter (ADC)
  • Peripherals
    • 2 UARTs
    • 2 SPI controllers
    • 2 I2C controllers
    • 16 PWM channels
    • USB 1.1 controller and PHY, with host and device support
    • 8 PIO state machines
  • 2 × Programmable IO (PIO) blocks, 8 state machines total
    • Flexible, user-programmable high-speed IO
    • Can emulate interfaces such as SD Card and VGA
  • QFN-56 7x7mm package

Block Diagram

Raspberry-Pi-RP2040-Microcontroller-Block-Diagram
RP2040 block diagram

As you can see, there is no flash memory embedded in the chip. We have to add an external Flash memory to store all the programs. A dedicated set of QSPI pins are provided for this so that you don’t need to spare any GPIOs for the purpose. There are dedicated pins for SWD (Serial Wire Debug), USB, and crystal oscillator.

Pinout

Raspberry-Pi-RP2040-Microcontroller-Pinout-Diagram-1_2
RP2040 pinout

Raspberry Pi Pico

The Pico is a minimal development board for RP2040. It integrates a 5V to 3.3V switching voltage regulator, flash memory (2 MB), USB connector, and a crystal oscillator. The board does not have a reset button or a dedicated USB-Serial driver. The board has castellated (edge-plated) holes so that you can solder the board directly on a carrier board. Otherwise, you can solder pin headers on the board and use it on a breadboard, for example. The Pico board costs around Rs.350 in India.

Raspberry-Pi-Pico-H-RP2040-Microcontroller-Board-Top-View-CIRCUITSTATE-Electronics-01
Raspberry Pi Pico H
Raspberry-Pi-Pico-H-RP2040-Microcontroller-Board-Bottom-View-CIRCUITSTATE-Electronics-01
It’s hard to read the pin labels. The pinout diagram is your friend.

Schematics

Raspberry-Pi-RP2040-Microcontroller-Pico-Board-Schematic-1
Raspberry Pi Pico schematic

Not all of the GPIO pins are broken out in Pico. Four of the GPIO pins are used for other purposes. So in case you want to use them, you will need to find a board that breaks them out or consider designing your own board.

  • GP29/ADC3 is used to measure VSYS.
  • GP25 is used by the debug LED.
  • GP24 is used for VBUS sense.
  • GP23 is connected to the SMPS Power Save pin.

Speaking of designing your own board, Raspberry Pi has provided two reference designs to get you started.

  1. Minimal Design Example [ZIP]
  2. The VGA, SD card & audio demo boards for Raspberry Pi Pico and Raspberry Pi Pico [ZIP]

Both designs are created with the help of KiCad, an open-source schematic and PCB design tool. You can download the above-given project files and directly open them in KiCad. For more information, check out the Hardware Design Guidelines file from Raspberry Pi.

Pinout

We have created a beautiful and intuitive pinout diagram for the Pico board.

The Arduino pins are based on the Arduino-Pico core by Earle F. Philhower, III. The pin assignments used by Mbed-based RP2040 core are different and it is also limited. With the Arduino-Pico core, you can have 3 serial ports in total (including one USB-CDC and two hardware UARTs), two SPI ports, and two I2C ports. Raspberry Pi Pico supports PWM and interrupts on all GPIO pins. There are 16 PWM channels and you can assign them to any GPIO pins. The only two disadvantages of the Pico board are the lack of a reset button and a dedicated USB-Serial driver. Due to that, you have to always disconnect the board from power to reset it, and without a dedicated USB-Serial driver, most serial monitor applications will get disconnected from the board when you reset it and you won’t be able to see any debug messages printed at the start of the connection.

Programming

There are multiple ways for building applications for RP2040 and flashing them to the microcontroller (more accurately the flash memory). There are official SDKs (Software Development Kit) available from Raspberry Pi; a C/C++ SDK and a Python SDK. In addition to that RP2040 is supported by the Arduino Development Framework (ADF). That means we can use the Pico board just like any other Arduino-supported board. In this tutorial, we will show you how you can use the official C/C++ SDK as well as ADF to develop software for the Raspberry Pi Pico.

Setting up C/C++ SDK

Setting up the development environment for the RP2040 C/C++ SDK is well documented in this PDF file – Getting started with Raspberry Pi Pico – from Raspberry Pi. For some reason, RPi is not providing web-based documentation and instead chooses to publish them as PDF files 🤥. So it is likely that the PDF files you download will get outdated when RPi publishes an updated version. So in case you ran into some issues, the first step will be to check if there is updated documentation from RPi. PDF documentation also makes it hard to find official information through web searches.

If you are on a Windows computer like us, go to Chapter 9 of the documentation and follow everything exactly as described. Basically, you have to download and install the following tools if you haven’t already, and make sure most of the binaries are available on the Path environment variable. The Path variables simply tell Windows where to find the executable files when they are invoked from a Terminal/Console application. You need to install,

Shawn Hymel has written an excellent walkthrough of the process here in his blog. But unlike the official documentation, Shawn makes use of the MinGW (Minimalist GNU for Windows) environment for building the elf2uf2  and pioasm tools. This has the advantage that you don’t need to use the NMake or the Microsoft Visual Studio tools to build your projects. The problem with using NMake is that you must always run it from the Developer Command Prompt window. If you do not run VS Code from the Developer Command Prompt, you will get the following error at the output window, and the build will fail.

[main] Building folder: pico-examples 
[main] Configuring folder: pico-examples 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files (x86)\Arm GNU Toolchain arm-none-eabi.2 2022.02\bin\arm-none-eabi-gcc.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files (x86)\Arm GNU Toolchain arm-none-eabi.2 2022.02\bin\arm-none-eabi-g++.exe" -Sc:/Pico/pico-examples -Bc:/Pico/pico-examples/build -G "NMake Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] Using PICO_SDK_PATH from environment ('C:\Pico\pico-sdk')
[cmake] PICO_SDK_PATH is C:/Pico/pico-sdk
[cmake] Defaulting PICO_PLATFORM to rp2040 since not specified.
[cmake] Defaulting PICO platform compiler to pico_arm_gcc since not specified.
[cmake] PICO compiler is pico_arm_gcc
[cmake] -- The C compiler identification is GNU 11.2.1
[cmake] -- The CXX compiler identification is GNU 11.2.1
[cmake] -- The ASM compiler identification is GNU
[cmake] -- Found assembler: C:/Program Files (x86)/Arm GNU Toolchain arm-none-eabi/11.2 2022.02/bin/arm-none-eabi-gcc.exe
[cmake] Build type is Debug
[cmake] Using regular optimized debug build (set PICO_DEOPTIMIZED_DEBUG=1 to de-optimize)
[cmake] Defaulting PICO target board to pico since not specified.
[cmake] Using board configuration from C:/Pico/pico-sdk/src/boards/include/boards/pico.h
[cmake] -- Found Python3: C:/Users/Vishnu Mohanan/AppData/Local/Programs/Python/Python39/python.exe (found version "3.9.6") found components: Interpreter 
[cmake] TinyUSB available at C:/Pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
[cmake] Compiling TinyUSB with CFG_TUSB_DEBUG=1
[cmake] cyw43-driver available at C:/Pico/pico-sdk/lib/cyw43-driver
[cmake] lwIP available at C:/Pico/pico-sdk/lib/lwip
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: C:/Pico/pico-examples/build
[cmakefileapi-driver] This version of CMake does not support the "toolchains" object kind. Compiler paths will be determined by reading CMakeCache.txt.
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Pico/pico-examples/build --config Debug --target hello_usb -j 18 --
[build] Warning: NMake does not support parallel builds. Ignoring parallel build command line option.
[build] The system cannot find the file specified
[build] CMake Error: Generator: execution of make failed. Make command was: nmake /nologo hello_usb && 
[build] Build finished with exit code 1
MinGW-Makefiles-for-CMake-VS-Code-Extension-Settings-Raspberry-Pi-Pico-CIRCUITSTATE-Electronics-01
Use MinGW Makefiles

The solution is to simply install MinGW as described by Shawn and add MinGW Makefiles as the value of Cmake:Generator property for the CMake extension in VS Code. If everything is done right, you will get a VS Code window like the below. We are compiling the hello_world example for USB.

Compiling-Raspberry-Pi-Pico-Examples-in-VS-Code-with-C-C++-SDK-for-RP2040-CIRCUITSTATE-Electronics-01
VS code window with the hello_usb.c program opened

Note that our build target is only hello_usb. That means only the hello_usb.c program will be compiled. By default, the build process will build all example programs which can take some time. Simply change the [all] value to the program you want to compile from the dropdown list.

Selecting-Default-Build-Target-Raspberry-Pi-Pico-Examples-in-VS-Code-with-C-C++-SDK-for-RP2040-CIRCUITSTATE-Electronics-01
Select the default build target

When you click the Build button on the bottom bar, you get a similar output at the terminal as below.

[main] Building folder: pico-examples 
[main] Configuring folder: pico-examples 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files (x86)\Arm GNU Toolchain arm-none-eabi.2 2022.02\bin\arm-none-eabi-gcc.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files (x86)\Arm GNU Toolchain arm-none-eabi.2 2022.02\bin\arm-none-eabi-g++.exe" -Sc:/Pico/pico-examples -Bc:/Pico/pico-examples/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] PICO_SDK_PATH is C:/Pico/pico-sdk
[cmake] PICO platform is rp2040.
[cmake] Build type is Debug
[cmake] Using regular optimized debug build (set PICO_DEOPTIMIZED_DEBUG=1 to de-optimize)
[cmake] PICO target board is pico.
[cmake] Using board configuration from C:/Pico/pico-sdk/src/boards/include/boards/pico.h
[cmake] TinyUSB available at C:/Pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
[cmake] Compiling TinyUSB with CFG_TUSB_DEBUG=1
[cmake] cyw43-driver available at C:/Pico/pico-sdk/lib/cyw43-driver
[cmake] lwIP available at C:/Pico/pico-sdk/lib/lwip
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: C:/Pico/pico-examples/build
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Pico/pico-examples/build --config Debug --target hello_usb -j 18 --
[build] [  0%] Performing build step for 'ELF2UF2Build'
[build] [  0%] Built target bs2_default
[build] [  0%] Built target bs2_default_padded_checksummed_asm
[build] [100%] Built target elf2uf2
[build] [  0%] No install step for 'ELF2UF2Build'
[build] [  0%] Completed 'ELF2UF2Build'
[build] [  0%] Built target ELF2UF2Build
[build] [100%] Built target hello_usb
[build] Build finished with exit code 0

Build finished with exit code 0 means a successful compilation.

Drag and Drop Programming

Once you compile a program, a set of binary files will be created in the build folder of the respective program. These files include elf, bin, hex, and uf2 files. The UF2 file can be used for drag and drop programming. To do this, connect your Pico board to the computer while simultaneously pressing and holding the BOOT button on your Pico. This will activate the mass storage mode and the Pico will be available as a drive on your My Computer window. There will be two files within it; an HTML shortcut and a UF2 information file that says,

UF2 Bootloader v3.0
Model: Raspberry Pi RP2
Board-ID: RPI-RP2

Now simply drag and drop the hello_usb.uf2 file to the RPI-RP2 drive. The file will be flashed to the Flash memory and Pico will be disconnected. The mass storage drive will now disappear. A COM port will now appear on your system. You can use any serial monitor application to read the “Hello World!” message from Pico. We are using the Arduino serial monitor.

Arduino-Serial-Monitor-Raspberry-Pi-Pico-Drag-and-Drop-Programming-Hello-World-CIRCUITSTATE-Electronics-01
Hello World from Raspberry Pi Pico

Setting up Arduino IDE

If setting up SDKs and using command-line tools is not your way of doing things, then you can easily write, compile and upload your applications to the Pico board with the help of your favorite Arduino IDE. There are two cores available for the RP2040 in Arduino; an Mbed OS-based core and a C/C++ SDK-based core. The Mbed OS core is the official core supported by Arduino and is also used for boards like Arduino Nano RP2040 Connect. A tutorial can be found here for installing the Mbed OS core on Arduino IDE.

Raspberry-Pi-Pico-Arduino-Mbed-OS-Package-Board-Manager-CIRCUITSTATE-Electronics-01
Select Raspberry Pico from Arduino Mbed OS RP2040 Boards

The first time you connect your Pico board to the computer, you will not see a COM port associated with it. This is because the Pico is still not ready to enumerate its USB port as a serial port. You need to modify the bootloader section of the RP2040 and enable the USB-CDC port. We have a complete tutorial showing how you can use Arduino IDE to enable the USB-CDC and upload your programs effortlessly.

How to Program Raspberry Pi Pico with Arduino IDE – Steps for Installation and Uploading Example Sketches

How to Program Raspberry Pi Pico with Arduino IDE – Steps for Installation and Uploading Example Sketches

Vishnu MohananAug 31, 202110 min read
Tutorial on installing RP2040 Mbed OS packages through Arduino IDE, compiling and uploading sketches to Raspberry Pi Pico microcontroller board.

To use the Arduino-Pico core, you should first add the boards URL to the Arduino IDE. Open the Preferences and add the following URL to the list.

https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

Then open the Boards Manager and search for “pico”. From the list, install the Raspberry Pi Pico/RP2040 item.

Add-Boards-Manager-URL-Arduino-Pico-RP2040-Core-CIRCUITSTATE-Electronics-01
Add the boards URL
Install-Arduino-Pico-RP2040-Core-in-Arduino-IDE-CIRCUITSTATE-Electronics-01
Install the Raspberry Pi Pico/RP2040
Choose-Raspberry-Pi-Pico-from-Boards-List-Arduino-Pico-RP2040-Core-CIRCUITSTATE-Electronics-01
Select Raspberry Pi Pico

After the installation is complete, go to Tools → Board → Raspberry Pi RP2040 Boards (2.2.2) and choose Raspberry Pi Pico from the list. If you have connected a fresh Pico board, the COM would not have been generated yet. But that’s okay. The Arduino-Pico core can automatically detect the Pico board and modify the bootloader. You don’t need to press any buttons. Simply open an example sketch and click the Upload button.

The Arduino-Pico core flashes the binary file by making the Pico board a mass storage device for a short duration, and prints the following lines to the console.

Sketch uses 50308 bytes (2%) of program storage space. Maximum is 2093056 bytes.
Global variables use 7236 bytes (2%) of dynamic memory, leaving 254908 bytes for local variables. Maximum is 262144 bytes.
C:\Users\Vishnu Mohanan\AppData\Local\Arduino15\packages\rp2040\tools\pqt-python3.0.1-base-3a57aed/python3 -I C:\Users\Vishnu Mohanan\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040.2.2/tools/uf2conv.py --serial COM9 --family RP2040 --deploy C:\Users\VISHNU~1\AppData\Local\Temp\arduino_build_273735/Blink.ino.uf2 
Resetting COM9
Converting to uf2, output size: 107008, start address: 0x2000
Flashing G: (RPI-RP2)
Wrote 107008 bytes to G:/NEW.UF2

The COM port will be disabled for a short duration but it will be back as soon as the flashing process is complete. Compared to the RP2040 Mbed OS core, the Arduino-Pico core has much more customization options available since it is using the official C/C++ SDK directly. For this reason, we suggest you use the Arduino-Pico core whenever possible. The code size will be also smaller when using the Arduino-Pico core.

In the upcoming posts, we will explore the features of the RP2040 microcontroller in detail. We will also show how you can create a standalone C/C++ project that uses the official SDK.

  1. RP2040 Datasheet [PDF]
  2. Raspberry Pi Pico Datasheet [PDF]
  3. Hardware Design with RP2040 [PDF]
  4. Getting started with Raspberry Pi Pico [PDF]
  5. Raspberry Pi Pico C/C++ SDK [PDF]
  6. Arduino-Pico Core for RP2040 Boards – GitHub
  7. How to Set Up Raspberry Pi Pico C/C++ Toolchain on Windows with VS Code – Shawn Hymel
  8. How to Program Raspberry Pi Pico with Arduino IDE – Steps for Installation and Uploading Example Sketches
  9. Raspberry Pi Pico High-Quality Pinout Diagram [PDF]
Share to your friends
Default image
Vishnu Mohanan

Founder and CEO at CIRCUITSTATE Electronics

Articles: 52

3 Comments

Leave a Reply

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

  1. Good article. I bought one Pico around 1 year ago. I didn’t started yet. I will try it with this tutorial.

    • That’s great. It is never too late to start. Please share your feedback after running your first program.