Guides · 9 min read

Raspberry Pi Pico C SDK VS Code Setup: First Project and UF2

Raspberry Pi Pico C SDK in VS Code: install the extension, first project, CMake explained, build and flash UF2, USB printf, Pico 2 targets, common build errors.

Programming the Raspberry Pi Pico with the C SDK in VS Code is the official way to use the board's full power. The Pico C/C++ SDK published by Raspberry Pi provides libraries with direct access to the GPIO, ADC, PWM, I2C, SPI, PIO and dual-core features of the RP2040 and RP2350 chips; your code is compiled to machine code and runs with no interpreter layer. Installing the SDK used to take hours; today the official Raspberry Pi Pico extension for VS Code downloads and sets up the compiler, CMake, Ninja and the SDK for you.

In this guide you'll install the extension, create your first C project, go through CMakeLists.txt line by line, build a UF2 file and flash it to the board, and read printf output over USB serial. You'll also compare MicroPython, Arduino and the C SDK for speed and difficulty, see why the Pico W's LED is driven differently, learn how to choose between ARM and RISC-V targets for the Pico 2, and get fixes for the most common build errors.

Programming the Raspberry Pi Pico with C++ and the C SDK
Raspberry Pi Pico: the RP2040 board accepts UF2 files built with the C/C++ SDK by drag and drop over USB.

Programming the Pico with the C/C++ SDK: when is it the right choice?

You can program the Pico in three ways. MicroPython is the easiest start: you write code in Thonny, save it and it runs straight away, but because the code is interpreted line by line it's usually 10–100 times slower than compiled code in tight loops. The Arduino core (arduino-pico) brings the familiar setup()/loop() structure and a large library ecosystem; this same SDK runs underneath it. The C SDK gives you the most control: microsecond-level timing, PIO programs, running the two cores with separate tasks, low-power modes and step-by-step debugging over SWD. For jobs where timing is critical, fast ADC sampling or custom protocols, and when you want to learn professional embedded development, the C SDK is the right choice.

FeatureMicroPythonArduino (arduino-pico)C/C++ SDK
Learning curveEasyMediumHard
First setupFirmware UF2 + Thonny, a few minutesBoard package in the Arduino IDEThe VS Code extension downloads the tools, slow the first time
Run speedInterpreted, slowest in tight loopsCompiled, close to CFastest, no extra layer
Uploading codeSave the file, no buildCompile and upload buttonBuild with CMake + Ninja, flash UF2
PIO and dual coreVia the rp2 module and _threadsetup1()/loop1() and PIO librariesFull access (pico_multicore, hardware_pio)
Debuggingprint()Serial.print()printf + step-by-step over SWD
Best forLearning, quick experimentsFast projects with ready librariesTiming-critical, low power, professional work

Installing the Raspberry Pi Pico extension for VS Code

  1. Download and install Visual Studio Code from the official site; on Windows leave the "Add to PATH" option ticked during setup.
  2. In the Extensions view on the left, search for "Raspberry Pi Pico" and install the extension published by Raspberry Pi; the C/C++ and CMake extensions it needs come with it.
  3. On macOS, first install Git and Tar with xcode-select --install in Terminal; on Linux make sure Python 3, Git and Tar are installed.
  4. Click the Raspberry Pi Pico icon that appears in the left sidebar; the commands for creating a project, opening an example and choosing the SDK version are here.
  5. When you create your first project, the extension downloads the SDK version you chose, the ARM compiler (and RISC-V for the Pico 2 if needed), CMake, Ninja and picotool; a few hundred MB come down, so use a fast connection and be patient.
Operating systemNeeds to be installed firstNote
Windows 10/11Nothing extraThe extension downloads all the tools
macOS (Sonoma or later)xcode-select --install (Git and Tar)Accept the Xcode licence if asked
Linux (Ubuntu, Debian, etc.)Python 3.10+, Git 2.28+, TarA udev rule lets picotool run without sudo
Raspberry Pi OS 64-bitNothing extraThe Lite version behaves like other Linux
Keep your projects in a short folder path with plain ASCII characters, for example C:\pico\blink or ~/pico/blink. Spaces or accented and non-English characters in the path can cause hard-to-read errors with some versions of CMake and Ninja; paths like "My Documents\New folder" are the most common troublemakers.

