I want to connect a USB keyboard to an Arduino Uno and have the Arduino react to the typed input, adding it to a buffer and eventually performing some hashing on the typed data. The code for hashing works fine, I tested it with input from the Serial monitor.
What I can't figure out: Is it actually possible to connect a USB keyboard to the Arduino as input device. Note: I do not refer to using the Arduino as input device, I know that is another common thing people play arround with.
I have tested the approach taken by this article (Connect a USB keyboard with an Arduino) which involves manually pulling the keyboard via the DATA and CLOCK signals of the keyboard. The central assumption of this article is that (some?) USB keyboards still use plain PS2 and can therefore simply be integrated via some easy code. Summary: This does not work with the 2 keyboards that I own. I might buy a cheap, simple keyboard and hope that it magically works...
These are other insights which I have gathered, please tell me if my findings are wrong:
USB is a complex protocol which is not available for Arduino Unos?
Some Arduinos (Micro for example) support USB and can use the official Keyboard library but that does not allow the Arduino to read from a keyboard, just act as one itself.
There are USB shields which handle the rather complex USB logic and translate it in a simpler protocol which then is usable in the Arduino.
Thanks for your replay. I might give the library a try. Otherwise it seems that the general approach of using PS2 keyboards is sensible. I still wonder if it is actually possible to use USB keyboard that way. Seemed dubious to me from the very start...
USB keyboards still support the legacy serial PS/2 protocol. Therefore these can easily used in Arduino projects. Schematic and code below should work with all Atmega AVR based Arduino boards like Uno, Nano, Mega etc.
This is rather an example of how to integrate USB or PS/2 keyboards in a simple and resource-saving way. Therefore there is no support of modifier keys like Shift or Alt there. There is however a fully functional PS/2 library available through the Arduino IDE library manager. There seem to be some newer USB keyboards around, that no more support the PS/2 protocol, though.
USB is a complex protocol which is not available for Arduino Unos?
Some Arduinos (Micro for example) support USB and can use the official Keyboard library but that does not allow the Arduino to read from a keyboard, just act as one itself.
There are USB shields which handle the rather complex USB logic and translate it in a simpler protocol which then is usable in the Arduino.
All of those findings are accurate.
If you just want a way to connect a "modern keyboard" to an Arduino, it might be simpler to look into Bluetooth keyboards. Arduino boards that support BT "natively" are more common than those that support USB Host, and I think BT "Shields" or modules are cheaper and more common than USB Host shields.