Convert Figma logo to code with AI

raspberrypi logopico-examples

No description available

2,775
809
2,775
129

Top Related Projects

Arduino core for the ESP32

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

Quick Overview

The raspberrypi/pico-examples repository is a collection of example projects for the Raspberry Pi Pico microcontroller. It provides a wide range of sample code demonstrating various features and capabilities of the Pico, including GPIO, PWM, ADC, I2C, SPI, and more. These examples serve as a valuable resource for developers working with the Raspberry Pi Pico.

Pros

  • Comprehensive collection of examples covering most Pico features
  • Well-organized structure with clear categorization of examples
  • Regularly updated to include new features and improvements
  • Official repository maintained by the Raspberry Pi Foundation

Cons

  • Some examples may lack detailed explanations or comments
  • Might be overwhelming for absolute beginners
  • Limited advanced or complex project examples
  • Some examples may require additional hardware components

Code Examples

  1. Blinking an LED:
#include "pico/stdlib.h"

int main() {
    const uint LED_PIN = 25;
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);
    while (true) {
        gpio_put(LED_PIN, 1);
        sleep_ms(500);
        gpio_put(LED_PIN, 0);
        sleep_ms(500);
    }
}
  1. Reading an analog value:
#include "pico/stdlib.h"
#include "hardware/adc.h"

int main() {
    adc_init();
    adc_gpio_init(26);
    adc_select_input(0);
    while (true) {
        uint16_t result = adc_read();
        printf("Raw value: %d\n", result);
        sleep_ms(500);
    }
}
  1. Using I2C to communicate with a device:
#include "pico/stdlib.h"
#include "hardware/i2c.h"

#define I2C_PORT i2c0
#define I2C_SDA 4
#define I2C_SCL 5

int main() {
    i2c_init(I2C_PORT, 100 * 1000);
    gpio_set_function(I2C_SDA, GPIO_FUNC_I2C);
    gpio_set_function(I2C_SCL, GPIO_FUNC_I2C);
    gpio_pull_up(I2C_SDA);
    gpio_pull_up(I2C_SCL);

    uint8_t data[] = {0x00, 0x01};
    i2c_write_blocking(I2C_PORT, 0x42, data, 2, false);
}

Getting Started

  1. Clone the repository:
    git clone https://github.com/raspberrypi/pico-examples.git
    
  2. Install the Pico SDK and set up your development environment as per the official documentation.
  3. Navigate to the desired example directory.
  4. Build the example using CMake:
    mkdir build
    cd build
    cmake ..
    make
    
  5. Flash the resulting .uf2 file to your Raspberry Pi Pico.

Competitor Comparisons

Arduino core for the ESP32

Pros of arduino-esp32

  • Extensive library support and compatibility with Arduino ecosystem
  • Broader hardware support, including various ESP32 variants
  • Active community and frequent updates

Cons of arduino-esp32

  • Higher power consumption compared to Pico
  • More complex setup and configuration process
  • Larger codebase, potentially steeper learning curve

Code Comparison

pico-examples:

#include "pico/stdlib.h"

int main() {
    gpio_init(PICO_DEFAULT_LED_PIN);
    gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
    while (true) {
        gpio_put(PICO_DEFAULT_LED_PIN, 1);
        sleep_ms(500);
        gpio_put(PICO_DEFAULT_LED_PIN, 0);
        sleep_ms(500);
    }
}

arduino-esp32:

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
}

The pico-examples code uses C and direct hardware manipulation, while arduino-esp32 uses C++ and Arduino's abstraction layer. The arduino-esp32 code is more beginner-friendly but may have slightly higher overhead.

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

Pros of MicroPython

  • Supports a wide range of microcontrollers and development boards
  • Provides a high-level Python-like programming experience for embedded systems
  • Extensive community support and third-party libraries

Cons of MicroPython

  • Generally slower execution compared to C/C++ code
  • Larger memory footprint, which can be a constraint on resource-limited devices
  • Limited access to low-level hardware features in some cases