First project: New C/C++ Project

  1. In the Pico sidebar, choose the New C/C++ Project command.
  2. Type a project name (for example blink) and pick the board type: Pico, Pico W, Pico 2 or Pico 2 W.
  3. Choose the folder for the project and the SDK version; if unsure, the latest suggested version is fine.
  4. In the console options, tick the console over USB (stdio over USB); you can leave UART off. This setting decides where printf goes.
  5. Press Create; the extension creates the folder, downloads any tools it needs and opens the project in a new window.

The new folder contains a few files. Your actual code is in the .c file with the same name as the project. CMakeLists.txt is the project's recipe: it says which source files to build, which SDK libraries to link and whether printf goes out over USB or UART. pico_sdk_import.cmake is a helper that finds the SDK, and you don't need to touch it. After building, the build folder holds the .uf2 file you flash to the board and the .elf file used for debugging.

File / folderJobDo you edit it?
blink.cThe program's source codeYes, this is where you write your code
CMakeLists.txtSources, libraries, stdio setting, board typeYes, when adding libraries
pico_sdk_import.cmakeFinds the SDKNo
.vscode/The extension's build and debug settingsUsually not
build/blink.uf2The file you drag and drop onto the boardRegenerated on every build
build/blink.elfBinary for the debugger and picotoolRegenerated on every build

First code: blinking the LED and printf over USB serial

C++ (Arduino IDE)
1// Raspberry Pi Pico C SDK: dahili LED yakıp söndürme + USB seri printf (blink.c)
2// Raspberry Pi Pico C SDK: blink the on-board LED + printf over USB serial (blink.c)
3#include <stdio.h>
4#include "pico/stdlib.h"
5#include "pico/stdio_usb.h"
6
7#ifndef PICO_DEFAULT_LED_PIN
8#error "Bu kod Pico / Pico 2 icindir; Pico W icin cyw43 ornegini kullan / use the cyw43 example for Pico W"
9#endif
10
11int main() {
12    stdio_init_all();                           // USB stdio'yu başlat / start USB stdio
13    const uint LED_PIN = PICO_DEFAULT_LED_PIN;  // Pico ve Pico 2'de GP25 / GP25 on Pico and Pico 2
14    gpio_init(LED_PIN);
15    gpio_set_dir(LED_PIN, GPIO_OUT);
16
17    // Seri port açılana kadar en fazla 3 saniye bekle / wait up to 3 s for the serial port
18    for (int i = 0; i < 30 && !stdio_usb_connected(); i++) {
19        sleep_ms(100);
20    }
21    printf("Merhaba / Hello, Pico C SDK!\n");
22
23    uint32_t count = 0;
24    while (true) {
25        gpio_put(LED_PIN, 1);                   // LED açık / LED on
26        sleep_ms(250);
27        gpio_put(LED_PIN, 0);                   // LED kapalı / LED off
28        sleep_ms(250);
29        printf("Yanip sonme / Blink: %lu\n", (unsigned long)count++);
30    }
31}

stdio_init_all() starts the stdio channels you enabled in CMake (USB here). The on-board LED of the Pico and Pico 2 is on GP25, and the SDK defines this pin as PICO_DEFAULT_LED_PIN; the #error line stops the build with a clear message if you accidentally build the code for a Pico W. The USB serial port takes a few hundred milliseconds to appear on the computer; waiting up to 3 seconds with stdio_usb_connected() stops the first printf lines from getting lost. To see the output you can use the VS Code Serial Monitor extension, the Arduino IDE Serial Monitor or any serial terminal such as PuTTY; because USB CDC is a virtual port, the baud rate doesn't matter. The port appears as something like COM3 on Windows, /dev/tty.usbmodem… on macOS and /dev/ttyACM0 on Linux.

