ESP32 S3 Board - HID.h error

I'm looking to build a Bluetooth & USB HID keyboard by using an ESP32 S3 board (USB C). So I got some help compiling this code as i'm no expert.
But I keep getting an HID.h error. No matter what libraries are installed this error persists. So not sure if it's because a board incompatibility or bad code.

Obviously the board works fine and have tested it with basic blinking LED sketches.

Any help would be appreciated. Thanks

Here is the persistent error:

/Documents/Arduino/libraries/Keyboard/src/Keyboard.h:25:10: fatal error: HID.h: No such file or directory
#include "HID.h"
^~~~~~~
compilation terminated.
exit status 1

Compilation error: exit status 1

#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEHIDDevice.h>
#include <BLECharacteristic.h>
#include <Keyboard.h>

BLEServer *pServer;
BLEHIDDevice *hid;
BLECharacteristic *inputKeyboard;

const int keyPins[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
const uint8_t keyCodes[] = {
  KEY_LEFT_CTRL, KEY_LEFT_SHIFT, KEY_LEFT_ALT, KEY_LEFT_GUI, // Pins 1-4
  KEY_RIGHT_CTRL, KEY_RIGHT_SHIFT, KEY_RIGHT_ALT, KEY_RIGHT_GUI, // Pins 5-8
  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', // Pins 9-19
  'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't' // Pins 20-29
};

void setup() {
  for (int i = 0; i < 20; i++) {
    pinMode(keyPins[i], INPUT_PULLUP);
  }

  BLEDevice::init("");
  pServer = BLEDevice::createServer();
  hid = new BLEHIDDevice(pServer);
  inputKeyboard = hid->inputReport(1);
  hid->manufacturer()->setValue("Manufacturer");
  hid->pnp(0x02, 0xe502, 0xa111, 0x0210);
  hid->hidInfo(0x00, 0x01);
  hid->reportMap((uint8_t*)_hidReportDescriptor, sizeof(_hidReportDescriptor));
  hid->startServices();

  BLEAdvertising *pAdvertising = pServer->getAdvertising();
  pAdvertising->setAppearance(HID_KEYBOARD);
  pAdvertising->addServiceUUID(hid->hidService()->getUUID());
  pAdvertising->start();
}

void loop() {
  for (int i = 0; i < 20; i++) {
    if (digitalRead(keyPins[i]) == LOW) {
      sendKeyPress(keyCodes[i]);
      delay(50);
      while (digitalRead(keyPins[i]) == LOW);
      sendKeyRelease();
      delay(100);
    }
  }
}

void sendKeyPress(uint8_t keyCode) {
  Keyboard.press(keyCode);
}

void sendKeyRelease() {
  Keyboard.releaseAll();
}

From the Keyboard reference page:

As you can see, generic ESP32 boards are not on Keyboard's (nor HID's) supported list.

The HID library is an "it's installed with the core" library. Like SPI, or Wire, it's specific to its core. The AVR core has it, as does SAM, SAMD and Renesas Uno. The ESP32 core doesn't. So you're not going to be able to use that sketch with your board.

I was hoping it wasn't this. Thanks for confirming.

Hi @timonycat. You can learn how to make your ESP32-S3 board emulate a keyboard by studying the examples listed under the File > Examples > USB > Keyboard menu in Arduino IDE.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.