Code Comparison

MicroPython example:

from machine import Pin
import time

led = Pin(25, Pin.OUT)
while True:
    led.toggle()
    time.sleep(1)

Pico Examples (C/C++):

#include "pico/stdlib.h"

int main() {
    const uint LED_PIN = 25;
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);
    while (true) {
        gpio_put(LED_PIN, 1);
        sleep_ms(1000);
        gpio_put(LED_PIN, 0);
        sleep_ms(1000);
    }
}

The MicroPython code is more concise and easier to read, while the Pico Examples code offers more direct control over hardware and potentially better performance.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Raspberry Pi RP2350 Pico SDK Examples - Early Access

RP2350 Instructions

Everything below this section is from the stock pico-examples, so ignore URLs etc., but generally instructions are the same.

The Pico SDK default continues to be to build for RP2040 (PICO_PLATFORM=rp2040), so to build for RP2350, you need to pass -DPICO_PLATFORM=rp2350 to CMake (or -DPICO_PLATFORM=rp2350-riscv for RISC-V).

Most, but not all examples, currently work on RP2350 however you should be able to do a full build with any of the above platforms (PICO_PLATFORM=host however currently fails on some examples)

For RISC-V compilation, you should take a compiler from here: https://www.embecosm.com/resources/tool-chain-downloads/#riscv-stable

Original pico-examples docs

Getting started

See Getting Started with the Raspberry Pi Pico and the README in the pico-sdk for information on getting up and running.

First Examples

AppDescriptionLink to prebuilt UF2
hello_serialThe obligatory Hello World program for Pico (Output over serial version)
hello_usbThe obligatory Hello World program for Pico (Output over USB version)https://rptl.io/pico-hello-usb
blinkBlink an LED on and off. Works on both boards with regular LEDs and Pico Whttps://rptl.io/pico-blink
blink_simpleBlink an LED on and off. Does not work on Pico W.https://rptl.io/pico-blink
picow_blinkBlinks the Pico W on-board LED (which is connected via the WiFi chip).http://rptl.io/pico-w-blink

ADC

AppDescription
hello_adcDisplay the voltage from an ADC input.
joystick_displayDisplay a Joystick X/Y input based on two ADC inputs.
adc_consoleAn interactive shell for playing with the ADC. Includes example of free-running capture mode.
onboard_temperatureDisplay the value of the onboard temperature sensor.
microphone_adcRead analog values from a microphone and plot the measured sound amplitude.
dma_captureUse the DMA to capture many samples from the ADC.
read_vsysDemonstrates how to read VSYS to get the voltage of the power supply.

Bootloaders (RP2350 Only)

AppDescription
enc_bootloaderA bootloader which decrypts binaries from flash into SRAM. See the separate README for more information

Clocks

AppDescription
hello_48MHzChange the system clock frequency to 48 MHz while running.
hello_gpoutUse the general purpose clock outputs (GPOUT) to drive divisions of internal clocks onto GPIO outputs.
hello_resusEnable the clock resuscitate feature, "accidentally" stop the system clock, and show how we recover.
detached_clk_periDetach peripheral clock and vary system clock.

CMake

AppDescription
build_variantsBuilds two version of the same app with different configurations

DCP

AppDescription
hello_dcpUse the double-precision coprocessor directly in assembler.

DMA

AppDescription
hello_dmaUse the DMA to copy data in memory.
control_blocksBuild a control block list, to program a longer sequence of DMA transfers to the UART.
channel_irqUse an IRQ handler to reconfigure a DMA channel, in order to continuously drive data through a PIO state machine.
sniff_crcUse the DMA engine's 'sniff' capability to calculate a CRC32 on a data buffer.

HSTX

AppDescription
dvi_out_hstx_encoder RP2350Use the HSTX to output a DVI signal with 3:3:2 RGB

Flash

