problem with code for arduino voltage reading
12 views (last 30 days)
Show older comments
Muhammad Alief Nasarudin
on 2 Jan 2020
Commented: Muhammad Alief Nasarudin
on 6 Jan 2020
Doing a project with pulse sensor on arduino followed a code online it hit an error im unable to understand im still learning matlab at a basic level can anyone help this is the coding error
Undefined function 'readVoltage' for input arguments of type 'matlab.graphics.axis.Axes'.
Error in mypulsesensor (line 85)
data(i) = readVoltage(a,'A0'); % read voltage on pin A0, store as next data point
2 Comments
Geoff Hayes
on 2 Jan 2020
Muhammad - what is variable a in your
data(i) = readVoltage(a,'A0')
? The error message is suggesting that this may be an axes and not the arduino (which you are trying to read from). You may need to post more of your code so that we can see how you have defined variables for the axes and arduino.
Accepted Answer
Geoff Hayes
on 2 Jan 2020
Muhammad - the problem is with this line of code
a = gca;
where you overwrite the arduino assigned variable with the current axes...and so when you reference a again with
data(1) = readVoltage(a,'A0');
the error occurs because now a is the axes. Consider an alternative name for the axes variable (one that perhaps describes what it references)
hCurrentAxes = gca;
plot(time(i-1:i), data(i-1:i)); %draw the line from the last Vout value to the current Vout value
%actual scroller
%Set appropriate axis limits and settings
set(gcf, 'doublebuffer', 'on');
%Avoiding flickering when updating
set(hCurrentAxes,'xlim',[0 dx]);
set(hCurrentAxes,'ylim',[min(50) - 1, max(200) + 1]); %REMEMBER TO CHANGE X AND Y
%Generate constants for use in UI Control intialization
pos = get(hCurrentAxes, 'position');
or just use gca instead.
You could also rename the variable for the arduino "handle" to something that is more descriptive.
More Answers (0)
See Also
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!