I am trying to use keyboard on my Arduino nano, but i get this error:
'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
As per the answer in Keyboard.h not found, I tried change the board to Arduino Leonardo, even though the script gets compiled it doesn't get uploaded (keeps on saying uploading for a long time).
This is the code I use:
#include <Keyboard.h>
void setup() {
Keyboard.begin();
}
void loop() {
}
-
4If you also change the board itself, it'll work. The Uno has different MCU and it doesn't have physical USB interface in it.KIIV– KIIV2021年11月08日 07:36:35 +00:00Commented Nov 8, 2021 at 7:36
-
4As said above you cannot use the Keyboard library on the Nano. It just doesn't have the necessary hardwarechrisl– chrisl2021年11月08日 08:00:12 +00:00Commented Nov 8, 2021 at 8:00
1 Answer 1
To convert the comments into an answer:
You cannot (!) use the Keyboard
library on the Arduino Uno/Nano/Mini. It needs a native USB interface to configure it as a HID device, but the Uno/Nano/Mini all use the Atmega328p, which doesn't have a native USB interface. These Arduinos use an additional chip on the board which acts as USB-UART-bridge.
You can compile the code for the Leonardo, because it has a native USB interface. But you cannot (!) upload code, which is compiled for the Leonardo, to an Uno/Nano/Mini. Its a completely different chip.
What to do now: Get an Arduino board which has a native USB interface, for example the Leonardo or the Micro.