AppDescription
cache_perfctrRead and clear the cache performance counters. Show how they are affected by different types of flash reads.
nukeObliterate 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.
programErase a flash sector, program one flash page, and read back the data.
xip_streamStream data using the XIP stream hardware, which allows data to be DMA'd in the background whilst executing code from flash.
ssi_dmaDMA directly from the flash interface (continuous SCK clocking) for maximum bulk read performance.
runtime_flash_permissionsDemonstrates adding partitions at runtime to change the flash permissions

FreeRTOS

These examples require you to set the FREERTOS_KERNEL_PATH to point to the FreeRTOS Kernel. See https://github.com/FreeRTOS/FreeRTOS-Kernel

AppDescription
hello_freertosExamples that demonstrate how run FreeRTOS and tasks on 1 or 2 cores.

GPIO

AppDescription
hello_7segmentUse the GPIOs to drive a seven segment LED display.
hello_gpio_irqRegister an interrupt handler to run when a GPIO is toggled.
dht_sensorUse GPIO to bitbang the serial protocol for a DHT temperature/humidity sensor.

See also: blink, blinking an LED attached to a GPIO.

HW divider

AppDescription
hello_dividerShow how to directly access the hardware integer dividers, in case AEABI injection is disabled.

I2C

AppDescription
bus_scanScan the I2C bus for devices and display results.
bmp280_i2cRead and convert temperature and pressure data from a BMP280 sensor, attached to an I2C bus.
lcd_1602_i2cDisplay some text on a generic 16x2 character LCD display, via I2C.
lis3dh_i2cRead acceleration and temperature value from a LIS3DH sensor via I2C
mcp9808_i2cRead temperature, set limits and raise alerts when limits are surpassed.
mma8451_i2cRead acceleration from a MMA8451 accelerometer and set range and precision for the data.
mpl3115a2_i2cInterface with an MPL3115A2 altimeter, exploring interrupts and advanced board features, via I2C.
mpu6050_i2cRead acceleration and angular rate values from a MPU6050 accelerometer/gyro, attached to an I2C bus.
ssd1306_i2cConvert and display a bitmap on a 128x32 or 128x64 SSD1306-driven OLED display
pa1010d_i2cRead GPS location data, parse and display data via I2C.
pcf8523_i2cRead time and date values from a real time clock. Set current time and alarms on it.
ht16k33_i2cDrive a 4 digit 14 segment LED with an HT16K33.
slave_mem_i2ci2c slave example where the slave implements a 256 byte memory

Interpolator

AppDescription
hello_interpA bundle of small examples, showing how to access the core-local interpolator hardware, and use most of its features.

Multicore

AppDescription
hello_multicoreLaunch a function on the second core, printf some messages on each core, and pass data back and forth through the mailbox FIFOs.
multicore_fifo_irqsOn each core, register and interrupt handler for the mailbox FIFOs. Show how the interrupt fires when that core receives a message.
multicore_runnerSet up the second core to accept, and run, any function pointer pushed into its mailbox FIFO. Push in a few pieces of code and get answers back.
multicore_doorbellClaims two doorbells for signaling between the cores. Counts how many doorbell IRQs occur on the second core and uses doorbells to coordinate exit.

OTP

AppDescription
hello_otpDemonstrate reading and writing from the OTP on RP2350, along with some of the features of OTP (error correction and page locking).

Pico Board

AppDescription
blinkyBlink "hello, world" in Morse code on Pico's LED
buttonUse Pico's BOOTSEL button as a regular button input, by temporarily suspending flash access.

Pico W Networking

These examples are for the Pico W, and are only available for PICO_BOARD=pico_w

