Main Content

readPressure

Read one sample of barometric air pressure data from the sensor

Since R2021a

Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.

Description

[pressureReading,timestamp] = readPressure(pressureSensor) returns one sample of the barometric air pressure measured in Pascals (Pa) along with the timestamp. timestamp is optional.

Note

The readPressure function is available for LPS22HB and BMP280 sensor.

Examples

Read Pressure Data from Sensor

Create an Arduino object and include the I2C library.

a = arduino();

Or, you can explicitly specify it in the Libraries Name-Value pair while creating the Arduino object.

clear a;
a = arduino('COM4', 'Uno', 'Libraries', 'I2C');

Create the sensor object for the sensor in use.

pressureSensor = lps22hb(a);

Return one sample of pressure data.

pressureReading = readPressure(pressureSensor)
pressureReading =
   9.5014e+04

Input Arguments

collapse all

A sensor connection, specified as a lps22hb object.

Output Arguments

collapse all

The barometric air pressure reading from the LPS22HB sensor, specified in Pascals (Pa).

Data Types: double

The time at which MATLAB® receives pressure data from the sensor, specified as a datetime.

Data Types: datetime

More About

collapse all

Code Generation Using MATLAB Function Block

  • Use readPressure in a MATLAB Function block with the Simulink® Support Package for Arduino® Hardware to generate code that can be deployed on Arduino Hardware.

  • Timestamp returned is always in seconds.

Version History

Introduced in R2021a

See Also