Unsuccessfull read: MatLab-Arduino Bluetooth Communication via HC-05 device
9 views (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
Urmila Rajpurohith
on 4 May 2021
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!
0 Comments
See Also
Categories
Find more on Simulink Supported Hardware 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!