3

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.

mpromonet
  • 127
  • 6
  • 3
    The USB host shield is what you want. – Majenko May 18 '17 at 14:54
  • 2
    PS2 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 http://playground.arduino.cc/Main/PS2Keyboard and http://pinouts.ru/InputCables/usb_ps2_mouse_pinout.shtml for the pinout. – Gerben May 18 '17 at 15:16
  • @Majenko does it again. That USB Shield is great. https://www.arduino.cc/en/Main/ArduinoUSBHostShield – SDsolar May 19 '17 at 06:11

2 Answers2

3

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

Pinout connection

sa_leinad
  • 3,118
  • 1
  • 20
  • 49
  • 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 May 18 '17 at 16:29
2

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...

dandavis
  • 1,037
  • 9
  • 12