Raspberry Pi Pico SDK Examples Getting started See Getting started with Raspberry Pi Pico-series and the README in the pico-sdk for informa…
Raspberry Pi Pico SDK Examples
Getting started
See Getting started with Raspberry Pi Pico-series and the README in the pico-sdk for information
on getting up and running.
Notes on different boards and platforms (RP2040 / RP2350)
The majority of examples are applicable to both RP2040 and RP2350 based boards,
however certain examples that use chip-specific functionality will only build on that platform.
Similarly, Wi-Fi and Bluetooth examples will only build on a board that includes Wi-Fi and Bluetooth support.
Platform and board information are passed to the CMake build via the PICO_PLATFORM and PICO_BOARD variables.
By default, the Pico SDK targets builds for RP2040 (PICO_PLATFORM=rp2040). To build for RP2350 instead, pass
-DPICO_PLATFORM=rp2350 to CMake (or -DPICO_PLATFORM=rp2350-riscv for RISC-V). Alternatively, in many cases, you can rely
on the board configuration to set the platform for you. For example, passing -DPICO_BOARD=pico2 will automatically select PICO_PLATFORM=rp2350.
For more information see the "Platform and Board Configuration" chapter of
the Raspberry Pi Pico-series C/C++ SDK book.
Information on which examples are not being built is displayed during the CMake configuration step.
First Examples
ADC
| App |
Description |
| hello_adc |
Display the voltage from an ADC input. |
| joystick_display |
Display a Joystick X/Y input based on two ADC inputs. |
| adc_console |
An interactive shell for playing with the ADC. Includes example of free-running capture mode. |
| onboard_temperature |
Display the value of the onboard temperature sensor. |
| microphone_adc |
Read analog values from a microphone and plot the measured sound amplitude. |
| dma_capture |
Use the DMA to capture many samples from the ADC. |
| read_vsys |
Demonstrates how to read VSYS to get the voltage of the power supply. |
async_context
| App |
Description |
| simple_at_time_worker |
Use a worker on a threadsafe background context to blink the on-board LED. |
Binary Info
| App |
Description |
| blink_any |
Uses bi_ptr variables to create a configurable blink binary - see the separate README for more details. |
| hello_anything |
Uses bi_ptr variables to create a configurable hello_world binary - see the separate README for more details. |
Bootloaders (RP235x Only)
These examples all produce multiple UF2s - a bootloader UF2, and then a separate UF2 of the program that the bootloader will load and boot. To load them onto a device with empty flash, first load the bootloader UF2, then reset to BOOTSEL mode and load the program UF2. This ordering is required because the bootloaders contain embedded partition tables - see section 5.10.6 in the RP2350 datasheet for more details on those.
| App |
Description |
| enc_bootloader |
A bootloader which decrypts binaries from flash into SRAM. See the separate README for more information. |
| uart_boot |
A bootloader which boots a separate RP2350 using the UART boot interface. See section 5.8 in the datasheet for more details, including the wiring requirements. |
Clocks
| App |
Description |
| hello_48MHz |
Change the system clock frequency to 48 MHz while running. |
| hello_gpout |
Use the general purpose clock outputs (GPOUT) to drive divisions of internal clocks onto GPIO outputs. |
| hello_resus |
Enable the clock resuscitate feature, "accidentally" stop the system clock, and show how we recover. |
| detached_clk_peri |
Detach peripheral clock and vary system clock. |
CMake
| App |
Description |
| build_variants |
Builds two versions of the same app with different configurations. |
DCP (RP235x Only)
| App |
Description |
| hello_dcp |
Use the double-precision coprocessor directly in assembler. |
DMA
| App |
Description |
| hello_dma |
Use the DMA to copy data in memory. |
| control_blocks |
Build a control block list, to program a longer sequence of DMA transfers to the UART. |
| channel_irq |
Use an IRQ handler to reconfigure a DMA channel, in order to continuously drive data through a PIO state machine. |
| sniff_crc |
Use the DMA engine's 'sniff' capability to calculate a CRC32 on a data buffer. |
Encrypted (RP235x Only)
| App |
Description |
| hello_encrypted |
Create a self-decrypting binary, using the hardened decryption stage. This should be secure against side channel attacks. |
| hello_encrypted_mbedtls |
Create a self-decrypting binary, using the MbedTLS decryption stage. This is not secure against side channel attacks, so is fast but provides limited protection. |
HSTX (RP235x Only)
Flash
| App |
Description |
| cache_perfctr |
Read and clear the cache performance counters. Show how they are affected by different types of flash reads. |
| nuke |
Obliterate the contents of flash. An example of a NO_FLASH binary (UF2 loaded directly into SRAM and runs in-place there). A useful utility to drag and drop onto your Pico if the need arises. |
| program |
Erase a flash sector, program one flash page, and read back the data. |
| xip_stream |
Stream data using the XIP stream hardware, which allows data to be DMA'd in the background whilst executing code from flash. |
| ssi_dma |
DMA directly from the flash interface (continuous SCK clocking) for maximum bulk read performance. |
| runtime_flash_permissions |
Demonstrates adding partitions at runtime to change the flash permissions. |
| partition_info |
Extract and enumerate partition information (address ranges, permissions, IDs, and names) from the partition table. |
FreeRTOS
These examples require you to set the FREERTOS_KERNEL_PATH to point to the FreeRTOS Kernel. See https://github.com/FreeRTOS/FreeRTOS-Kernel
GPIO
| App |
Description |
| hello_7segment |
Use the GPIOs to drive a seven segment LED display. |
| hello_gpio_irq |
Register an interrupt handler to run when a GPIO is toggled. |
| dht_sensor |
Use GPIO to bitbang the serial protocol for a DHT temperature/humidity sensor. |
See also: blink, blinking an LED attached to a GPIO.
HW divider
| App |
Description |
| hello_divider |
Show how to directly access the hardware integer dividers, in case AEABI injection is disabled. |
I2C
| App |
Description |
| bus_scan |
Scan the I2C bus for devices and display results. |
| bmp280_i2c |
Read and convert temperature and pressure data from a BMP280 sensor, attached to an I2C bus. |
| ina219_i2c |
Monitor power usage of another Pico device using an ina219 sensor, via I2C. |
| ina228_i2c |
Monitor power usage of another Pico device ina228 sensor, via I2C. |
| ina237_i2c |
Monitor power usage of another Pico device using an ina237 sensor, via I2C. |
| ina260_i2c |
Monitor power usage of another Pico device using an ina260 sensor, via I2C. |
| lcd_1602_i2c |
Display some text on a generic 16x2 character LCD display, via I2C. |
| lis3dh_i2c |
Read acceleration and temperature value from a LIS3DH sensor via I2C |
| mcp9808_i2c |
Read temperature from a MCP9808 sensor, set limits and raise alerts when limits are surpassed. |
| mma8451_i2c |
Read acceleration from a MMA8451 accelerometer and set range and precision for the data. |
| mpl3115a2_i2c |
Interface with an MPL3115A2 altimeter, exploring interrupts and advanced board features, via I2C. |
| mpu6050_i2c |
Read acceleration and angular rate values from a MPU6050 accelerometer/gyro, attached to an I2C bus. |
| ssd1306_i2c |
Convert and display a bitmap on a 128x32 or 128x64 SSD1306-driven OLED display. |
| pa1010d_i2c |
Read GPS location data, parse and display data via I2C. |
| pcf8523_i2c |
Read time and date values from a PCF8523 real time clock. Set current time and alarms on it. |
| ht16k33_i2c |
Drive a 4 digit 14 segment LED with an HT16K33. |
| slave_mem_i2c |
i2c slave example where the slave implements a 256 byte memory. |
| slave_mem_i2c_burst |
i2c slave example where the slave implements a 256 byte memory. This version inefficiently writes each byte in a separate call to demonstrate read and write burst mode. |
Interpolator
| App |
Description |
| hello_interp |
A bundle of small examples, showing how to access the core-local interpolator hardware, and use most of its features. |
Low Power
These examples demonstrate how to use the pico_low_power library.
Multicore
| App |
Description |
| hello_multicore |
Launch a function on the second core, printf some messages on each core, and pass data back and forth through the mailbox FIFOs. |
| multicore_fifo_irqs |
On each core, register an interrupt handler for the mailbox FIFOs. Show how the interrupt fires when that core receives a message. |
| multicore_runner |
Set up the second core to accept, and run, any function p |