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
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Marisa Assink
el 8 de Oct. de 2023
Respondida: Hornett
el 17 de Sept. de 2024
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 comentarios
Respuesta aceptada
Más respuestas (1)
Hornett
el 17 de Sept. de 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 comentarios
Ver también
Categorías
Más información sobre Modeling en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!