Need a higher speed data link to MATLAB

Status
Not open for further replies.

kdharbert

Well-known member
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?
 
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?
 
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.
 
What bitrate do you need? You can try Ethernet which will give you up to 80..90 mbit per second.
 
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.
 
? 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..
 
Yup, or the PC is too slow :) (don't laugh... the Arduino Serial Monitor was too slow.. Paul had to rewrite it)
 
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?
 
Yes. You can ignore that setting. Usb Serial is always max speed. The bitrate setting is ignored. It is for compatibility only.
 
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/USB-Serial-Print-Speed-Test/blob/master/usb_serial_print_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.
 
Real-time means time-deterministic. You should specify ur max allowed latenctly, which is not the same as saying real-time.
 
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.
 
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...
 
...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?
 
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.
 
Status
Not open for further replies.
Back
Top