I was able to figure it out, it was a problem with my ISP (Xfinity). Works fine with no edits on different networks, or at home with the wifi off on my laptop.
Undefined function error for readDistance function within GUI editor
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am using the function readDistance() with an Arduino and HC - SR04 ultrasonic sensor. I have tested it in the command line to ensure my equipment is working and successfully received the distance value. However, for my assignment, I need to create a GUI and get the data there. When I try to use it in the GUI editor, I get the following error: 'Undefined function 'readDistance' for input arguments of type 'double'. '
I am using it in this context:
function CollectDataButtonPushed(app, event)
data = zeros(1e4,1);
t = zeros(1e4,1);
i = 1;
tic
while toc < 10
value = readDistance(app.us);
data(i) = value;
data(i) = data(i) * 100; %convert from m to cm
t(i) = toc;
i = i + 1;
end
plot(app.UIAxes, data);
%writetable(T,filename);
end
I have declared and set up my Arduino and sensor like this:
properties (Access = private)
a % arduino
us % ultrasound sensor
end
app.a = arduino('COM4', 'Uno', "Libraries", "Ultrasonic");
app.us = app.a.ultrasonic('D7','D6');
I have also tried to use the function like the following, but I get an error that says 'Dot indexing is not supported for variables of this type.'
value = app.us.readDistance();
I have tried searching for this error, but all I can find are the pages on how to use the readDistance() function which don't offer specific help.
0 Commenti
Risposta accettata
Più risposte (1)
Hornett
il 17 Set 2024
Hi Marisa,
I understand that you are unable to use the function “readDistance()” with an Arduino and HC - SR04 ultrasonic sensor, I believe that you have defined the ultrasonic object in an incorrect way, to define it correctly you should use the following syntax:
app.us = ultrasonic(app.a, ‘D7’, ‘D6’ ).
In this code snippet,‘app.a’represents the arduino object,'D7'is the trigger pin, and'D6'is the echo pin.
Please find the documentation of the “ultrasonic” function below:
Hope this helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su MATLAB Support Package for Arduino Hardware in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!