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

9 ビュー (過去 30 日間)
Graziano Messineo
Graziano Messineo 2019 年 12 月 14 日
回答済み: Urmila Rajpurohith 2021 年 5 月 4 日
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 Center および File ExchangeSimulink Supported Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by