How to use QTPY ESP32-S2 as a USB Controller

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Caducation
 
Posts: 16
Joined: Tue Mar 02, 2021 7:09 pm

How to use QTPY ESP32-S2 as a USB Controller

Post by Caducation »

Hi, I am trying to get my QTPY ESP32-S2 to register as a USB device for use as a joystick/controller.

https://learn.adafruit.com/adafruit-qt- ... 2/overview

The product info states this version of the QTPY can be used as a USB device which is the main reason for choosing it.

I installed the ArduinoJoystick Library v2.0 in hopes to use Joystick.X() to relay and set up a single axis as a test in Windows USB Game Controller Setup.

https://github.com/MHeironimus/ArduinoJoystickLibrary

So far none of the samples or my test code will compile because they are missing PluggableUSB.h.
"Arduino\libraries\ArduinoJoystickLibrary-version-2.0\src/DynamicHID/DynamicHID.h:37:12: fatal error: PluggableUSB.h: No such file or directory
#include "PluggableUSB.h"
^~~~~~~~~~~~~~~~
compilation terminated."

Here is one of the shortest example codes from the library

Code: Select all

// Simple example application that shows how to read four Arduino
// digital pins and map them to the USB Joystick library.
//
// Ground digital pins 9, 10, 11, and 12 to press the joystick 
// buttons 0, 1, 2, and 3.
//
// NOTE: This sketch file is for use with Arduino Leonardo and
//       Arduino Micro only.
//
// by Matthew Heironimus
// 2015-11-20
//--------------------------------------------------------------------

#include <Joystick.h>

Joystick_ Joystick;

void setup() {
  // Initialize Button Pins
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);

  // Initialize Joystick Library
  Joystick.begin();
}

// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 9;

// Last state of the button
int lastButtonState[4] = {0,0,0,0};

void loop() {

  // Read pin values
  for (int index = 0; index < 4; index++)
  {
    int currentButtonState = !digitalRead(index + pinToButtonMap);
    if (currentButtonState != lastButtonState[index])
    {
      Joystick.setButton(index, currentButtonState);
      lastButtonState[index] = currentButtonState;
    }
  }

  delay(50);
}
PluggableUSB.h and .cpp are listed in the core API for arduino (Found here https://github.com/arduino/ArduinoCore-API), none of the sample code directly includes it as it is called from Joystick.h. Even including it fails to compile because it is non-existent. All the info I can find relating to this problem seems to point back to the board manager and installing various boards that aren't the one I am using.

So my questions:
1. Can this QTPY be used as a USB Keyboard/Controller?
2. Is there a specific setting or option I should be looking for in the Arduino IDE to note using as a USB device?
3. Is PluggableUSB.h missing and should be in the core ide by default? The joystick library calls DynamicHID.h which references PluggableUSB.h but it is not in any core library. I just updated the IDE to 2.0.3 and updated all my libraries and board definitions so it should all be current.

Thank You!

User avatar
Caducation
 
Posts: 16
Joined: Tue Mar 02, 2021 7:09 pm

Re: How to use QTPY ESP32-S2 as a USB Controller

Post by Caducation »

I believe the piece of the puzzle that was missing was the Adafruit Tiny_USB Library.
https://github.com/adafruit/Adafruit_TinyUSB_Arduino

With this library I am able to see the QTPY as a controller via the Windows Game Controller Setup and pass info to it. If I find out more I will update this thread.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”