I'm trying to connect a Teensy 3.6 to a device that provides a Raw HID interface. I've used KurtE's work here: https://forum.pjrc.com/threads/47914-T3-6-USB-Host-Raw-Hid?highlight=USBHost as a starting point. So far, it seems like I'm unable to connect to the device properly.
Here is my code:
I have turned on debug logging in USBHost_t36, and this is what I get on the serial console when I run the code:
I have been able to connect to this device using a simple node.js CLI script, like so:
This script successfully lists all of the HID devices on my machine, and receives data from the target device when it sends it.
The device in question shows up like this in Apple System Profiler:
Any ideas on what I should be doing to connect to this device? Is there a better starting point or example that I should be working from? Thanks!
Here is my code:
Code:
// Simple RawHID Sketch
#include "USBHost_t36.h"
USBHost myusb;
USBHub hub1(myusb);
USBHIDParser hid1(myusb);
USBHIDParser hid2(myusb);
USBHIDParser hid3(myusb);
RawHIDController rawhid1(myusb);
USBDriver *drivers[] = {&hub1, &hid1, &hid2, &hid3,};
#define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
const char * driver_names[CNT_DEVICES] = {"Hub1", "HID1", "HID2","HID3"};
bool driver_active[CNT_DEVICES] = {false, false};
// Lets also look at HID Input devices
USBHIDInput *hiddrivers[] = { &rawhid1};
#define CNT_HIDDEVICES (sizeof(hiddrivers)/sizeof(hiddrivers[0]))
const char * hid_driver_names[CNT_DEVICES] = {"RawHid1"};
bool hid_driver_active[CNT_DEVICES] = {false};
void setup()
{
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.println("\n\nUSB Host Testing");
Serial.println(sizeof(USBHub), DEC);
myusb.begin();
rawhid1.attachReceive(OnReceiveHidData);
}
void loop()
{
myusb.Task();
CheckUSBDeviceStatus();
}
bool OnReceiveHidData(uint32_t usage, const uint8_t *data, uint32_t len) {
Serial.print("RawHID data: ");
Serial.println(usage, HEX);
while (len) {
uint8_t cb = (len > 16) ? 16 : len;
const uint8_t *p = data;
uint8_t i;
for (i = 0; i < cb; i++) {
Serial.printf("%02x ", *p++);
}
Serial.print(": ");
for (i = 0; i < cb; i++) {
Serial.write(((*data >= ' ') && (*data <= '~')) ? *data : '.');
data++;
}
len -= cb;
Serial.println();
}
return true;
}
void CheckUSBDeviceStatus() {
for (uint8_t i = 0; i < CNT_DEVICES; i++) {
if (*drivers[i] != driver_active[i]) {
if (driver_active[i]) {
Serial.printf("*** Device %s - disconnected ***\n", driver_names[i]);
driver_active[i] = false;
} else {
Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
driver_active[i] = true;
const uint8_t *psz = drivers[i]->manufacturer();
if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
psz = drivers[i]->product();
if (psz && *psz) Serial.printf(" product: %s\n", psz);
psz = drivers[i]->serialNumber();
if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
}
}
}
for (uint8_t i = 0; i < CNT_HIDDEVICES; i++) {
if (*hiddrivers[i] != hid_driver_active[i]) {
if (hid_driver_active[i]) {
Serial.printf("*** HID Device %s - disconnected ***\n", hid_driver_names[i]);
hid_driver_active[i] = false;
} else {
Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
hid_driver_active[i] = true;
const uint8_t *psz = hiddrivers[i]->manufacturer();
if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
psz = hiddrivers[i]->product();
if (psz && *psz) Serial.printf(" product: %s\n", psz);
psz = hiddrivers[i]->serialNumber();
if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
}
}
}
}
I have turned on debug logging in USBHost_t36, and this is what I get on the serial console when I run the code:
Code:
reset waited 5
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 1FFF4000
periodictable = 1FFF4000
port change: 14001403
connect
begin reset
port change: 14001005
port enabled
end recovery
new_Device: 1.5 Mbit/sec
new_Pipe
I have been able to connect to this device using a simple node.js CLI script, like so:
Code:
var HID = require('node-hid');
var devices = HID.devices();
console.log(devices)
var device = new HID.HID(1008,69);
device.on('data', function(data) {
console.log(data);
})
This script successfully lists all of the HID devices on my machine, and receives data from the target device when it sends it.
The device in question shows up like this in Apple System Profiler:
Code:
HP Proximity Reader (X3D03A):
Product ID: 0x0045
Vendor ID: 0x03f0 (Hewlett Packard)
Version: 16.00
Speed: Up to 12 Mb/sec
Manufacturer: Hewlett-Packard
Location ID: 0x14100000 / 19
Current Available (mA): 500
Current Required (mA): 100
Extra Operating Current (mA): 0
Any ideas on what I should be doing to connect to this device? Is there a better starting point or example that I should be working from? Thanks!