CMakeLists.txt line by line

Code
1# CMakeLists.txt: Pico C SDK proje dosyası / project file
2cmake_minimum_required(VERSION 3.13)
3
4# Kart: pico, pico_w, pico2, pico2_w / board type
5set(PICO_BOARD pico CACHE STRING "Board type")
6
7# SDK'yı bulur, project() satırından önce gelmeli / locates the SDK, must come before project()
8include(pico_sdk_import.cmake)
9
10project(blink C CXX ASM)
11set(CMAKE_C_STANDARD 11)
12set(CMAKE_CXX_STANDARD 17)
13
14pico_sdk_init()
15
16add_executable(blink blink.c)
17
18# Kullanılan SDK kütüphaneleri / SDK libraries used
19target_link_libraries(blink pico_stdlib)
20
21pico_enable_stdio_usb(blink 1)     # printf USB'den / printf over USB
22pico_enable_stdio_uart(blink 0)    # UART stdio kapalı / UART stdio off
23
24# .uf2, .bin, .hex ve .dis dosyalarını da üret / also generate .uf2, .bin, .hex, .dis
25pico_add_extra_outputs(blink)

The PICO_BOARD line sets which board you're building for and must come before include(pico_sdk_import.cmake) and project(), because the SDK picks the board header and processor architecture at that stage. pico_sdk_init() makes all the SDK libraries known to CMake. add_executable() lists the program name and source files, and target_link_libraries() lists the SDK libraries in use; pico_stdlib covers GPIO, timing and stdio, and you add hardware_adc for the ADC, hardware_pio for PIO and pico_multicore for the second core. pico_enable_stdio_usb() and pico_enable_stdio_uart() choose where printf goes. Without pico_add_extra_outputs() on the last line only the .elf is produced; this line is what creates the UF2 file. The CMakeLists.txt generated by the extension also has version and program-name lines; you don't need to remove them.

Building, creating the UF2 and flashing

To build, press the Compile button in the status bar at the bottom right of VS Code. The extension first configures the build folder with CMake, then compiles the sources with Ninja; the first build compiles the whole SDK so it can take a minute or two, and later builds only recompile changed files and take a few seconds. A successful build ends with blink.uf2 in the build folder. UF2 is a format designed for loading programs onto microcontrollers by copying a file as if to a USB stick: each 512-byte block carries 256 bytes of program data plus the target address, which is why the UF2 file is about twice the size of the binary.

  1. Hold down the BOOTSEL button on the Pico, plug the USB cable into the computer, then release the button.
  2. A drive appears on the computer, called RPI-RP2 for the Pico and RP2350 for the Pico 2.
  3. Drag and drop build/blink.uf2 onto this drive; the drive disappears on its own and the program starts running.
  4. Quicker: with the board in BOOTSEL mode, press the Run button in the status bar; the extension loads the UF2 onto the board and restarts it.
  5. If the drive never appears, make sure the cable isn't charge-only; for details see Pico not recognised.

Pico W and Pico 2 W: the LED is on the Wi-Fi chip

C++ (Arduino IDE)
1// Pico W / Pico 2 W: LED, Wi-Fi çipine (CYW43) bağlıdır (blink_w.c)
2// Pico W / Pico 2 W: the LED is wired to the wireless chip (CYW43) (blink_w.c)
3// CMake: PICO_BOARD pico_w (ya da pico2_w), target_link_libraries(... pico_stdlib pico_cyw43_arch_none)
4#include <stdio.h>
5#include "pico/stdlib.h"
6#include "pico/cyw43_arch.h"
7
8int main() {
9    stdio_init_all();
10    if (cyw43_arch_init()) {                    // 0 = başarılı / 0 = success
11        printf("cyw43 baslatilamadi / init failed\n");
12        return -1;
13    }
14    while (true) {
15        cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);   // LED açık / LED on
16        sleep_ms(250);
17        cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);   // LED kapalı / LED off
18        sleep_ms(250);
19    }
20}

