I have and arduino uno board with a USB Host Shield attached to it. I am hoping to take inputs from a keyboard attached to the USB host shield in order to run a function. For example, I click a on the keyboard and some servos move into one position. Is it possible to do that?
It is a great video, I used it before I made this forum post. The issue I was having was that he displays the inputs directly to a little screen. I'm not sure how to translate an input from the keyboard into an if statement.
In the USBHIDMultiMediaKbd example, I think you would put your code in HIDSelector::ParseHIDData().
I'm sorry, I don't quite understand what you mean. Would you be able to explain it a little bit more?
Have you connected your USB keyboard to the USB Host Shield and used one of the library examples to see if it worked? Which example, if not the USBHIDMultiMediaKbd example.
My USB keyboard is connected to the USB Host Shield and i used the USB Host Sheild Library 2.0 from the video that you linked above. Should I use the USBHIDMultiMediaKbd instead?
Did you try the library examples that came with the USB Host Shield 2.0 library? Were you able to get input from your keyboard?
I did not try the library examples, where would I find those? I have not been able to get input from my keyboard yet.
The examples are in the Arduino IDE menu under:
File->Examples->LibraryName-
The various "HID" (Human Interface Device) examples are under:
File->Examples->UDB Host Shield Library 2.0->HID
You can also find them in your sketchbook directory under: libraries/USB_Host_Shield_2.0/examples/HID
I don't know if "USBHIDBootKbd", "USBHIDBootKbdAndMouse" or "USBHIDMultimediaKbd" would be most appropriate. Try them all.
Thank you, I'll try those out today. Thank you for all your help
I used the USBHIDBOOTKBD one as it seemed to be working the best, but when I type into the serial monitor it comes out as different as a combination of symbols. For example, I pressed A several times and it output a bunch of backward question marks, squares, and three apostrophes. Is that what it is supposed to be doing?
What do you mean by "type into serial monitor"? Do you when you type on your USB keyboard?
Sounds like a baud rate mismatch. Did you set Serial Monitor to 115200 as they set in setup() of the example?
Sorry, I did mean when I type on the USB keyboard. The serial monitor was set to 115200 though, I was just using the default code to try and get correct inputs first
No. It's supposed to be showing the received HID messages in hexadecimal. I don't know why your Serial Monitor would be spouting nonsense. Usually, that is a baud rate mismatch but you say Serial Monitor is set to 115200. You could try other baud rates to see if any of them produce readable results.
So, I tried the serial monitor at 9600 and it doesn't display nonsense, it says like UP >09< DN >15< ASCII: r. Does that mean anything?
9600 is the only one I have found so far that isn't complete giberish.
0x15 is the USB Key Code for the "r/R" key so it does make sense when that key goes down you would get an ASCII 'r'.
The table of key codes is in this document:
So when I type with the keyboard, the ASCII is displaying the key I pressed, can I make an if statement off the ASCII value?
I recommend changing to the USBHIDBootKbd example. Then you can do whatever you want with the ASCII in:
void KbdRptParser::OnKeyPressed(uint8_t key)
{
Serial.print("ASCII: ");
Serial.println((char)key);
};
I still have no idea why your sketch is sending at 115200 baud but your Serial Monitor only works when you set it for 9600 baud.