AppDescription
picow_access_pointStarts a WiFi access point, and fields DHCP requests.
picow_blinkBlinks the on-board LED (which is connected via the WiFi chip).
picow_blink_slow_clockBlinks the on-board LED (which is connected via the WiFi chip) with a slower system clock to show how to reconfigure communication with the WiFi chip under those circumstances
picow_iperf_serverRuns an "iperf" server for WiFi speed testing.
picow_ntp_clientConnects to an NTP server to fetch and display the current time.
picow_tcp_clientA simple TCP client. You can run python_test_tcp_server.py for it to connect to.
picow_tcp_serverA simple TCP server. You can use python_test_tcp_client.py to connect to it.
picow_tls_clientDemonstrates how to make a HTTPS request using TLS.
picow_tls_verifyDemonstrates how to make a HTTPS request using TLS with certificate verification.
picow_wifi_scanScans for WiFi networks and prints the results.
picow_udp_beaconA simple UDP transmitter.
picow_httpdRuns a LWIP HTTP server test app

FreeRTOS examples

These are examples of integrating Pico W networking under FreeRTOS, and require you to set the FREERTOS_KERNEL_PATH to point to the FreeRTOS Kernel. See https://github.com/FreeRTOS/FreeRTOS-Kernel

AppDescription
picow_freertos_iperf_server_nosysRuns an "iperf" server for WiFi speed testing under FreeRTOS in NO_SYS=1 mode. The LED is blinked in another task
picow_freertos_iperf_server_sysRuns an "iperf" server for WiFi speed testing under FreeRTOS in NO_SYS=0 (i.e. full FreeRTOS integration) mode. The LED is blinked in another task
picow_freertos_ping_nosysRuns the lwip-contrib/apps/ping test app under FreeRTOS in NO_SYS=1 mode.
picow_freertos_ping_sysRuns the lwip-contrib/apps/ping test app under FreeRTOS in NO_SYS=0 (i.e. full FreeRTOS integration) mode. The test app uses the lwIP socket API in this case.
picow_freertos_ntp_client_socketConnects to an NTP server using the LwIP Socket API with FreeRTOS in NO_SYS=0 (i.e. full FreeRTOS integration) mode.
pico_freertos_httpd_nosysRuns a LWIP HTTP server test app under FreeRTOS in NO_SYS=1 mode.
pico_freertos_httpd_sysRuns a LWIP HTTP server test app under FreeRTOS in NO_SYS=0 (i.e. full FreeRTOS integration) mode.

Pico W Bluetooth

These examples are for the Pico W, and are only available for PICO_BOARD=pico_w. They are examples from the Blue Kitchen Bluetooth stack, see here for a full description.

By default, the Bluetooth examples are only built in one "mode" only (background, poll, or freertos), with the default being background. This can be changed by passing -DBTSTACK_EXAMPLE_TYPE=poll etc. to CMake, or all examples can be built (which may be slow) by passing -DBTSTACK_EXAMPLE_TYPE=all Freertos versions can only be built if FREERTOS_KERNEL_PATH is defined.

The Bluetooth examples that use audio require code in pico-extras. Pass -DPICO_EXTRAS_PATH=${HOME}/pico-extras on the cmake command line or define PICO_EXTRAS_PATH=${HOME}/pico-extras in your environment and re-run cmake to include them in the build.

