ctadlock
Active member
We have connected a USB HID keyboard device (think barbode scanner) to a Teensy 4 via the underside D-/D+ pins and are using PaulStoffregen/USBHost_t36. We have configured the device so it returns the following characters when a button is pressed. This works as expected when connected to Windows. However when we read the data from code on the Teensy we get unexpected data. We are in contact with the device manufacturer and they say they are using a standard keyboard.
So whats the issue? Is the code wrong? Are we not processing the data correctly?
EXPECTED / Windows
ACTUAL / Teensy
Teensy Code
So whats the issue? Is the code wrong? Are we not processing the data correctly?
EXPECTED / Windows
Code:
-045DD30AA84880;
ACTUAL / Teensy
Code:
Byte received (hex): 0
Byte received (hex): 5F
Byte received (hex): 29
Byte received (hex): 40
Byte received (hex): 24
Byte received (hex): 44
Byte received (hex): 5E
Byte received (hex): 42
Byte received (hex): 21
Byte received (hex): 41
Byte received (hex): 21
Byte received (hex): 24
Byte received (hex): 45
Byte received (hex): 29
Byte received (hex): 29
Byte received (hex): 29
Byte received (hex): 3A
Byte received (hex): 0
Teensy Code
C:
#include <USBHost_t36.h>
// Create USB host object
USBHost myusb;
USBHIDParser hid1(myusb);
KeyboardController keyboard(hid1);
// Callback function to handle when a key is pressed
void keyPressed() {
uint8_t rawKey = keyboard.getKey(); // Get the raw byte from the device
// Print the byte as hexadecimal
Serial.print("Byte received (hex): ");
Serial.print(rawKey, HEX);
}
void setup() {
// Initialize Serial communication
Serial.begin(9600);
while (!Serial); // Wait for Serial to connect
// Initialize USB
myusb.begin();
// Attach the key press callback
keyboard.attachPress(keyPressed);
}
void loop() {
// Process USB events
myusb.Task();
}