Pico Getting Started
Text tutorial
Introduction
Raspberry Pi Pico Basics
MicroPython series
Install Thonny IDE
In order to facilitate the development of Pico/Pico2 boards using MicroPython on a computer, it is recommended to download the Thonny IDE
- Download Thonny IDE and follow the steps to install, the installation packages are all Windows versions, please refer to Thonny's official website for other versions
- After installation, the language and motherboard environment need to be configured for the first use. Since we are using Pico/Pico2, we select the Raspberry Pi option for the motherboard environment
- Configure MicroPython environment and choose Pico/Pico2 port
- Connect Pico/Pico2 to your computer first, and in the lower right corner of Thonny left-click on the configuration environment option --> select Configture interpreter
- In the pop-up window, select MicroPython (Raspberry Pi Pico), and choose the corresponding port
- Click OK to return to the Thonny main interface, download the corresponding firmware library and burn it to the device, and then click the Stop button to display the current environment in the Shell window
- How to download the firmware library for Pico/Pico2 in windows: After holding down the BOOT button and connecting to the computer, release the BOOT button, a removable disk will appear on the computer, copy the firmware library into it
- How to download the firmware library for RP2040/RP2350 in windows: After connecting to the computer, press the BOOT key and the RESET key at the same time, release the RESET key first and then release the BOOT key, a removable disk will appear on the computer, copy the firmware library into it (you can also use the Pico/Pico2 method)
Details
C/C++ series
For C/C++, it is recommended to use Pico VS Code for development. This is a Microsoft Visual Studio Code extension designed to make it easier for you to create, develop, and debug projects for the Raspberry Pi Pico series development boards. No matter if you are a beginner or an experienced professional, this tool can assist you in developing Pico with confidence and ease. Here's how to install and use the extension.
- Official website tutorial: https://www.raspberrypi.com/news/pico-vscode-extension/
- This tutorial is applicable to Raspberry Pi Pico, Pico2 and the RP2040 and RP2350 series development boards developed by our company
- The default development environment is Windows. For other environments, please refer to the official website tutorial for installation
Install VSCode
- Firstly, click to download pico-vscode package, unzip and open the package, double-click to install VSCode
Note: If vscode is already installed, check if the version is v1.87.0 or higher
Install extension
- Click on EXTENSIONS, select Install from VSIX
- Select the package with vsix suffix, click Install
- Then vscode will automatically install Raspberry Pi Pico and its dependent extensions. You can click Refresh to view the installation progress
- The bottom right corner shows installation completed, close vscode
- Open the directory C:\Users\username and copy the entire .pico-sdk to that directory
- The copy is completed
- Open VSCode and configure various paths in the Raspberry Pi Pico extension
The configuration is as follows:Cmake Path:
${HOME}/.pico-sdk/cmake/v3.28.6/bin/cmake.exe
Git Path:
${HOME}/.pico-sdk/git/cmd/git.exe
Ninja Path:
${HOME}/.pico-sdk/ninja/v1.12.1/ninja.exe
Python3 Path:
${HOME}/.pico-sdk/python/3.12.1/python.exe
New project
- Configuration is completed, then create a new project. First enter the project name, select the path, and click Create to create the project
To test the official example, you can click Example next to the project name to select
- The project was created successfully
- Select SDK version
- Select Yes for advanced configuration
- Select the cross-compilation chain, 13.2.Rel1 is for ARM cores, RISCV.13.3 is for RISCV cores, and you can choose one of them according to your needs
- Selects Default (the path configured earlier) for CMake version
- Select Default for Ninja version
- Select development board
- Click Complie to compile
- The uf2 format file is successfully compiled
Import project
- The Cmake file for importing the project cannot have Chinese (including comments), otherwise it may cause import failure
- To import your own project, you need to add a line of code to the Cmake file to switch between pico and pico2 normally, otherwise even if pico2 is selected, the compiled firmware will still be suitable for pico
set(PICO_BOARD pico CACHE STRING "Board type")
Update extension
- The extension version in the offline package is 0.15.2, and you can also choose to update to the latest version after the installation is complete
Arduino IDE series
Install Arduino IDE
- First, go to Arduino official website to download the installation package of the Arduino IDE.
- Here, you just need to select to download.
- Once the download is complete, click Install.
Notice: During the installation process, it will prompt you to install the driver, just click Install
Arduino IDE interface
- After the first installation, when you open the Arduino IDE, it will be in English. You can switch to other languages in File --> Preferences, or continue using the English interface.
- In the Language field, select the language you want to switch to, and click OK.
Install Arduino-Pico Core in the Arduino IDE
- Open the Arduino IDE, click on the file in the top left corner, and select Preferences
- Add the following link to the attached board manager URL, and then click OK
https://github.com/earlephilhower/arduino-pico/releases/download/4.0.2/package_rp2040_index.json
Note: If you already have an ESP32 board URL, you can use a comma to separate the URLs as follows:
https://dl.espressif.com/dl/package_esp32_index.json,https://github.com/earlephilhower/arduino-pico/releases/download/4.0.2/package_rp2040_index.json
- Click Tools > Development Board > Board Manager > Search pico, as my computer has already been installed, it shows that it is installed
First upload of the program
- Press and hold the BOOTSET button on the Pico board, connect the pico to the USB port of the computer via the Micro USB cable, and release the button after the computer recognizes a removable hard disk (RPI-RP2).
- Download the program and open D1-LED.ino under the arduino\PWM\D1-LED path
- Click Tools --> Port, remember the existing COM, do not click this COM (the COM displayed is different on different computers, remember the COM on your own computer)
- Connect the power board to the computer using a USB cable. Then, go to Tools > Port. For the first connection, select uf2 Board. After uploading, when you connect again, an additional COM port will appear
- Click Tools > Development Board > Raspberry Pi Pico > Raspberry Pi Pico or Raspberry Pi Pico 2
- After setting it up, click the right arrow to upload the program
- If issues arise during this period, and if you need to reinstall or update the Arduino IDE version, it is necessary to uninstall the Arduino IDE completely. After uninstalling the software, you need to manually delete all contents within the C:\Users\[name]\AppData\Local\Arduino15 folder (you need to show hidden files to see this folder). Then, proceed with a fresh installation.
Open source demos
MircoPython video demo (github)
MicroPython firmware/Blink demos (C)
Raspberry Pi official C/C++ demo (github)
Raspberry Pi official micropython demo (github)
Arduino official C/C++ demo (github)
Demo
C/C++ Demo
01-LCD
- LCD refreshes an image and waits for 2.5 seconds
- LCD refreshes GUI demo
02-picoprobe
- This demo is based on the open-source program picoprobe
- The RP2350-GEEK runs the picoprobe demo, which will emulate a USB TO SWD and USB TO UART device
- Using the UART interface as a USB to serial tool, it can be used for device communication
- Using the SWD interface as a debugging tool, when used with openocd, it can debug most ARM chips
- For more information, please refer to the "PicoProbe Tutorial" below
03-FATFS
- The demo implements a command-line interface similar to busybox or DOS. It can mount a TF card, create and view files, and so on. The command “help” can be used to view all available commands
- Note that the TF card file format is FAT32
Micropython Demo
01-LCD
How to use
- Upload all py and bmp files under the file to the RP2350-GEEK via thonny upload
Running result
- LCD displays the GUI screen, waits for a few seconds, and then displays the bmp image
02-SD
How to use
- Upload all py files under the file to the RP2350-GEEK via thonny and reset
Running result
- After the RP2350-GEEK is reset, it will automatically mount the TF to the SD file according to the boot.py program
- Double-click to open the SD folder, and you can see the files stored in the TF card
PicoProbe Tutorial
Install OpenOCD
Linux (and Raspberry Pi)
Download the dependency library
sudo apt install automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev
Get and compile
git clone https://github.com/raspberrypi/openocd.git
cd openocd
./bootstrap
./configure
make -j4
sudo make install
Windows
- Because OpenOCD self-compilation is complicated in the Windows environment, it is recommended to use the compiled version
- Unzip and store in a shorter directory, such as directly in the C drive
Add environment variables
- Click on the Start menu and search for "Environment Variables"
- Click on "Edit the System Environment Variables"
- Double-click the "Path" variable to enter the editing interface
- Add a new path
- ①Create a new variable address
- ②Enter the address where the OpenOCD is stored
- ③Click OK to save
- Click "OK" to save your changes
- Restart the computer
Install GDB
Linux (and Raspberry Pi)
- Install gdb-multiarch
sudo apt install gdb-multiarch
Windows
- If you have the pico-sdk environment installed correctly, skip this step, as GDB is already included in the Arm GNU Toolchain
- If you do not have pico-sdk installed, it is recommended to use the official pico installer to install it
Use Raspberry Pi Debug Probe to flash the program
- Pico Debug Probe allows you to load binary files via the SWD port and OpenOCD
- Every time you push a new binary file to Pico, you do not need to unplug and then hold down the BOOTSEL button
- Using RP2350 as an example, the flashing command is
sudo openocd -f interface/cmsis-dap.cfg -f target/rp2350.cfg -c "adapter speed 5000" -c "program {your elf file name}.elf verify reset exit”
- If you have a file named blink.elf in your current folder
sudo openocd -f interface/cmsis-dap.cfg -f target/rp2350.cfg -c "adapter speed 5000" -c "program blink.elf verify reset exit"
Use Raspberry Pi Debug Probe to debug the program
Open the OpenOCD server
- You can use openocd in server mode and connect it to GDB, providing you with breakpoints and "correct" debugging
Use the GDB command line
- This demo is built based on the pico-sdk environment, and the pico-example is compiled
- Open PowerShell and go to the corresponding build folder, here the blink demo is used as an example
- Open GBD and enter the following command
- Enter the following commands in sequence
target remote localhost:3333
load
continue
After successful execution, you can see pico executing blink, the led flickers
Debug with VSCode (Advanced)
- Make sure that Open the OpenOCD server and Use the GDB command line are working properly
- Make sure that the Pico compilation environment is set up properly
- Make sure you have the following plugins installed on your VSCode
- Cortex-Debug
- Cmake-tools
- C/C++
- First open the OpenOCD server
- Open the pico-examples folder with VSC and start the blink demo
- Use the shortcut key F1 and enter the following command
open 'launch.json'
- Once opened, put the following in it
- If it is Windows, then enter
{
"version": "0.2.0",
"configurations": [
{
"name": "Pico Debug",
"type":"cortex-debug",
"cwd": "${workspaceRoot}",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"servertype": "external",
// This may need to be arm-none-eabi-gdb depending on your system
"gdbPath" : "gdb",
// Connect to an already running OpenOCD instance
"gdbTarget": "localhost:3333",
"svdFile": "${env:PICO_SDK_PATH}/src/rp2350/hardware_regs/rp2350.svd",
"runToMain": true,
// Work around for stopping at main on restart
"postRestartCommands": [
"break main",
"continue"
]
}
]
}
- If it is Linux, then enter
{
"version": "0.2.0",
"configurations": [
{
"name": "Pico Debug",
"type":"cortex-debug",
"cwd": "${workspaceRoot}",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"servertype": "external",
// This may need to be arm-none-eabi-gdb depending on your system
"gdbPath" : "arm-none-eabi-gdb",
// Connect to an already running OpenOCD instance
"gdbTarget": "localhost:3333",
"svdFile": "${env:PICO_SDK_PATH}/src/rp2350/hardware_regs/rp2350.svd",
"runToMain": true,
// Work around for stopping at main on restart
"postRestartCommands": [
"break main",
"continue"
]
}
]
}
- The difference between the two is that the gdb called is different
- Enter the Run & Debug interface with shortcut keys Ctrl+Shift+D
- ①Select Pico Debug as the debugger
- ②Select CMake as debug mode
- ③Start debugging button, shortcut key F5
- ④Select blink as debugging object
- Click the debug button to enter the debugging mode, and the shortcut key is F5
- The debugging toolbar appears
- ①Restart your device
- ②Continue to run the program
- ③Execute the next step
- ④Enter function running
- ⑤Exit function running
- ⑥Stop debugging
- Click to continue running the program, using the shortcut key F5, you will see the pico running the blink program