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

9 次查看(过去 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
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 中查找有关 Simulink Supported Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by