This should be easier.. Arduino Nano HID

Hey guys,

Someone wrote somewhere that the Arduino can serve as Human Interface Device.
So I started experimenting. Doing a Mouseclick or some movement worked. But Keyboard...

What I have done:
Using an Arduino Nano via USB

  1. I register the library "Keyboard" (version 1.0.5)
  2. I imported the library "Keyboard"
  3. I wrote my script
  4. I see an Error message, that I dont understand.

This is the Script:

#include <Keyboard.h>

void setup() {
  Serial.begin(9600);
  Keyboard.begin();
}

void loop() {
  Keyboard.press('a');
  delay(100);  
  Keyboard.release('a'); 
  delay(5000);

  Keyboard.press('b');
  delay(100);
  Keyboard.release('b');
  delay(5000);

  Keyboard.press('c');
  delay(100);
  Keyboard.release('c');
  delay(5000);
}

and this is the error message:

C:\Users\SFoX\Documents\Arduino\test\test.ino: In function 'void setup()':
C:\Users\SFoX\Documents\Arduino\test\test.ino:5:3: error: 'Keyboard' was not declared in this scope
Keyboard.begin();
^~~~~~~~
C:\Users\SFoX\Documents\Arduino\test\test.ino: In function 'void loop()':
C:\Users\SFoX\Documents\Arduino\test\test.ino:10:3: error: 'Keyboard' was not declared in this scope
Keyboard.press('a');
^~~~~~~~

exit status 1

Compilation error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

I have no Idea, why this isnt working.

From Keyboard - Arduino Reference

The keyboard functions enable 32u4 or SAMD micro based boards to send keystrokes to an attached computer through their micro’s native USB port

The Nano does not have a suitable microcontroller and hence no native USB port

What model of Nano? There are many different Nano models these days, it's very confusing.

If you mean the "classic" Nano V3 (atmega328) then you are out of luck. This type can't be HID.

If you want something of a similar size and inexpensive, try Arduino Micro or Sparkfun Pro Micro (don't confuse with Pro Mini) or a clone of one of those models.

Its an AZ-Nano V3-Board Atmega328 CH340

Yep. Won't do HID.

which one is the next bigger Arduino that has HID functionallity? Got an (original) "Arduino Nano Every" somewhere, will this one do it?

Did you read the link posted by @UKHeliBob ? It's a little out of date because there are other chips used in Arduino boards that will also do HID these days, but not all. Look for one based on a chip which has the "native USB" feature.

Why do you need something "bigger" than Micro?

Unlucky again, as far as I can figure.

If you want a small formfactor and don't need many IO-pins

The SAMD21 Seeeduino XIAO.
Seeeduino offers more microcontrollers which are called "XIAO" so you have to carefully look if it is a SAMD21-type

USB is high-speed (even at USB2.0) and a pretty complex protocol.

Remember just plug in anything and it rows up functioning with a lot of different devices all using the one and the same bus.

This requires to obey a lot of standards at high speed. The easyness of use for the consumer is bought with high complex silicon just for making the USB-bus work. The older microcontrollers just don't have this complex USB-logic inside.

best regards Stefan

Thank you guys very much. Very Helpfull.
I just brought this SAM21 device.

But you said

The XIAO is smaller, not bigger, than Nano. How will it meet your needs?

Smaller in number of pins, bigger in memory and CPU power.

1 Like

@westfw True. We still have little idea of what @glitchminister needs, other than something with native USB.

Wait, how can that have worked if you are using Nano V3? The Mouse library won't compile on Nano, same as Keyboard library, will it?

Hmm. There used to be serial mice. Can you tell your pc you have one of those, and have a serially connected arduino send appropriate codes?

1 Like

I remember PS2 sockets for keyboard & mouse. They were just serial ports, I think. They were colour coded, as were the plugs on mice & keyboards, so I guess their purpose was configured in the operating system and they were not "Universal".

I don't think there is a way to detect the difference between PS2 keyboards or PS2 mice.
I still use them with Arduino.

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