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 VSCode.
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 examples | - |
| 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
-
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();}
- Example path:
Hardware Connection
- Connect the board to the computer using a USB cable
Operation Result
-
usb_device
PIO‑USB emulates a mouse and moves the mouse 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.