On the Pico W and Pico 2 W the on-board LED isn't connected to the microcontroller but to the CYW43439 Wi-Fi and Bluetooth chip, so it can't be lit with gpio_put() and PICO_DEFAULT_LED_PIN isn't defined. You first start the wireless chip with cyw43_arch_init(), then control the LED with cyw43_arch_gpio_put(). In CMakeLists.txt set PICO_BOARD to pico_w or pico2_w and add the pico_cyw43_arch_none library to target_link_libraries; if you're going to use Wi-Fi, choose a version with a network stack such as pico_cyw43_arch_lwip_threadsafe_background instead. If you wire an external LED to a pin like GP15 instead of using the on-board LED, the gpio_put() code from the first example works on the Pico W as it is.

Choosing the target for the Pico 2: ARM or RISC-V?

The RP2350 chip on the Pico 2 has two pairs of cores: two ARM Cortex-M33 and two Hazard3 RISC-V cores. Only two cores run at a time, and the UF2 you load decides which architecture runs. The default and recommended target is ARM (rp2350-arm-s); thanks to its floating-point unit and DSP instructions it's faster for most jobs. The RISC-V target is interesting for trying out and learning the open architecture. The choice is made in CMake with the PICO_BOARD and PICO_PLATFORM variables; when you pick the Pico 2 in the extension, it also offers a RISC-V option and downloads the RISC-V compiler it needs.

BoardPICO_BOARDPICO_PLATFORMCores that run
Raspberry Pi Picopicorp20402 × Cortex-M0+
Raspberry Pi Pico Wpico_wrp20402 × Cortex-M0+
Raspberry Pi Pico 2 (ARM)pico2rp2350-arm-s (default)2 × Cortex-M33
Raspberry Pi Pico 2 (RISC-V)pico2rp2350-riscv2 × Hazard3 RISC-V
Raspberry Pi Pico 2 Wpico2_wrp2350-arm-s2 × Cortex-M33
Every UF2 file is built for a specific chip. If you copy a UF2 built for the RP2040 onto a Pico 2, the program won't run, and the reverse is also true. After changing the board type, the cache in the old build folder may keep building with the wrong settings; change the board through the extension's commands, or delete the build folder and configure the project again.

One step further: reading the on-chip temperature sensor

C++ (Arduino IDE)
1// Dahili sıcaklık sensörünü ADC ile oku, printf ile yaz (temp.c)
2// Read the on-chip temperature sensor with the ADC, print it (temp.c)
3// CMake: target_link_libraries(temp pico_stdlib hardware_adc)
4#include <stdio.h>
5#include "pico/stdlib.h"
6#include "hardware/adc.h"
7
8int main() {
9    stdio_init_all();
10    adc_init();
11    adc_set_temp_sensor_enabled(true);          // sıcaklık sensörünü aç / enable the sensor
12    adc_select_input(4);                        // giriş 4: RP2040 ve RP2350A'da sıcaklık / input 4: temperature
13
14    const float conv = 3.3f / (1 << 12);        // 12 bit, 3,3 V referans / 12-bit, 3.3 V reference
15    while (true) {
16        uint16_t raw = adc_read();
17        float volts = raw * conv;
18        float tempC = 27.0f - (volts - 0.706f) / 0.001721f;   // veri sayfası formülü / datasheet formula
19        printf("Ham / Raw: %u  %.3f V  Sicaklik / Temp: %.1f C\n", raw, volts, tempC);
20        sleep_ms(1000);
21    }
22}

This example shows how to add a hardware library in the SDK: you add the hardware/adc.h header to the code and the hardware_adc library to the target_link_libraries line in CMakeLists.txt. On the RP2040 and on the Pico 2's RP2350A, ADC input 4 is connected to the temperature sensor inside the chip. The 12-bit raw value is converted to a voltage with the 3.3 V reference and to degrees Celsius with the datasheet formula: at 27 °C the sensor gives about 0.706 V and drops about 1.721 mV per degree. Because the sensor measures the chip's own temperature, it can be a few degrees off room temperature; the goal here is to learn the ADC and printf rather than to measure precisely. To move on to PIO and dual-core examples with the same structure, see Pico PIO and dual core.

