Matlab serial interface with Arduino is very slow

I am trying to set a serial link in Matlab using an Arduino board. Reading data from the board is going well. However, writing data to the board takes about a second for each block of information I send.

The code I run to write data is:

s = serial(comprt,'BaudRate',9600,'DataBits',8);
fopen(s);
fprintf(s, '%c', 'c');
fprintf(s, '%u %u %u %u \n', [A B C D]);
pause(1);
fprintf(s, '%c', 'a');
pause(1);

A, B, C, D are 8-bit numbers from 0 to 255, 'c' and 'a' are character commands that do things on the Arduino board and click on the firmware on the board.

If I do not turn on pause commands (1), so when I do not stop Matlab from executing the next command for at least a second, the serial information does not pass.

Can someone help me speed up recording material to the serial port? I checked with the Arduino editor, and when I enter the equivalent commands through their interface, everything is fine. Thus, delays are not related to the Arduino board or device drivers, this is definitely on the Matlab side.

+1
source share
1 answer

I used MATLAB quite a bit with Arduino. Example: see here ( http://www.instructables.com/id/Arduino-to-MATLAB-GUI-Live-Data-Acquisition-Plotti/ ) [see A link in the instructions for my GitHub Arduino and MATLAB code] and here ( https://www.youtube.com/watch?v=wY3oh2GIfCI ).

I believe your problem is on your side of the Arduino.

Add this line to your setup () function:

Serial.setTimeout(100); //this will make the Arduino wait a max of only 100ms per incoming set of serial data, before moving on

: http://arduino.cc/en/Serial/SetTimeout

-, , . , , .

. , Arduino 1 , , , .

. : MATLAB Newline Arduino Serial.readBytesUntil . - , (Ex: 1 ), .

? , , . .

+1

All Articles