1

Edit: What I'm looking for is some kind of library which could be used with an arduino to read the HID protocol output from the Data+ and Data- cables of the USB.

========== If I cut the cable of a usb keyboard, plug in power and ground can I use the clk and data wires to read keystrokes into the Arduino? If so any pointers to libraries and schematics?

Simple I instructions? The "for dummies" version?

EDIT

Following some of the suggestions below I found this:

https://github.com/julianschuler/USBKeyboard

Which looks like what I want to do, basically hook up the lines into the arduinio and read from the keyboard using the HID protocol in this library.

EDIT 2

That doesn't do what I want. Does anyone know how this could be accomplished?

asked Apr 12, 2021 at 17:34
7
  • From what device do you want to read keystrokes? from an USB keyboard? Commented Apr 12, 2021 at 17:35
  • yes from the keyboard. Commented Apr 12, 2021 at 18:27
  • I think you can do this using an USB Host shield. Commented Apr 12, 2021 at 18:36
  • Which looks like what I want to do ... no it isn't ... read it again Commented Apr 12, 2021 at 20:26
  • If it is possible to make an AVR bit-bang the USB protocol as a device, it may also be possible as a host. Have you tried to find such a library or project? Commented Apr 15, 2021 at 9:01

1 Answer 1

3

USB doesn't have data and clock lines. It has a pair of data lines with inverted polarity (D+ and D-). The USB protocol is considerably more complex than you seem to imagine.

However there is a caveat: some keyboards have the ability to work in IBM PS/2 mode. For this you will need a USB to PS/2 adaptor (pictured below) and then use the PS2Keyboard.h library. Your mileage may vary, though, as not all keyboards will work.

enter image description here

answered Apr 12, 2021 at 18:10
4
  • Any place I can get information on this protocol? I don't want the adapter, I want to plug in the cables directly and manipulate the data. Commented Apr 12, 2021 at 18:28
  • 1
    I think you don't actually need the adapter. It should just connect the pins of the USB jack to the pins of the PS/2 plug. So you could just directly connect the lines to the Arduino. A very short google search gave some promising results Commented Apr 12, 2021 at 18:38
  • These adapters only work if the USB keyboard has a dual controller which understands the PS2 protocol as well as the HID USB protocol. (Most modern keyboards don't) I don't have one of those, and I am looking for a library or method for directly interfacing the HID protocol with an Arduino. Commented Apr 14, 2021 at 22:01
  • 1
    Then you will need to invest in a usb host shield. Commented Apr 14, 2021 at 22:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.