Download Print this page

Raspberry Pi Pico Series Getting Started

C/c++ development
Hide thumbs Also See for Pico Series:

Advertisement

Quick Links

Advertisement

loading
Need help?

Need help?

Do you have a question about the Pico Series and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for Raspberry Pi Pico Series

  • Page 2: Colophon

    (“High Risk Activities”). RPL specifically disclaims any express or implied warranty of fitness for High Risk Activities and accepts no liability for use or inclusions of Raspberry Pi products in High Risk Activities.
  • Page 3: Table Of Contents

      3. Install the Raspberry Pi Pico VS Code Extension ............
  • Page 4 Getting started with Raspberry Pi Pico-series Debugging your project ................
  • Page 5: Chapter 1. Introduction

    Raspberry Pi microcontroller-based board. Pico-series devices are built around microcontrollers designed by Raspberry Pi. Development on the boards is fully supported with both a C/C++ SDK, and an official MicroPython port. This book talks about how to get started with the SDK, and walks you through how to build, install, and work with the SDK toolchain.
  • Page 6: Chapter 2. Install Visual Studio Code

    Getting started with Raspberry Pi Pico-series Chapter 2. Install Visual Studio Code Visual Studio Code (VS Code) is a popular open source editor developed by Microsoft. The Raspberry Pi Pico VS Code Extension makes it easy to install dependencies and build software for Pico-series devices.
  • Page 7: Chapter 3. Install The Raspberry Pi Pico Vs Code Extension

    Chapter 3. Install the Raspberry Pi Pico VS Code Extension The Raspberry Pi Pico VS Code extension helps you create, develop, run, and debug projects in Visual Studio Code. It includes a project generator with many templating options, automatic toolchain management, one click project compilation, and offline documentation of the Pico SDK.
  • Page 8: Install The Extension

    Getting started with Raspberry Pi Pico-series 3.2. Install the Extension You can find the extension in the VS Code Extensions Marketplace. Search for the Raspberry Pi Pico extension, published by Raspberry Pi. Click the Install button to add it to VS Code.
  • Page 9: Chapter 4. Load A Project

    The Raspberry Pi Pico extension adds some capabilities to the status bar at the bottom right of the screen. Compile Compiles the sources and builds the target UF2 file. You can copy this binary onto your device to program it.
  • Page 10: Compile And Run Blink

    Getting started with Raspberry Pi Pico-series The extension sidebar also contains some quick access functions. Click on the Pico icon in the side menu and you’ll see Compile Project. Hit Compile Project and a terminal tab will open at the bottom of the screen displaying the compilation progress.
  • Page 11: Debug

    4.3. Debug The Raspberry Pi Debug Probe is a debug solution for any Arm-based computer. You can use other debug hardware with Pico-series devices, but we recommend the Debug Probe to make configuration as simple as possible. If you’d like...
  • Page 12 Getting started with Raspberry Pi Pico-series function, and run until that breakpoint is hit. Figure 4. Debugging in VS Code. Once in debugging mode, the sidebar has a number of windows displaying useful information about the current state of the device. At the top, a small control bar contains buttons that control code execution. Hover over the buttons to identify them.
  • Page 13 Getting started with Raspberry Pi Pico-series Figure 5. Debugging in VS Code. You can add and remove a breakpoint by clicking on the red dot. Press Run (F5); execution should halt on the breakpoint. Next, press Step-over (F10) and you should see the LED light...
  • Page 14: Chapter 5. Say "Hello World" In C

    Getting started with Raspberry Pi Pico-series Chapter 5. Say "Hello World" in C After blinking an LED on and off, the next thing that most developers will want to do is create and use a serial port, and say "Hello World."...
  • Page 15: Create A Project

    VSCode extension 1. In the VSCode left sidebar, select the Raspberry Pi Pico icon, labelled "Raspberry Pi Pico Project". 2. Select New Project. 3. In the Name field, name your project. For example "hello_world".
  • Page 16: Build Your Project

    Getting started with Raspberry Pi Pico-series automatically generated the .vscode directory for you. Select yes. 5.3. Build your project To run the "Hello world" example: 1. Hold down the BOOTSEL button on your Pico-series device while plugging it into your development device using a micro USB cable to force it into USB Mass Storage Mode.
  • Page 17: Appendix A: Debugprobe

    Getting started with Raspberry Pi Pico-series Appendix A: Debugprobe Raspberry Pi provides two ways to debug Pico-series devices: • Raspberry Pi Debug Probe • debugprobe firmware running on a second Pico or Pico 2 Both methods provide a way to debug Pico-series devices on platforms that lack GPIOs to connect directly to UART or SWD, such as Windows, macOS, and Linux.
  • Page 18: Debug Probe

    Getting started with Raspberry Pi Pico-series To run OpenOCD, use the openocd command in your terminal. Debug Probe The simplest way to debug a Pico-series device is the Raspberry Pi Debug Probe. The Raspberry Pi Debug Probe provides Serial Wire Debug (SWD), and a generic USB-to-Serial bridge.
  • Page 19: Debug With A Second Pico Or Pico 2

    Getting started with Raspberry Pi Pico-series Figure 9. Wiring between the Debug Probe (left) and Pico (right). To connect Debug Probe to Pico H, connect the following: • Debug Probe "D" port to Pico H "DEBUG" SWD JST-SH connector •...
  • Page 20: Install Debugprobe

    Getting started with Raspberry Pi Pico-series Figure 10. Wiring between Pico A (left) and Pico B (right) with Pico A acting as a debugger and Pico B as a system under test. You must connect at least the ground and the two SWD wires.
  • Page 21: Debug Probe Interfaces

    Pico B’s UART serial port through Pico A’s USB connection. You can also use the UART wires to talk to any other UART serial device, such as the boot console on a Raspberry Pi. To power Pico A with Pico B, connect the following pins: •...
  • Page 22: Windows

    Getting started with Raspberry Pi Pico-series $ sudo minicom /dev/ttyACM0 115200 Windows Download and install PuTTY. Open Device Manager and locate the COM port number of the device running debugprobe . In this example it is COM7 Open PuTTY. Select Serial under connection type.
  • Page 23: Macos

    Getting started with Raspberry Pi Pico-series Select Open to start the serial console. You are now ready to run your application. macOS First, install minicom using Homebrew: $ brew install minicom Then, run the following command to use the UART connection:...
  • Page 24: Debug With Openocd

    Getting started with Raspberry Pi Pico-series $ minicom /dev/tty.usbmodem1234561 115200 Debug with OpenOCD With Debug Probe, you can load binaries via the SWD port and OpenOCD. First, build a binary. Then, run the following command to upload the binary to the Pico, replacing blink.elf...
  • Page 25 Getting started with Raspberry Pi Pico-series $ gdb blink.elf > target remote localhost:3333 > monitor reset init > continue GDB doesn’t work on all platforms. Use one of the following alternatives instead of , depending on your operating system and device: •...
  • Page 26: Appendix B: Picotool

    Getting started with Raspberry Pi Pico-series Appendix B: Picotool It is possible to embed information into a Pico-series binary, which can be retrieved using a command line utility called picotool Getting picotool picotool utility is available in its own repository. You will need to clone and build it if you haven’t ran the pico-setup script.
  • Page 27: Using Picotool

    Getting started with Raspberry Pi Pico-series  NOTE If you are building on Microsoft Windows you should invoke CMake as follows, C:\Users\pico\picotool> mkdir build C:\Users\pico\picotool> cd build C:\Users\pico\picotool\build> cmake .. -G "NMake Makefiles" C:\Users\pico\picotool\build> nmake Using picotool picotool binary includes a command-line help function,...
  • Page 28: Display Information

    The information can be either read from one or more connected Raspberry Pi microcontrollers in BOOTSEL mode, or from a file. This file can be an ELF, a UF2 or a BIN file.
  • Page 29 Getting started with Raspberry Pi Pico-series   Include all information TARGET SELECTION:   To target one or more connected RP2040 device(s) in BOOTSEL mode (the default)   --bus <bus>   Filter devices by USB bus number   --address <addr>  ...
  • Page 30: Save The Program

    Getting started with Raspberry Pi Pico-series $ sudo picotool info -bp Program Information  name: hello_world  features: stdout to UART Fixed Pin Information  20: UART1 TX  21: UART1 RX The tool can also be used on binaries still on your local filesystem, $ picotool info -a lcd_1602_i2c.uf2...
  • Page 31: Binary Information

    Getting started with Raspberry Pi Pico-series   Filter devices by USB bus number   --address <addr>   Filter devices by USB device address   -f, --force   Force a device not in BOOTSEL mode but running compatible code to reset so the  ...
  • Page 32: Pins

    Getting started with Raspberry Pi Pico-series • build attributes, this is a similar list of strings, for things pertaining to the binary itself (e.g. Debug Build) Pins This is certainly handy when you have an executable called hello_serial.elf but you forgot what Raspberry Pi microcontroller-based board it was built for, as different boards may have different pins broken out.
  • Page 33: Appendix C: Manual Toolchain Setup

    Configure your environment via Script If you are developing for a Pico-series device on the Raspberry Pi 5, the Raspberry Pi 4B, or the Raspberry Pi 400, most of the installation steps in this Getting Started guide can be skipped by running the pico_setup.sh...
  • Page 34: Manually Configure Your

    Getting started with Raspberry Pi Pico-series $ sudo reboot Once your Raspberry Pi has rebooted, you can open Visual Studio Code in the "Programming" menu and follow the instructions from Chapter Manually Configure your Environment Get the SDK and examples Pico Examples repository provides a set of example applications written using the SDK.
  • Page 35: Update The Sdk

    Raspberry Pi. Exit raspi-config with Esc. Choose "Yes" and reboot your Raspberry Pi to enable the serial port.  IMPORTANT Raspberry Pi 5 makes the UART on the 3-pin debug header the default for serial0 . To use use GPIO pins 15 and 14...
  • Page 36: Use The Cli To Blink An Led In C

    Learning how to blink an LED gets you half way to anywhere. So let’s blink the LED on a Pico-series device. This code shown here for the Raspberry Pi Pico and Pico 2 blinks the LED connected to pin 25 of the device. Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/blink_simple/blink_simple.c...
  • Page 37: Load And Run "Blink

    Getting started with Raspberry Pi Pico-series -- Build files have been written to: /home/pi/pico/pico-examples/build  IMPORTANT The SDK builds binaries for the Raspberry Pi Pico 2 by default. To build a binary for a different board, pass the -DPICO_BOARD=<board> option to CMake, replacing the <board>...
  • Page 38: Using The Command Line

    Getting started with Raspberry Pi Pico-series Figure 13. Blinking the on-board LED on the Raspberry Pi Pico 2. Arrows point to the on- board LED, and the BOOTSEL button. Using the command line  You can use picotool to load a UF2 binary onto your Pico-series device, see...
  • Page 39: Manually Create Your Own Project

    Removing power from the board does not remove the code. When you restore power to the board, the flashed code will run again. Aside: Other Boards If you are not following these instructions on a Raspberry Pi Pico-series device, you may not have a BOOTSEL button (as...
  • Page 40 Getting started with Raspberry Pi Pico-series while (1) { gpio_put(LED_PIN, 0); sleep_ms(250); gpio_put(LED_PIN, 1); puts("Hello World\n"); sleep_ms(1000); 24 } ① ② The onboard LED is connected to GP25 on Pico and Pico 2, if These lines will add strings to the binary visible using you’re building for Pico W the LED is connected to...
  • Page 41: Debugging Your Project

    $ cmake .. $ make  IMPORTANT The SDK builds binaries for the Raspberry Pi Pico by default. To build a binary for a different board, pass the -DPICO_BOARD=<board> option to CMake, replacing the <board> placeholder with the name of the board you’d like to target.
  • Page 42 Getting started with Raspberry Pi Pico-series deeper into how your project is actually built, and how the lines in our CMakeLists.txt files here relate to the structure of the SDK, if you find yourself wanting to know more at some future point.
  • Page 43: Appendix D: Use Other Integrated Development Environments

    Eclipse is a multiplatform Integrated Development environment (IDE) available for Linux, macOS, and Windows. The latest version works well on the Raspberry Pi 4, 400, and 5 (4GB and up) running a 64-bit OS. The following instructions describe how to set up Eclipse on a Linux device for to develop on Pico-series devices. Instructions for other systems will be broadly similar, although the details of connecting to Pico-series devices vary.
  • Page 44 2-wire debug connections from the host device to the microcontroller prior to running the code. On a Raspberry Pi, this can be done via GPIO connections, but on a laptop or desktop device, you need to use extra hardware for this connection.
  • Page 45: Creating A Run Configuration

    Getting started with Raspberry Pi Pico-series Figure 14. Setting the OCD executable name and path in Eclipse. Creating a Run configuration In order to run or debug code in Eclipse you need to set up a Run Configuration. This sets up all the information needed to identify the code to run, any parameters, the debugger, source paths and SVD information.
  • Page 46 Eclipse. Setting up the debugger Let’s set up OpenOCD to talk to the Raspberry Pi microcontroller. openocd in the boxes labelled Executable and Actual Executable. We also need to set up OpenOCD to use the Pico specific configuration, so in the Config options sections add the following.
  • Page 47 Getting started with Raspberry Pi Pico-series Figure 17. Setting up the Debugger and OpenOCD in Eclipse. Setting up the SVD plugin SVD provides a mechanism to view and set peripheral registers on the Pico board. An SVD file provides register locations and descriptions, and the SVD plugin for Eclipse integrates that functionality in to the Eclipse IDE.
  • Page 48: Use Clion

    Mac. This is a commercial IDE often the choice of professional developers (or those who love JetBrains IDEs) although there are free or reduce price licenses available. It will run on a Raspberry Pi, however the performance is not ideal, so it is expected you would be using CLion on your desktop or laptop.
  • Page 49 Getting started with Raspberry Pi Pico-series Figure 20. A newly opened CLion pico- examples project. Notice at the bottom that CLion attempted to load the CMake project, but there was an error; namely that we hadn’t specified PICO_SDK_PATH Configuring CMake Profiles Select Settings…...
  • Page 50 Getting started with Raspberry Pi Pico-series  IMPORTANT The SDK builds binaries for the Raspberry Pi Pico by default. To build a binary for a different board, pass the -DPICO_BOARD=<board> option to CMake, replacing the <board> placeholder with the name of the board you’d like to target.
  • Page 51 (see Figure 25). In this case this is the cmake-build-debug directory. The UF2 file can be copied onto a Raspberry Pi microcontroller in BOOTSEL mode, or the ELF can be used for debugging. Figure 25. Locating hello_usb build...
  • Page 52: Other Environments

    Getting started with Raspberry Pi Pico-series Other Environments There are too development environments available to describe all of them here. You can use many of them with the SDK. In general, IDEs require the following features to support Pico-series devices: •...
  • Page 53: Appendix H: Documentation Release History

    Getting started with Raspberry Pi Pico-series Appendix H: Documentation Release History August 8 2024 Initial release. August 8 2024...

This manual is also suitable for:

Pico 2