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 fclose(instrfindall); end
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.
No products are associated with this question.
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.