I am working on a project using an ESP32C3 to emulate a keyboard. I have included the arduino Keyboard library in my ini file, but build fails on failing to find HID.h. I cannot find out how to install any HID library.
The Arduino-ESP32 features no HID.h library. Still, USB keyboard or mouse functionality is available as USBHIDKeyboard.h
.
Max, thank you for your response. Perhaps you could assist me further.
My main.cpp is as follows:
#include Arduino (within angle brackets, of course)
#include “USBHIDKeyboard.h”
#include “USB.h”
USBHIDKeyboard Keyboard:
void setup() {
Keyboard.begin();
USB.begin();
}
void loop() {}
Executing Platformio Build, the compiler reports ‘USBHIDKeyboard’ does not name a type, and, unsurprisingly, that Keyboard and USB were not declared in this scope.
Any thoughtn
Whats your exact platformio.ini
?
Again, thank you for taking the time for this.
Platformio.ini:
[env:seeed_xiao_esp32c3]
platform = espressif32
board = seed_xiao_esp32c3
framework = arduino
Also, in anticipation:
PACKAGES:
- framework-arduinoespressif32 @ 3.20009.0 (2.0.9)
- tool-esptoolpy @ 1.40501.0 (4.5.1)
- toolchain-riscv32-esp @ 8.4.0+202lr2-patch5
You’re on an old version, update to espressif32 6.6.0.
CLI →
pio pkg update -g -p espressif32
or platform = espressif32@6.6.0
in the pltaformio.ini
Hi Max!
Well…
platformio.ini:
; PlatformIO Project Configuration File
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
; Please visit documentation for the other options and examples
; Redirecting...
[env:seeed_xiao_esp32c3]
platform = espressif32@6.6.0
board = seeed_xiao_esp32c3
framework = arduino
main.cpp:
#include <Arduino.h>
#include “USBHIDKeyboard.h”
#include “USB.h”
USBHIDKeyboard Keyboard;
void setup() {
pinMode(0, INPUT_PULLUP);
Keyboard.begin();
USB.begin();
}
void loop() {
// put your main code here, to run repeatedly:
}
build:
Executing task: platformio run --environment seeed_xiao_esp32c3
Processing seeed_xiao_esp32c3 (platform: espressif32@6.6.0; board: seeed_xiao_esp32c3; framework: arduino)
Verbose mode can be enabled via -v, --verbose
option
CONFIGURATION: ***
PLATFORM: Espressif 32 (6.6.0) > Seeed Studio XIAO ESP32C3
HARDWARE: ESP32C3 160MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-arduinoespressif32 @ 3.20014.231204 (2.0.14)
- tool-esptoolpy @ 1.40501.0 (4.5.1)
- toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO v6.1 documentation
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies…
Dependency Graph
|-- USB @ 2.0.0
Building in release mode
Compiling .pio/build/seeed_xiao_esp32c3/src/main.cpp.o
Building .pio/build/seeed_xiao_esp32c3/bootloader.bin
Generating partitions .pio/build/seeed_xiao_esp32c3/partitions.bin
esptool.py v4.5.1
Creating esp32c3 image…
Merged 1 ELF section
Successfully created esp32c3 image.
Compiling .pio/build/seeed_xiao_esp32c3/lib4f0/USB/USBHID.cpp.o
Compiling .pio/build/seeed_xiao_esp32c3/lib4f0/USB/USBHIDConsumerControl.cpp.o
Compiling .pio/build/seeed_xiao_esp32c3/lib4f0/USB/USBHIDGamepad.cpp.o
Compiling .pio/build/seeed_xiao_esp32c3/lib4f0/USB/USBHIDKeyboard.cpp.o
Compiling .pio/build/seeed_xiao_esp32c3/lib4f0/USB/USBHIDMouse.cpp.o
Compiling .pio/build/seeed_xiao_esp32c3/lib4f0/USB/USBHIDSystemControl.cpp.o
Compiling .pio/build/seeed_xiao_esp32c3/lib4f0/USB/USBHIDVendor.cpp.o
Compiling .pio/build/seeed_xiao_esp32c3/lib4f0/USB/USBVendor.cpp.o
src/main.cpp:5:1: error: ‘USBHIDKeyboard’ does not name a type
USBHIDKeyboard Keyboard;
^~~~~~~~~~~~~~
src/main.cpp: In function ‘void setup()’:
src/main.cpp:9:3: error: ‘Keyboard’ was not declared in this scope
Keyboard.begin();
^~~~~~~~
src/main.cpp:10:3: error: ‘USB’ was not declared in this scope
USB.begin();
^~~
Compiling .pio/build/seeed_xiao_esp32c3/FrameworkArduino/Esp.cpp.o
*** [.pio/build/seeed_xiao_esp32c3/src/main.cpp.o] Error 1
Oh, my bad, it’s a ESP32C3? That chip does not have a freely programmable USB peripheral. Its function is fixed to USB CDC (Serial) and JTAG.
The ESP32S3 would support it. See all the .skip.X
files in https://github.com/espressif/arduino-esp32/tree/master/libraries/USB/examples/Keyboard/KeyboardMessage to skip the incompatible boards.
Same is said in
Oh well…
Perhaps you could advise me on another matter. I installed VSCode, then installed the Platformio extension which, it was my understanding, would also install the Platformio CLI. But, when I access the Platform Core CLI and enter “pio --help” I am told that ‘pio’ is not found but can be installed with: sudo apt install platformio
???
Don’t install PlatformIO via apt
. You can expose the pio
commands to the regular shell as documented.
https://docs.platformio.org/en/latest/core/installation/shell-commands.html
So, is there a way to get the CLI without apt? (Oh, wait, I wasn’t looking in the page you referenced)
(And, by the way, I do have a couple of S3 boards, and, reconfiguring, I got successful build)