Skip to content

elementosystems/PicoWWebUSB

Repository files navigation

PicoWWebUSB Project

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.

Repository Structure

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.

Features

WebUSB & CDC Communication:

The device uses TinyUSB to provide both CDC and a vendor-specific WebUSB interface.

LED Indicators:

The LED blinking pattern provides visual feedback about the USB connection state. Check out the led_blinking_task implementation.

GPIO Control:

USB commands can control GPIO pins. The process_usb_commands function interprets 2-byte commands to toggle GPIO states.

ADC and Current Measurement:

An ACS712 sensor measures current. The project uses an ADC to sample voltage and compute current in the adc_task and read_current functions.

Building the Project

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

Flashing the Firmware

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.

Running and Testing

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.

GPIO Control:

Send 2-byte commands [GPIO_PIN_SELECTOR, ON/OFF_STATE] to control pins. See the process_usb_commands function for command definitions.

Current Measurement:

The ADC is periodically read and current is echoed back via both CDC and WebUSB.

Dependencies

Pico SDK: Imported via pico_sdk_import.cmake.

TinyUSB Library: Used to implement USB functionalities.

About

PicoWWebUSB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •