The following code works well and I do get the ASCII clicked on the keyboard. However, as the code uses the OnKeyDown event, the UNO is not getting what might be stored in the keyboard's buffer, even as a result of a key being constantly pressed.
The project requires to connect the shield to a USB device that sends ASCII strings as a keyboard emulator, apparently without the key up/down state, therefore the UNO must read whatever being sent.
My questions:
How to modify the code so it reads whatever the HID sends regardless of keys state?
The UNO need to send the data to a MKR-WIFI-1010's Serial1 interface. What is the best method to send the information from the UNO, should I connect to TX/RX in parallel to my dev PC or I should implement SoftwareSerial for second interface? maybe something else?
Thanks!
#include <hidboot.h>
#include <usbhub.h>
class KbdRptParser : public KeyboardReportParser {
protected:
void OnKeyDown (uint8_t mod, uint8_t key);
};
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) {
uint8_t c = OemToAscii(mod, key);
if (c) Serial.print((char)c);
}
USB Usb;
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
KbdRptParser Prs;
void setup() {
Serial.begin( 115200 );
while (!Serial);
Serial.println("Start");
if (Usb.Init() == -1) Serial.println("OSC did not start.");
delay( 200 );
HidKeyboard.SetReportParser(0, &Prs);
}
void loop() {
Usb.Task();
}
ninora:
The following code works well and I do get the ASCII clicked on the keyboard. However, as the code uses the OnKeyDown event, the UNO is not getting what might be stored in the keyboard's buffer, even as a result of a key being constantly pressed.
I do not understand this. Connect a plain USB keyboard to the USB host shield. If the USB keyboard A key is pressed, does 'a' appear on the serial console? If so, it is working correctly. What happens if you press and release the A key then press and release the B key? 'ab' should appear on the serial console.
If the keyboard emulator device does not work, it may be because the device needs a custom USB host driver.
gbafamily:
I do not understand this. Connect a plain USB keyboard to the USB host shield. If the USB keyboard A key is pressed, does 'a' appear on the serial console? If so, it is working correctly. What happens if you press and release the A key then press and release the B key? 'ab' should appear on the serial console.
If the keyboard emulator device does not work, it may be because the device needs a custom USB host driver.
Pressing any key on the a standard PC keyboard generates the expected code on the console.
The card reader is not generating any character probably because it is not acting as a pure keyboard, I can only assume it is not firing the onKeyDown / onKeyUp events, it is just sending a string as you would expect from such device.
The card reader works perfectly when connected to a PC and requires no special driver (confirmed through Device Manager).
The only other thing I can think to try is to power the Uno using the barrel jack (black round connector). The USB card reader may not be receiving enough power when the Uno is powered through its USB connector.
gbafamily:
The only other thing I can think to try is to power the Uno using the barrel jack (black round connector). The USB card reader may not be receiving enough power when the Uno is powered through its USB connector.
Already done, your assumption is correct and that's why I am using external power. I also know the reader works as it beeps and change the led color in response to successful card reading.
This is a software issue, how to use the library to make a reading without waiting for key down event.
I write here because I try to understand how works the buffer of this library. To launch in my question... I am working in a project using [USB_Host_Shield_2.0 library]. I connect my host shield and Arduino MEGA (both official) with a customized USB Hub Device (Device Class Interface: HID (0x03) and FullSpeed) which just sends 64B packages. I just want to watch on Serial Monitor of Arduino IDE the data buffer that the device send, so I have been studying HIDUniversal and HIDComposite library (and all their hereditance) for several months and using [USBHIDMultimediakbd.ino] example (I used others before to study them).
I try to modify this example for my purpose.
My question is: What variable contains the buffer of data that Device sends?
It seems to my that there are two variables that could contain all the buffer: buf from hiduniversal.Init or hidcomposite.Init and data from Usb.InTransfer .
I trust you know how it works because the project of this post is running properly.
Thanks!
Cas
(P.S: Yes, I read all USB Host 2.0 library's documentation generated by GitHub and I found in Circuits@Home)