AppDescription
picow_bt_example_a2dp_sink_demoA2DP Sink - Receive Audio Stream and Control Playback.
picow_bt_example_a2dp_source_demoA2DP Source - Stream Audio and Control Volume.
picow_bt_example_ancs_client_demoLE ANCS Client - Apple Notification Service.
picow_bt_example_att_delayed_responseLE Peripheral - Delayed Response.
picow_bt_example_audio_duplexAudio Driver - Forward Audio from Source to Sink.
picow_bt_example_avrcp_browsing_clientAVRCP Browsing - Browse Media Players and Media Information.
picow_bt_example_dut_mode_classicTesting - Enable Device Under Test (DUT.c) Mode for Classic.
picow_bt_example_gap_dedicated_bondingGAP bonding
picow_bt_example_gap_inquiryGAP Classic Inquiry.
picow_bt_example_gap_le_advertisementsGAP LE Advertisements Scanner.
picow_bt_example_gap_link_keysGAP Link Key Management (Classic.c).
picow_bt_example_gatt_battery_queryGATT Battery Service Client.
picow_bt_example_gatt_browserGATT Client - Discover Primary Services.
picow_bt_example_gatt_counterGATT Server - Heartbeat Counter over GATT.
picow_bt_example_gatt_device_information_queryGATT Device Information Service Client.
picow_bt_example_gatt_heart_rate_clientGATT Heart Rate Sensor Client.
picow_bt_example_gatt_streamer_serverPerformance - Stream Data over GATT (Server.c).
picow_bt_example_hfp_ag_demoHFP AG - Audio Gateway.
picow_bt_example_hfp_hf_demoHFP HF - Hands-Free.
picow_bt_example_hid_host_demoHID Host Classic.
picow_bt_example_hid_keyboard_demoHID Keyboard Classic.
picow_bt_example_hid_mouse_demoHID Mouse Classic.
picow_bt_example_hog_boot_host_demoHID Boot Host LE.
picow_bt_example_hog_host_demoHID Host LE.
picow_bt_example_hog_keyboard_demoHID Keyboard LE.
picow_bt_example_hog_mouse_demoHID Mouse LE.
picow_bt_example_hsp_ag_demoHSP AG - Audio Gateway.
picow_bt_example_hsp_hs_demoHSP HS - Headset.
picow_bt_example_le_credit_based_flow_control_mode_clientLE Credit-Based Flow-Control Mode Client - Send Data over L2CAP.
picow_bt_example_le_credit_based_flow_control_mode_serverLE Credit-Based Flow-Control Mode Server - Receive data over L2CAP.
picow_bt_example_led_counterHello World - Blinking a LED without Bluetooth.
picow_bt_example_le_mitmLE Man-in-the-Middle Tool.
picow_bt_example_le_streamer_clientPerformance - Stream Data over GATT (Client.c).
picow_bt_example_mod_playerAudio Driver - Play 80's MOD Song.
picow_bt_example_nordic_spp_le_counterLE Nordic SPP-like Heartbeat Server.
picow_bt_example_nordic_spp_le_streamerLE Nordic SPP-like Streamer Server.
picow_bt_example_sdp_general_querySDP Client - Query Remote SDP Records.
picow_bt_example_sdp_rfcomm_querySDP Client - Query RFCOMM SDP record.
picow_bt_example_sine_playerAudio Driver - Play Sine.
picow_bt_example_sm_pairing_centralLE Central - Test Pairing Methods.
picow_bt_example_sm_pairing_peripheralLE Peripheral - Test Pairing Methods.
picow_bt_example_spp_and_gatt_counterDual Mode - SPP and LE Counter.
picow_bt_example_spp_and_gatt_streamerDual Mode - SPP and LE streamer.
picow_bt_example_spp_counterSPP Server - Heartbeat Counter over RFCOMM.
picow_bt_example_spp_flowcontrolSPP Server - RFCOMM Flow Control.
picow_bt_example_spp_streamer_clientPerformance - Stream Data over SPP (Client.c).
picow_bt_example_spp_streamerPerformance - Stream Data over SPP (Server.c).
picow_bt_example_ublox_spp_le_counterLE u-blox SPP-like Heartbeat Server.

Some Standalone Bluetooth examples (without all the common example build infrastructure) are also available:

AppDescription
picow_ble_temp_sensorReads from the on board temperature sensor and sends notifications via BLE
picow_ble_temp_sensor_with_wifiSame as above but also connects to Wi-Fi and starts an "iperf" server
picow_ble_temp_readerConnects to one of the above "sensors" and reads the temperature

PIO

