How to display altitude, temp, and pressure of BMP 280 using Arduino (uno) on Matlab?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Geoff Hayes
2020-4-21
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?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!