Working with C/C++
This chapter contains the following sections. Please read as needed:
Setting Up the Development Environment
Please refer to the Install and Configure Pico C/C++ Development Environment Tutorial to download and install the Pico VS Code.
Example
The C/C++ examples are located in the examples\C directory of the example package.
| Example | Basic Program Description | Dependency Library |
|---|---|---|
| 01_USB | PIO-USB emulation of USB device/host example | - |
| 02_RGB | Onboard RGB LED example | - |
01_USB
-
The examples are modified from sekigon-gonnoc's Pico-PIO-USB.
-
Example version: 0.5.3
-
PICO SDK version: 2.2.0
Example Description
-
Board selection
-
File path:
examples/01_USB/src/pio_usb_configuration.h -
For RP2350-USB-C and RP2350-USB-CM, switch via macro definitions
#define RP2350_USB_C 1#define RP2350_USB_CM 0
-
-
usb_device
- Example path:
examples/usb_device - Uses PIO-USB to emulate an HID keyboard/mouse device. After the computer recognizes it, the mouse cursor moves periodically.
- Example path:
-
host_hid_to_device_cdc
-
Example path:
examples/host_hid_to_device_cdc -
Uses PIO-USB as a host to read HID reports from a keyboard/mouse and outputs them to the computer's serial port via native USB CDC.
-
Note: When compiling this example, you must comment out the return statements in the file
SDK\lib\tinyusb\src\portable\raspberrypi\pio_usb\hcd_pio_usb.c, as shown below:bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) {uint8_t const pio_rhport = RHPORT_PIO(rhport);// return pio_usb_host_endpoint_abort_transfer(pio_rhport, dev_addr, ep_addr);}uint32_t hcd_frame_number(uint8_t rhport) {(void) rhport;// return pio_usb_host_get_frame_number();}
-
Hardware Connection
- Connect the PIO-USB interface of the development board to the computer.
Operation Result
-
usb_device
Through PIO-USB, the board emulates a mouse and moves the cursor every 0.5 seconds.

-
host_hid_to_device_cdc
Similar to capture_hid_report, prints mouse/keyboard reports from the host port to the device port's CDC.

02_RGB
Example Description
- Uses GPIO16 to drive a WS2812B RGB LED via PIO, cycling through colors.
Hardware Connection
- Connect the board to the computer using a USB cable.
Operation Result
- After flashing, the WS2812B RGB LED continuously fades through red, green, and blue.