1

I'm a day 1 beginner to Arduino, and I am trying to obtain input from a USB keyboard. I've connected the USB keyboard to an Arduino USB host shield attached to an Arduino Uno r3, and I am using the example HID sketch (USBHIDBootKeyboard.ino) provided with the USB Host Shield libraries : https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino

I am powering the Arduino Uno r3 + USB Host Shield via USB. Upon init, only Start is written to the Serial Monitor. Tests show that SetReportParser exits with 0. Yet the keyboards are silent. I've tried three keyboards, all of which work properly when connected to the computer.

When using USBHidBootMouse.ino with a mouse, movements & buttons are perceived and print messages as intended.

https://www.circuitsathome.com/mcu/hid-support-for-usb-host-shield-library-2-0-released/ states that

Also, it is recommended to use external power supply while working with HID devices – I’ve seen many devices which would refuse to function when Arduino receives power from its USB port only.

EDIT : I tried to test if the power was the issue, so I used a 5V generator with intensity measurement. The results are : the Arduino Uno r3 uses 60mA, the keyboard uses 60 mA, connecting to the serial port uses 40 mA (much to my surprise).

This means the keyboard's power requirements shouldn't be the problem.

Then what would the problem be ? I'm helpless here. If the library linked on the official Arduino site doesn't work, then it should mean i'm using it wrong.

  • You should determine if this works when providing power. If not, then it's more likely a software problem - keyboards and mice as similar, but different, and your keyboard code may not be correct. – Chris Stratton Dec 28 '17 at 18:45
  • You should probably also measure the voltage supplied to the USB peripheral, either at F2 on the board (hopefully a polyfuse not a one-time fuse), especially when loaded by a keyboard. Or you could use one of those inline USB power meters assuming it is one which supports proper data passthrough. – Chris Stratton Dec 28 '17 at 18:48
  • @ChrisStratton It doesn't work when providing power. I've used a generator that supplied a 5V voltage while measuring the intensity : the arduino Uno itself uses 60mA, connecting it to the computer through serial uses 40mA (for a reason I don't understand), and connecting the keyboard uses 60mA. So it means the keyboard uses significantly less than 500mA, which means it's not the problem. So it - should - be a software problem ? But I'm only launching the library example sketch, so it not working is quite surprising. (EDITING OP IN PROGRESS) – Julien BERNARD Dec 28 '17 at 21:05
1

see last paragraph of this page https://github.com/felis/USB_Host_Shield_2.0

it says this:

FAQ

When I plug my device into the USB connector nothing happens?

Try to connect a external power supply to the Arduino - this solves the problem in most cases.

You can also use a powered hub between the device and the USB Host Shield.

You should then include the USB hub library: #include <usbhub.h>

and create the instance like so: USBHub Hub1(&Usb);.

your keyboard may be multiple HID devices with a USB hub to connect them

  • A possibility, though less likely to be coincidentally true for the three keyboards reportedly tried, unless they are all the same and obviously all combo devices. – Chris Stratton Dec 29 '17 at 2:42
  • Thanks, I had missed this. As stated in my other answer, uncommenting the provided commented line "USBHub Hub(&Usb);" made it work for one keyboard, and I hastily thought it would work with others but didn't test it. The keyboard I tried is indeed a keyboard that accepts 2 other USB connections on its shell. The other 2 keyboards are simple keyboards, and the 3 are significantly different. I'm going to test these 2 with a hub instanciated and see if it makes them work. – Julien BERNARD Dec 29 '17 at 13:08
0

I looked for the difference between USBHIDBootMouse & USBHIDBootKbd, and noticed line 100,

USBHub Hub(&Usb);

was commented in the BootKbd side. Uncommenting it got the code to work.

I'm quite unsure how what interpretation to have from this. There should be a reason this line is commented in the library github.

Or maybe it is simply an error. In any case, uncommenting it got the code to work here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.