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

2 views (last 30 days)
I have been using the 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 an error:
"Error in try2 (line 35)
dat1=readTemperature();%unkown pin"
I dont know if we have to use simulink or if we must run Arduino software at the same time.
Please help me.
Thank you.

Answers (1)

Vimal Rathod
Vimal Rathod on 26 Apr 2020
Hi,
You have to establish an I2C channel connection after connecting the arduino and the required parameters like temperature, pressure and altitude should be read and write in that channel itself.
Refer to the following link which describes the example for temperature reading from arduino. You can modify your code appropriately to suit your needs.

Categories

Find more on 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!