This project demonstrates WebUSB on a Pico device using the TinyUSB stack. The firmware allows the Pico to act as a USB device with both CDC (serial) and custom WebUSB functionalities. For example, it reads current using an ACS712 sensor, and lets you control GPIO pins via USB commands.
build/ - Build output directory (generated by CMake).
src/ PicoWWEBUSB.c - Main project source including USB, ADC, and GPIO tasks.
test/ - Directory for project tests.
CMakeLists.txt - CMake configuration file for building the project.
CMakePresets.json - CMake presets for various configurations.
pico_sdk_import.cmake - Pico SDK import configuration.
The device uses TinyUSB to provide both CDC and a vendor-specific WebUSB interface.
The LED blinking pattern provides visual feedback about the USB connection state. Check out the led_blinking_task implementation.
USB commands can control GPIO pins. The process_usb_commands function interprets 2-byte commands to toggle GPIO states.
An ACS712 sensor measures current. The project uses an ADC to sample voltage and compute current in the adc_task and read_current functions.
This project uses CMake. To build the project:
mkdir build
cd build
cmake ..
cmake --build .
You can also use Ninja if your environment supports it:
mkdir build
cd build
cmake -G Ninja ..
ninja
After building, flash the firmware (UF2 file) onto your Pico device. The UF2 file is generated in the build directory (e.g., PicoWWEBUSB.uf2). Simply drag and drop it onto the Pico when it appears as a mass storage device.
Serial/WebUSB Communication: When the device is connected, you can use a serial terminal or compatible browser (with WebUSB support) to communicate with the device.
Send 2-byte commands [GPIO_PIN_SELECTOR, ON/OFF_STATE] to control pins. See the process_usb_commands function for command definitions.
The ADC is periodically read and current is echoed back via both CDC and WebUSB.
Pico SDK: Imported via pico_sdk_import.cmake.
TinyUSB Library: Used to implement USB functionalities.