Unsuccessfull read: MatLab-Arduino Bluetooth Communication via HC-05 device

조회 수: 7 (최근 30일)
I'm trying to understand why my code returns the message "Warning: Unsuccessful read: A timeout occurred before the Terminator was reached.'Bluetooth' unable to read all requested data." when i set a baud rate different from 9600 in the Arduino Sketch, for my bluetooth istance.
My code below
bt=Bluetooth('HC05',1);
fopen(bt);
stop_rec=0;
h=animatedline('Marker','o');
data=[];
i=1;
while(stop_rec==0)
tic;
a=fscanf(bt,'%s');
ind=find(a==';');
data(i,:)=[str2double(a(1:ind-1)),str2double(a(ind+1:end))];
addpoints(h,i,data(i,1));
drawnow
i=i+1;
flushinput(bt)
flushoutput(bt)
if(i>500)
stop_rec=1;
end
toc;
end
fclose(bt);

답변 (1개)

Urmila Rajpurohith
Urmila Rajpurohith 2021년 5월 4일
Hi
The initialization process on the Arduino board takes a few seconds. "fopen" does not wait until the initialization process finishes.Adding a pause between "fopen" and the following commands may resolve the issue.The input of "pause()" depends on the hardware. Usually, a few seconds would be long enough.
Hope this helps!

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by