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();
}