I am trying to communicate arduino with matlab. takes data every 10 seconds and program give 'Warning: Unsuccessful read: A timeout occurred before the Terminator was reached..'.How can I this problem ?

3 views (last 30 days)
clc
clear all
delete(instrfindall);
close(instrfindall);
s = serial('COM3');
time=100;
i=1;
while(i<time)
fopen(s)
fprintf(s, 'Your serial data goes here')
out = fscanf(s)
Temp(i)=str2num(out(1:4));
subplot(211);
plot(Temp,'g');
axis([0,time,20,50]);
title('Parameter: DHT11 Temperature');
xlabel('---> time in x*0.02 sec');
ylabel('---> Temperature');
grid
Humi(i)=str2num(out(5:9));
subplot(212);
plot(Humi,'m');
axis([0,time,25,100]);
title('Parameter: DHT11 Humidity');
xlabel('---> time in x*0.02 sec');
ylabel('---> % of Humidity ');
grid
fclose(s)
i=i+1;
drawnow;
end
delete(s)
clear s
  1 Comment
Geoff Hayes
Geoff Hayes on 13 May 2020
Erhan - how are you sending the data? Do you know for sure that it is going over COM3. Also, i don't know if this will fix the problem, but why are you calling fopen on each iteration of the loop? Can't you just do it once outside of the loop?

Sign in to comment.

Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!