Serial vs raw HID vs something else?

Status
Not open for further replies.

kwaegel

Member
I'm using a Teensy 3 to drive a 9-DOF accelerometer (see my previous thread here).

I need to get the data back to my host system as quickly as possible (low latency), but Serial.print() has the overhead of converting everything to ASCII strings. Raw HID looks better, but I'd have to break things into bytes. Is there any sort of middleware library that makes it easy to send larger primitives back to the host system?

I could write one myself, but I'd wanted to check if someone had already invented this wheel first.
 
I need to get the data back to my host system as quickly as possible (low latency), but Serial.print() has the overhead of converting everything to ASCII strings.

You can use Serial.write(buffer, length) to send binary data very efficiently.
 
Huh. I most have overlooked that. I only notice Serial.write(byte) when I was reading the docs.

All the same, though, you have some nice HID sample code here and it seems a shame not to use it. I was also thinking of shrinking the USB packet size to 22 bytes to avoid buffering on the sending side.

HID also looks easier to set up, after wading through all the Win32 comm documentation and scanning for the correct port...
 
I agree about HID versus Serial. Seems way easier from a user perspective. There's a bunch of really nice libraries, for instance from node.

I've been using JSON to encode the data. This is perhaps a bit more heavyweight than necessary, but there's lots of good libraries to parse JSON and it allows arbitrary sized messages. Most JSON libraries have a method that will let you know if they have not yet received a complete JSON struct.

I also have JSON parsing working to receive data FROM the host (in my case over MIDI sysex) using the awesome jsmn library.

Code is here.

-c
 
Status
Not open for further replies.
Back
Top