Use more than one Teensy with RawHID at once?

Status
Not open for further replies.

low

New member
Hi,

I'm confused about how to use multiple Teensys with RawHID on a host PC at the same time.

Would I simply open all the RawHID communication devices with a single call to rawhid_open() that would enumerate all the devices with the same vid, pid usage_page, and usage? And then use trial and error to figure out which Teensy RawHID is associated with which enumerated device?

Or, would I need to change the usage page and/or usage values in the header files each time I upload code to a particular Teensy, so that each Teensy has a unique usage_page/page value?

Code:
#define VENDOR_ID               0x16C0
#define PRODUCT_ID              0x0480
#define RAWHID_USAGE_PAGE       0xFFAB  // recommended: 0xFF00 to 0xFFFF
#define RAWHID_USAGE            0x0200  // recommended: 0x0100 to 0xFFFF

But then how would I use the rawhid_open()? Would I use rawhid_open() in a separate thread for each Teensy, and use the unique usage page and page values that I defined earlier?

Thanks in advance,
low
 
Last edited:
Assuming you are writing PC code to do this - you might get some tips from the github sources of TyCommander.

I've used that with one HID device - I assume it has code to track multiple HID like it does multiple USB Serial.
 
Thanks for the reply,

I'm trying to get sensor data from two (or more) different Teensys (possibly connected to different USB ports if that helps) using RawHID on each Teensy.

I'm not enough of a C expert to easily understand source code from another project. I was hoping to use the the Host Side Functions written by Paul Stoffregen.

low
 
What have you tried?

When I look at the APIs, it looks like it is setup to handle multiple ones.
int rawhid_open(int max, int vid, int pid, int usage_page, int usage);

Open up to "max" devices that match vid, pid, usage_page and usage. Return is the number of devices actually opened.
So if you pass in lets say 5 as the first parameter, you should be able open up to 5 devices. The number opened is returned from the call.

You can then read from the individual devices: int rawhid_recv(int num, void *buf, int len, int timeout);
You pass in the index to each device as first parameter

As to figure out which one is which... Probably several ways. Could maybe play with PID/VID. Or could setup some simple protocol. Where maybe you have your program on PC send out some query, like: Who are you... And each one returns back some information which tells you what information you need to determine what to do next.
 
Give your devices an ID, and after the the connection is made, have you Teensy devices sent out their ID. It's also worth knowing that each Teensy already has a unique ID burnt into the MCU. Your sketch could read that value and sent it to the host.
 
Status
Not open for further replies.
Back
Top