AppDescription
hello_pioAbsolutely minimal example showing how to control an LED by pushing values into a PIO FIFO.
apa102Rainbow pattern on on a string of APA102 addressable RGB LEDs.
clocked_inputShift in serial data, sampling with an external clock.
differential_manchesterSend and receive differential Manchester-encoded serial (BMC).
hub75Display an image on a 128x64 HUB75 RGB LED matrix.
i2cScan an I2C bus.
ir_necSending and receiving IR (infra-red) codes using the PIO.
logic_analyserUse PIO and DMA to capture a logic trace of some GPIOs, whilst a PWM unit is driving them.
manchester_encodingSend and receive Manchester-encoded serial.
onewireA library for interfacing to 1-Wire devices, with an example for the DS18B20 temperature sensor.
pio_blinkSet up some PIO state machines to blink LEDs at different frequencies, according to delay counts pushed into their FIFOs.
pwmPulse width modulation on PIO. Use it to gradually fade the brightness of an LED.
spiUse PIO to erase, program and read an external SPI flash chip. A second example runs a loopback test with all four CPHA/CPOL combinations.
squarewaveDrive a fast square wave onto a GPIO. This example accesses low-level PIO registers directly, instead of using the SDK functions.
squarewave_div_syncGenerates a square wave on three GPIOs and synchronises the divider on all the state machines
st7789_lcdSet up PIO for 62.5 Mbps serial output, and use this to display a spinning image on a ST7789 serial LCD.
quadrature_encoderA quadrature encoder using PIO to maintain counts independent of the CPU.
quadrature_encoder_substepHigh resolution speed measurement using a standard quadrature encoder
uart_rxImplement the receive component of a UART serial port. Attach it to the spare Arm UART to see it receive characters.
uart_txImplement the transmit component of a UART serial port, and print hello world.
ws2812Examples of driving WS2812 addressable RGB LEDs.
additionAdd two integers together using PIO. Only around 8 billion times slower than Cortex-M0+.

PWM

AppDescription
hello_pwmMinimal example of driving PWM output on GPIOs.
led_fadeFade an LED between low and high brightness. An interrupt handler updates the PWM slice's output level each time the counter wraps.
measure_duty_cycleDrives a PWM output at a range of duty cycles, and uses another PWM slice in input mode to measure the duty cycle.

Reset

AppDescription
hello_resetPerform a hard reset on some peripherals, then bring them back up.

RTC

AppDescription
hello_rtcSet a date/time on the RTC, then repeatedly print the current time, 10 times per second, to show it updating.
rtc_alarmSet an alarm on the RTC to trigger an interrupt at a date/time 5 seconds into the future.
rtc_alarm_repeatTrigger an RTC interrupt once per minute.

SHA-256

AppDescription
hello_sha256Demonstrates how to use the pico_sha256 library to calculate a checksum using the hardware in rp2350
mbedtls_sha256Demonstrates using the SHA-256 hardware acceleration in mbedtls

SPI

AppDescription
bme280_spiAttach a BME280 temperature/humidity/pressure sensor via SPI.
mpu9250_spiAttach a MPU9250 accelerometer/gyoscope via SPI.
spi_dmaUse DMA to transfer data both to and from the SPI simultaneously. The SPI is configured for loopback.
spi_flashErase, program and read a serial flash device attached to one of the SPI controllers.
spi_master_slaveDemonstrate SPI communication as master and slave.
max7219_8x7seg_spiAttaching a Max7219 driving an 8 digit 7 segment display via SPI
max7219_32x8_spiAttaching a Max7219 driving an 32x8 LED display via SPI

System

AppDescription
boot_infoDemonstrate how to read and interpret sys info boot info.
hello_double_tapAn LED blink with the pico_bootsel_via_double_reset library linked. This enters the USB bootloader when it detects the system being reset twice in quick succession, which is useful for boards with a reset button but no BOOTSEL button.
randDemonstrate how to use the pico random number functions.
narrow_io_writeDemonstrate the effects of 8-bit and 16-bit writes on a 32-bit IO register.
unique_board_idRead the 64 bit unique ID from external flash, which serves as a unique identifier for the board.

Timer

AppDescription
hello_timerSet callbacks on the system timer, which repeat at regular intervals. Cancel the timer when we're done.
periodic_samplerSample GPIOs in a timer callback, and push the samples into a concurrency-safe queue. Pop data from the queue in code running in the foreground.
timer_lowlevelExample of direct access to the timer hardware. Not generally recommended, as the SDK may use the timer for IO timeouts.

