The easiest start is the official Raspberry Pi Pico VS Code extension, which installs the SDK, toolchain and tools and generates projects. This is what it produces underneath, useful when you build from the command line or CI.
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake) # copy from pico-sdk/external/, must come before project()
project(my_project C CXX ASM)
pico_sdk_init()
add_executable(sensor main.c)
target_link_libraries(sensor pico_stdlib)
pico_enable_stdio_usb(sensor 1) # printf over USB CDC (shows up as /dev/ttyACM0, COMx)
pico_enable_stdio_uart(sensor 0) # default would be UART0 on GP0/GP1
pico_add_extra_outputs(sensor) # also write .uf2 / .bin / .hex / .map
#include <stdio.h>
#include "pico/stdlib.h"
int main() {
stdio_init_all();
while (true) {
printf("hello\n");
sleep_ms(1000);
}
}
Build
export PICO_SDK_PATH=/path/to/pico-sdk # or -DPICO_SDK_PATH=... on the cmake line
cmake -S . -B build -DPICO_BOARD=pico2 # pico, pico_w, pico2, pico2_w, ...
cmake --build build --target sensor
The two classic mistakes
- Forgetting
PICO_BOARD. Without it the SDK assumes the original Pico. For a Pico W,PICO_BOARD=pico_wis what enables the wireless libraries; for a Pico 2 you needpico2. Board headers live in the SDK undersrc/boards/include/boards. - Waiting for printf output on USB while stdio goes to UART. The plain hello-world example prints to the UART; enable USB stdio as above if you only have the USB cable connected.
Get the latest stable SDK from the master branch; develop has upcoming features.