Hello all,
I am looking into what Arduino boards can be used as a HID keyboard. Currently I use an Arduino R4 WiFi but I am looking into making this one free for new projects. The example sketch from the keyboard library states that only a Arduino Leonardo, Micro or Due. I now this to be not up to date since my Arduino R4 WiFi works fine. The library page in the Language Reference (link: https://docs.arduino.cc/language-reference/en/functions/usb/Keyboard/) states that a couple more boars can be used (R4, MKR, Gige etc.). Only, if you go to the library's page in Arduino Docs, select 'Arduino' as the maintainer (so its an official Arduino library), look up keyboard, you get this page: https://docs.arduino.cc/libraries/keyboard/?_gl=11an9wvl_upMQ.._gaMTU0MjUzNTkxNi4xNzQ1Mjg3Nzcx_ga_NEXN8H46L5*MTc0NTI4Nzc2OC4xLjEuMTc0NTI4OTE5Mi4wLjAuNTkyMzA5NDgx This page lists a lot more Arduino's boards as HID capable. Including the Arduino Mega and I have two Arduino Mega 2560 available. Only compiling the sketch for an Arduino Mega or Mega 2560 will fail. If I try to compiles the same sketch for an R4, Leonardo, Micro or Due, it compiles successfully as expected.
Question: What info on what Boards can easily be used with the Keyboard library / as a HID device is correct?
Used sketches are uploaded. I simply took my Uno R4 sketch and commended all the stuff that has to do with the LED matrix out, since I expected trouble with making it work on my mega board.
knoppendrukker_loslaten_write_ledMatrixTest.ino (4.4 KB)
knoppendrukker_loslaten_mega.ino (4.4 KB)
I tried compiling the example sketch that comes with the keyboard library for the Arduino Mega / Mage 2560, but this will fail and comes up with the following error message:
In file included from C:\Users\Gebruiker\AppData\Local\Temp\.arduinoIDE-unsaved2025322-9008-10eyesa.x3cf\Serial\Serial.ino:22:0:
C:\Users\Gebruiker\Documents\Arduino\libraries\Keyboard\src/Keyboard.h:29:2: warning: #warning "Using legacy HID core (non pluggable)" [-Wcpp]
#warning "Using legacy HID core (non pluggable)"
^~~~~~~
C:\Users\Gebruiker\AppData\Local\Temp\.arduinoIDE-unsaved2025322-9008-10eyesa.x3cf\Serial\Serial.ino: In function 'void setup()':
C:\Users\Gebruiker\AppData\Local\Temp\.arduinoIDE-unsaved2025322-9008-10eyesa.x3cf\Serial\Serial.ino:28:3: error: 'Keyboard' was not declared in this scope
Keyboard.begin();
^~~~~~~~
C:\Users\Gebruiker\AppData\Local\Temp\.arduinoIDE-unsaved2025322-9008-10eyesa.x3cf\Serial\Serial.ino: In function 'void loop()':
C:\Users\Gebruiker\AppData\Local\Temp\.arduinoIDE-unsaved2025322-9008-10eyesa.x3cf\Serial\Serial.ino:37:5: error: 'Keyboard' was not declared in this scope
Keyboard.write(inChar + 1);
^~~~~~~~
Multiple libraries were found for "Keyboard.h"
Used: C:\Users\Gebruiker\Documents\Arduino\libraries\Keyboard
Not used: C:\Users\Gebruiker\AppData\Local\Arduino15\libraries\Keyboard
exit status 1
Compilation error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
This is obviously not the problem, since the sketch does include the library at the beginning of the sketch. My own sketches produce the same error message. And then a bit more warnings but those are not stopping the sketch from completing compilation.