Common build errors and fixes

Error message / symptomCauseFix
SDK location was not specified / PICO_SDK_PATHCMake was run by hand outside the extensionUse the extension's Compile button or set the PICO_SDK_PATH environment variable
No CMAKE_C_COMPILER could be found / arm-none-eabi-gcc not foundThe compiler wasn't downloaded or the download stopped half wayRestart VS Code and let the extension finish downloading its tools
pico/stdlib.h: No such file or directorypico_stdlib missing from target_link_librariesAdd the library; if only the editor shows red squiggles and the build passes, it's an IntelliSense issue
'PICO_DEFAULT_LED_PIN' undeclaredBoard set to pico_w or pico2_wUse the cyw43 example or define an external LED pin
undefined reference to cyw43_arch_initpico_cyw43_arch_none not linkedAdd it to target_link_libraries
undefined reference to adc_inithardware_adc not linkedAdd hardware_adc to target_link_libraries
No printf outputUSB stdio off or the port opened too lateCheck pico_enable_stdio_usb(... 1), stdio_init_all() and the wait loop
UF2 copied but nothing happensBuilt for the wrong board or platformSet PICO_BOARD for your board, clean the build folder
Strange CMake/Ninja errors about the pathSpaces or non-ASCII characters in the pathMove the project to a short path such as C:\pico\blink

If you'd like to get a quick feel for the Pico's GPIO, button and PWM logic before moving to the C SDK, the Raspberry Pi Pico on-board LED, external LED, traffic light, button with LED and PWM LED fade projects in the BlueGrays app walk you through every step with a circuit diagram and ready-made code; rewriting the same circuits later with the C SDK structure from this guide is excellent practice. For the basics, have a look at what is the Raspberry Pi Pico.

Frequently asked questions

Can the Raspberry Pi Pico be programmed in C++?

Yes. The official Pico C/C++ SDK supports both C and C++; the CXX language is already declared in the project() line of CMakeLists.txt, and you can add .cpp files to the add_executable() line.

How do I set up VS Code for the Raspberry Pi Pico?

Install VS Code, then install the Raspberry Pi Pico extension published by Raspberry Pi from the Extensions view. On your first project the extension downloads the SDK, compiler, CMake and Ninja by itself. macOS needs xcode-select --install first, and Linux needs Python 3, Git and Tar.

How do I create a UF2 file for the Pico?

When CMakeLists.txt contains pico_add_extra_outputs(), building the project produces a .uf2 file in the build folder. Plug the board in while holding BOOTSEL and copy the file onto the drive that appears, or use the extension's Run button.

Where do I see printf output from the Pico C SDK?

If pico_enable_stdio_usb(target 1) is set in CMake and stdio_init_all() is called in the code, printf goes to the USB serial port. Open that port with the VS Code Serial Monitor, the Arduino Serial Monitor or PuTTY to see the output; the baud rate doesn't matter.

Is MicroPython or the C SDK faster on the Pico?

Code compiled with the C SDK is usually 10–100 times faster than interpreted MicroPython in tight loops. In many sensor projects you won't notice the difference, though; MicroPython suits learning and quick experiments, while the C SDK suits timing-critical, performance-hungry work.

Which target should I choose for the Pico 2: ARM or RISC-V?

For most projects choose the default ARM Cortex-M33 target (rp2350-arm-s); its floating-point unit usually makes it faster. The RISC-V target (rp2350-riscv) is for exploring the open architecture. In CMake the board is set with PICO_BOARD pico2 and the architecture with PICO_PLATFORM.

See all projects
Raspberry Pi Pico Onboard LED Blink (Pico and Pico W)
PI-1Beginner

Raspberry Pi Pico Onboard LED Blink (Pico and Pico W)

