How to display altitude, temp, and pressure of BMP 280 using Arduino (uno) on Matlab?
2 views (last 30 days)
Show older comments
I have use this code:
a=serial('COM3','BaudRate',9600);
%create the coordinate axis
plotTitle='Test';
xLabel = 'Elapsed Time (s)'; % x-axis label
yLabel = 'Temperature (C)';
legend1='Temperature';
legend2='Pressure';
legend3='alitude';
yMax=40 ;
yMin=0;
min = 0;
max = 40;
delay=.01;
%function variables
time=0;
data1=0;
data2=0;
data3=0;
count=0;
%plot set up
plotGraph=plot(time,data1,'-r' );
hold on
plotGraph1=plot(time,data2,'-b')
plotGraph2=plot(time, data3,'-g' )
title(plotTitle,'FontSize',15);
xlabel(xLabel,'FontSize',15);
ylabel(yLabel,'FontSize',15);
plotGrid = 'on';
legend(legend1,legend2,legend3);
axis([yMin yMax min max]);
grid(plotGrid);
tic
%loop
while ishandle(plotGraph) %when plot is active will run until plot is closed
dat1=readTemperature();%unkown pin
dat2=pressure;%unkown pin
dat3=altitude;%unkown pin
count=count+1;
time(count)=toc;
data1(count)=dat(1);
data2(count)=dat(2);
data3(count)=dat(3);
set(plotGraph,'XData',time,'YData',data);
set(plotGraph1,'XData',time,'YData',data1);
set(plotGraph2,'XData',time,'YData',data2);
axis([0 time(count) min max]);
%Update the graph
pause(delay);
end
delete(a);
but i get and error:
"Error in try2 (line 35)
dat1=readTemperature();%unkown pin"
Im also not sure if we have to use simulink with the code.
Please explain in detail.
Thank you.
3 Comments
Geoff Hayes
on 21 Apr 2020
Is this your code or have you copied the code from https://www.mathworks.com/matlabcentral/answers/443562-plot-bmp280-data-temperature-altitude-and-air-pressure-to-matlab-via-arduino?
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!