Arduino USB
I want to write an Arduino Sketch (if there is no other possibility it can also be plain c) , to grab keyboard inputs from my ordinary USB keyboard. Preferably without expensive hardware, but as mentioned, if there is no other possibility, this will do it too.
Is this possible with V-USB? I looked a their website, but it seems like this only supports being slave and to imitate a keyboard.
-
3The USB host shield is what you want.Majenko– Majenko05/18/2017 14:54:36Commented May 18, 2017 at 14:54
-
2PS2 is a whole lot easier. And most usb-keyboards tend to also "speak" PS2, but you millage may vary. This way you don't need any USB host shield. See playground.arduino.cc/Main/PS2Keyboard and pinouts.ru/InputCables/usb_ps2_mouse_pinout.shtml for the pinout.Gerben– Gerben05/18/2017 15:16:20Commented May 18, 2017 at 15:16
-
@Majenko does it again. That USB Shield is great. arduino.cc/en/Main/ArduinoUSBHostShieldSDsolar– SDsolar05/19/2017 06:11:09Commented May 19, 2017 at 6:11
2 Answers 2
As suggested in the comments, you have two options:
As suggested by Majenko, you can use the Arduino USB Host Shield: Picture of USB Host Shield
Alternatively you could use a PS2 keyboard instead (as suggested by Gerben). Arduino already has a library to handle PS2 keyboards, so the implementation of it would be easy. For reference (and example program) playground.arduino.cc/Main/PS2Keyboard
If you do not have access to a PS2 keyboard or just want to use a USB keyboard, Gerben further suggests that most USB keyboards can be converted to PS2 keyboards with an adapter: USB to PS2 adapter
The keyboard must be able to support both formats (USB & PS2).
The following webpage shows the connections needed to go from USB to PS2: USB to PS/2 adapter pinout
-
Gerben & Majenko, let me know if you would like to post your own answer and I will remove your content from my answer. Otherwise thank you for your suggestions in the comments and I hope I have done your suggestions justice.sa_leinad– sa_leinad05/18/2017 16:29:54Commented May 18, 2017 at 16:29
I am able to use this library: https://github.com/techpaul/PS2KeyAdvanced and USB's data +/- connected to pins 2+3 of an arduino to read keys on standard keyboards.
keyboard.begin( 3, 2); // D3= data+, D2= data-
A standard keyboard is one which doesn't need a driver to work on any computer. I'd tried several libraries, serial keyboard adapters, and ps2/usb converters, and this method works best. Since the ps2-USB converter is just a physical pin change with no logic, standard USB keyboards just magically with with the PS2 libraries; even caps lock and what not...