UART

AppDescription
hello_uartPrint some text from one of the UART serial ports, without going through stdio.
lcd_uartDisplay text and symbols on a 16x02 RGB LCD display via UART
uart_advancedUse some other UART features like RX interrupts, hardware control flow, and data formats other than 8n1.

Universal

These are examples of how to build universal binaries which run on RP2040, and RP2350 Arm & RISC-V. These require you to set PICO_ARM_TOOLCHAIN_PATH and PICO_RISCV_TOOLCHAIN_PATH to appropriate paths, to ensure you have compilers for both architectures.

AppDescription
blinkSame as the blink example, but universal.
hello_universalThe obligatory Hello World program for Pico (USB and serial output). On RP2350 it will reboot to the other architecture after every 10 prints.
nuke_universalSame as the nuke example, but universal. On RP2350 runs as a packaged SRAM binary, so is written to flash and copied to SRAM by the bootloader

USB Device

TinyUSB Examples

Most of the USB device examples come directly from the TinyUSB device examples directory here. Those that are supported on RP2040 devices are automatically included as part of the pico-examples build as targets named tinyusb_dev_<example_name>, e.g. https://github.com/hathach/tinyusb/tree/master/examples/device/hid_composite is built as tinyusb_dev_hid_composite.

At the time of writing, these examples are available:

  • tinyusb_dev_audio_4_channel_mic
  • tinyusb_dev_audio_test
  • tinyusb_dev_board_test
  • tinyusb_dev_cdc_dual_ports
  • tinyusb_dev_cdc_msc
  • tinyusb_dev_dfu
  • tinyusb_dev_dfu_runtime
  • tinyusb_dev_dynamic_configuration
  • tinyusb_dev_hid_composite
  • tinyusb_dev_hid_generic_inout
  • tinyusb_dev_hid_multiple_interface
  • tinyusb_dev_midi_test
  • tinyusb_dev_msc_dual_lun
  • tinyusb_dev_net_lwip_webserver
  • tinyusb_dev_uac2_headset
  • tinyusb_dev_usbtmc
  • tinyusb_dev_video_capture
  • tinyusb_dev_webusb_serial

Whilst these examples ably demonstrate how to use TinyUSB in device mode, their CMakeLists.txt is set up in a way tailored to how TinyUSB builds their examples within their source tree.

For a better example of how to configure CMakeLists.txt for using TinyUSB in device mode with the Raspberry Pi SDK see below:

SDK build example

AppDescription
dev_hid_compositeA copy of the TinyUSB device example with the same name, but with a CMakeLists.txt which demonstrates how to add a dependency on the TinyUSB device libraries with the Raspberry Pi Pico SDK

Low Level example

AppDescription
dev_lowlevelA USB Bulk loopback implemented with direct access to the USB hardware (no TinyUSB)

USB Host

All the USB host examples come directly from the TinyUSB host examples directory here. Those that are supported on RP2040 devices are automatically included as part of the pico-examples build as targets named tinyusb_host_<example_name>, e.g. https://github.com/hathach/tinyusb/tree/master/examples/host/cdc_msc_hid is built as tinyusb_host_cdc_msc_hid.

At the time of writing, there is only one host example available:

  • tinyusb_host_cdc_msc_hid

USB Dual Mode

USB Dual Mode uses PIO as a USB host controller and the RP2040 USB device controller as a device controller. All the USB dual examples come directly from the TinyUSB dual examples directory here. Those that are supported on RP2040 devices are automatically included as part of the pico-examples build as targets named tinyusb_dual_<example_name>, e.g. https://github.com/hathach/tinyusb/tree/master/examples/dual/host_hid_to_device_cdc is built as tinyusb_dual_host_hid_to_device_cdc.

At the time of writing, there is only one dual example available:

  • tinyusb_dual_host_hid_to_device_cdc

Watchdog

AppDescription
hello_watchdogSet the watchdog timer, and let it expire. Detect the reboot, and halt.