Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Serial vs raw HID vs something else?

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    11

    Serial vs raw HID vs something else?

    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.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,171
    Quote Originally Posted by kwaegel View Post
    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.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    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...

  4. #4
    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

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,171
    Opps, the web page was missing any mention of Serial.write(buffer, length). I added it.

    http://www.pjrc.com/teensy/td_serial.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •