How to display altitude, temp, and pressure of BMP 280 using Arduino (uno) on Matlab?

2 views (last 30 days)
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
Diego Portillo
Diego Portillo on 21 Apr 2020
Edited: Diego Portillo on 21 Apr 2020
i copied form that link and tried to mess with it but i could do anything with it. Im am working with serial port since it is easier but i still cant figure it out. This is what i have so far.
s = serial ("COM3");
time = 60;
k=1;
while (k<time)

Sign in to comment.

Answers (0)

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!