This C++ project demonstrates USB gamepad support on RP2040 and RP2350-based boards using PIO USB.
It prints the pressed gamepad buttons to the serial console for easy debugging and testing.
-
Hardware:
- Adafruit Metro RP2350. You also need this cable to connect to the usb host breakout: USB Type A Jack Breakout Cable with Premium Female Jumpers
- Other compatible RP2040/RP2350 boards (e.g., Raspberry Pico/Pico 2) with an external usb connector attached. Like the WaveShare RP2040 PiZero or similar boards.
- USB gamepad or controller (e.g., Xbox-style, DualShock 4, DualSense, etc.)
-
Software:
- Raspberry Pi Pico SDK
- TinyUSB (latest master)
- Pico PIO USB (latest main)
Set the environment variablePICO_PIO_USB_PATH
to the location of this repo.
Note:
Program output is printed to the serial console (GPIO-0 and GPIO-1).
This is the default config. Connect the gamepad to the usb host breakout pins You need to solder the headers yopurself.
git clone https://github.com/fhoedemakers/pico-pio-usb-gamepad-test.git
cd pico-pio-usb-gamepad-test
git submodule update --init
mkdir build
cd build
cmake ..
make
Example: Building for a Raspberry Pi Pico 2 with PIO-USB enabled on an external USB connector (DP+ on GPIO 16, DP- on GPIO 17):
git clone https://github.com/fhoedemakers/pico-pio-usb-gamepad-test.git
cd pico-pio-usb-gamepad-test
git submodule update --init
mkdir build
cd build
cmake -DBOARD=pico_sdk -DPICO_BOARD=pico2 -DPIO_DP_PLUS_PIN=16 ..
make
Example: Building for the WaveShare RP2040 PiZero with PIO-USB enabled on USB port labeled PIO USB (DP+ on GPIO 6, DP- on GPIO 7):
git clone https://github.com/fhoedemakers/pico-pio-usb-gamepad-test.git
cd pico-pio-usb-gamepad-test
git submodule update --init
mkdir build
cd build
cmake -DBOARD=pico_sdk -DPICO_BOARD=pico -DPIO_DP_PLUS_PIN=6 ..
make
For boards where you want to use the internal USB controller instead of PIO USB:
git clone https://github.com/fhoedemakers/pico-pio-usb-gamepad-test.git
cd pico-pio-usb-gamepad-test
git submodule update --init
mkdir build
cd build
# For Adafruit Metro RP2350:
cmake -DENABLE_PIO_USB=0 ..
# For Raspberry Pi Pico 2:
cmake -DBOARD=pico_sdk -DPICO_BOARD=pico2 -DENABLE_PIO_USB=0 ..
make
See hid_app.cpp
for the full list of tested controllers. Confirmed working:
- Xbox-style controllers (XINPUT)
- Sony DualShock 4
- Sony DualSense
- (More in source)
- For wiring details and pin assignments, refer to the board documentation and the
CMakeLists.txt
options. - Some low speed devices like keyboards might not work with PIO usb.
- Button labels are displayed in the serial console using a NES controller style:
A, B, Select, Start, Left, Right, Up, Down.
Other buttons are currently not shown.