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

Thread: Need a higher speed data link to MATLAB

  1. #1
    Senior Member
    Join Date
    Oct 2019
    Posts
    113

    Need a higher speed data link to MATLAB

    I have been using a Teensy 4.1 to send data to MATLAB via the serial link. I have maxed out the link budget and need a new solution. Any advice on data acquisition hardware and MATLAB\OS config that can get me a higher speed datapath?

  2. #2
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    637
    By Serial do you mean the hardware serial or the USB? Are you able to buffer data or do you need it streaming in real-time? Are you sending ASCII characters or binary data?

  3. #3
    Senior Member
    Join Date
    Oct 2019
    Posts
    113
    USB serial presently.
    Ascii.
    I am sending rafts of about 180 characters, so some buffering is already taking place...but after that I need real-time.

  4. #4
    Senior Member
    Join Date
    May 2019
    Posts
    114
    What bitrate do you need? You can try Ethernet which will give you up to 80..90 mbit per second.

  5. #5
    Senior Member
    Join Date
    Oct 2019
    Posts
    113
    I need less than 1Mbit.
    If I use ethernet, I'll need some way to get the data through the OS to MATLAB. That has a number of other moving parts that I'd need to figure out. I'm not sure if anyone has done it.

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,219
    ? The normal Serial does 1MBit with ease.. its laughing about that...given that the USB connection is 480MBit...
    So what's wrong here?
    Even the Teensy LC would be fast enough..

  7. #7
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    637
    Teensy 4 USB hits 480 Mb/s.
    https://forum.pjrc.com/threads/60609...l=1#post236797

    I'm guessing there's maybe some limitation on the MATLAB side. Or some other limitation in the code? In terms of debugging, I think I would try just sending some data to the PC, without MATLAB, to see whether the issue is with MATLAB or potentially some issue with your code.

  8. #8
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,219
    Yup, or the PC is too slow (don't laugh... the Arduino Serial Monitor was too slow.. Paul had to rewrite it)

  9. #9
    Senior Member
    Join Date
    Oct 2019
    Posts
    113
    Perhaps that's good news. I'm operating off the understanding that the USB serial connection to the PC maxes at 115200. So that's just the serial monitor's speed?

  10. #10
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,219
    Yes. You can ignore that setting. Usb Serial is always max speed. The bitrate setting is ignored. It is for compatibility only.

  11. #11
    Senior Member
    Join Date
    May 2019
    Posts
    114
    Matlab has UDP data transfer functions. I have gotten beyond 80mbit with matlab.

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,951
    As a quick speed test, try uploading this program to your Teensy 4.1. Just copy it all into a blank Arduino window and upload.

    https://github.com/PaulStoffregen/US...rint_speed.ino

    Then make sure you have the right serial port selected in Tools > Ports, and open the Arduino Serial Monitor.

    As it runs, you'll see it shows the number of lines per second it's managing to send to the serial monitor. Each line is 33 bytes, so just multiply by 33 to get an idea of how many bytes/sec your Teensy is capable of sending (in a good-if-not-best case scenario).

    In Arduino, you'll see Teensy appears twice in the Tools > Ports menu. If you select the "Teensy port" version, you'll get the optimized serial monitor. You should see much higher speed. The regular "Serial port" version will use the original serial monitor code. Save your work before trying that, as the old serial monitor was too slow to keep up and it can even completely crash the Arduino IDE.

  13. #13
    Senior Member
    Join Date
    May 2019
    Posts
    114
    Real-time means time-deterministic. You should specify ur max allowed latenctly, which is not the same as saying real-time.

  14. #14
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,219
    My old pc shows 872048 - Windows, with a linux VM running, IP HD-TV on a second screen, and some other programs in the background.
    (Seems too slow for the Teensy..the Arduino Serial monitor crashed, again..)

    @tschrama: yes, it may be needed to add wait-loops to get fixed time intervals. Or other techniques.
    Even 1 Byte per second can be real-time, if it's defined that way.

  15. #15
    Senior Member
    Join Date
    May 2019
    Posts
    114
    BTW. Using UDP or Serial is almost the same in MATLAB.

  16. #16
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,951
    Quote Originally Posted by Frank B View Post
    My old pc shows 872048 - Windows, with a linux VM running, IP HD-TV on a second screen, and some other programs in the background.
    (Seems too slow for the Teensy..the Arduino Serial monitor crashed, again..)
    872048 lines/sec is really fast, over half of the theoretical 480 Mbit/sec bandwidth! (taking USB protocol overhead into account)

    And yeah, I did the best I could with about 2 months work on the serial monitor. It's still not up to the task of these speeds. My Java skills only go so far...

  17. #17
    Senior Member
    Join Date
    Oct 2019
    Posts
    113
    ...looks like I goofed a reply. Resend...
    The speed test shows between 420000 and 450000 using a Windows 10 desktop. The math indicates I have enough headroom for the use case if MATLAB cooperates. Thanks!
    @Paul: Thanks for the details on the IDE idiosyncrasies, it explains a lot. I have to bring people up on Teensy+IDE from scratch in the near future, so those little items are pure gold to me right now.
    @tschrama: I suspect UDP is easily supported in libraries...any advice on hats\shields to make connections neat?

  18. #18
    For the record, I started a thread on this topic here. I'm currently using a workaround on the MATLAB side that loops the serial read and write functions with no more than 200 bytes per read or write. The effective data transmission rate is ~20Mbps using PsychToolbox IOPort instead of MATLAB's builtin Java-based serial interface. I'll post again if I manage to improve this. I'm also going to reach out to Mathworks to find out whether they have any interest in supporting 480Mbps serial ports - but I don't expect much.

Posting Permissions

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