MATLAB Answers


serial port reading.

Here i submit a matlab program, which read ASCII values from a serial port to which an arduino board is connected.

for i = 0: 10
fclose(instrfindall); %close all serial comms
s=serial('COM25','BaudRate',9600); %start serial port to arduino
fopen(s); %open port
out = fgets(s); %read data from arduino, which waited until start
disp(out) %display arduino data

The program read data successfully,but the problem is, its can't read data synchronously from arduino output port(COM25).(ie, some line of data is missing). kindly give me a solution for this problem and kindly give me a correct code also.


Log in to comment.

1 Answer

Answer by Walter Roberson
on 29 Feb 2012
 Accepted Answer

Do not continually close and open the serial port.

The default for serial ports is to read asynchronously. You have to change the serial port properties to read synchronously.

You have not changed your serial port terminator character, as is needed for arduino. See the MATLAB File Exchange contribution that shows a GUI for interacting with arduino devices.


Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today