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

7 vues (au cours des 30 derniers jours)
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);

Réponses (1)

Urmila Rajpurohith
Urmila Rajpurohith le 4 Mai 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!

Catégories

En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by