The opening project of the Raspberry Pi Pico series! We blink the Pico's green built-in LED to confirm the board works, the classic "Hello World" first experiment. No external parts needed, just the Pico and a USB cable. The code is written in MicroPython, the language officially supported by the Raspberry Pi Foundation.

5.0(1)
11
Raspberry Pi Pico: Controlling an External LED (Breadboard)
PI-2Beginner

Raspberry Pi Pico: Controlling an External LED (Breadboard)

The next step after the Pico's built-in LED: connect an external LED on a breadboard and control it through pin GP14. You'll learn how to use any of the Pico's GPIO pins as an output, the LED's polarity (long leg = anode/+, short leg = cathode/–) and why a current-limiting resistor (220Ω) is a must. Without the resistor, too much current flows through the LED and it can burn out.

4.5(2)
7
Raspberry Pi Pico Alternating Two LEDs (Blink-Flip Pattern)
PI-3Beginner

Raspberry Pi Pico Alternating Two LEDs (Blink-Flip Pattern)

The next step after the Pico's single LED: the classic flip-flop animation, with two LEDs blinking in turn. One LED turns off as the other turns on, the most basic example of handling multiple GPIOs. Two LEDs of different colors (red on GP14, green on GP13) swap every 500 ms. With MicroPython's Pin.toggle() method, the code stays short and readable.

5.0(2)
20
Raspberry Pi Pico Traffic Light Simulator (3 LEDs Sequential)
PI-4Beginner

Raspberry Pi Pico Traffic Light Simulator (3 LEDs Sequential)

We recreate real traffic light logic with red, yellow and green LEDs, the first Pico project to move up to 3 LEDs! Green says "go" for 4 seconds, yellow "get ready" for 1.5 seconds, red "stop" for 3 seconds, and red+yellow "set off" for 1 second (the European traffic light pattern). You'll learn to define functions (def all_off()), state machine logic and multi-GPIO synchronization.

4.0(1)
12
Raspberry Pi Pico Button Controlled LED (Push)
PI-9Beginner
Premium

Raspberry Pi Pico Button Controlled LED (Push)

First input project with Pico — button read! LED lights while button is pressed, off when released. This is the big step after LED animations: signal input from the world to Pico. Learn Pin.IN (input mode), Pin.PULL_UP (internal pull-up resistor — standard for buttons), button.value() reading. GP14 LED, GP2 button (internal PULL_UP). Pressed = LOW (0), released = HIGH (1) — reverse logic seems confusing at first but is industry standard.

11
Raspberry Pi Pico PWM LED Fade (Breathing Effect)
PI-14Beginner

Raspberry Pi Pico PWM LED Fade (Breathing Effect)

The LED doesn't just blink anymore, it breathes! With the Raspberry Pi Pico's PWM (Pulse Width Modulation), the LED's brightness slowly rises and then slowly fades, a calm "breathing" effect like a sleeping laptop's light. You'll learn the machine.PWM class, the 16-bit brightness value from 0–65535 with duty_u16() and the PWM frequency.

4
Raspberry Pi Pico RGB LED Color Cycle (3-Channel PWM)
PI-15Beginner

Raspberry Pi Pico RGB LED Color Cycle (3-Channel PWM)

One LED, millions of colors! An RGB LED actually holds 3 separate LEDs: red, green and blue. Set the brightness of each one separately with the Pico's 3 PWM channels and the colors mix: red + green = yellow, green + blue = cyan, all three = white. In this project the LED cycles through 8 colors.

6
Raspberry Pi Pico Button Debounce: IRQ vs Software Polling
PI-13Intermediate
Premium

Raspberry Pi Pico Button Debounce: IRQ vs Software Polling

If one press of a button made your code count 3-4 times, the culprit is contact bounce: the button's metal contacts open and close many times within microseconds as they touch! In this project we count the same button in 2 different ways and compare them side by side in Serial: RAW polling (catches the bounce and miscounts) and IRQ + software debounce (counts correctly).

12