Main Content

lps22hb

Connect to LPS22HB sensor on Arduino hardware I2C bus

Description

The lps22hb object reads barometric air pressure and ambient temperature using the LPS22HB sensor connected to the I2C bus of the Arduino® hardware. LPS22HB is used to read barometric air pressure. The LPS22HB also has an embedded temperature sensor. Attach the LPS22HB sensor to the I2C pins on the hardware. You can read the data from the sensor in MATLAB® using the Object Functions.

Creation

Description

pressureSensor = lps22hb(a) creates a sensor object with default property values.

Example: pressureSensor = lps22hb(a);.

pressureSensor = lps22hb(a,Name,Value) creates a sensor object with properties using one or more Name,Value pair arguments.

Example: pressureSensor = lps22hb(a,'I2CAddress',0x5D);.

Input Arguments

expand all

Connection to the hardware specified as an object.

Example: pressureSensor = lps22hb(a) creates a connection to the LPS22HB sensor on the hardware represented as an object, a.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Specify the I2C address of the sensors when multiple I2C devices with the expected address for LPS22HB are connected to the same hardware board. LPS22HB can have two I2C addresses depending on the logic level on pin SA0 of the sensor.

Pin NamePin StateI2C Address
SA0Low0x5C
High0x5D

You can specify the I2C address in:

  • Hexadecimal, decimal, or binary format

  • String of hexadecimal value of I2C Address

  • Character vector of hexadecimal value of I2C Address

Example: pressureSensor = lps22hb(a,'I2CAddress',0x5C)

0x5C is the I2C address of the LPS22HB connected to Arduino board.

If not specified, the object will be created with one of the available I2C device address in the table. Availability of I2C device with the expected address will be determined by using scanI2CBus.

I2C bus number, specified as 0 or 1. The default value is 0.

Example: pressureSensor = lps22hb(a, 'Bus', 1) creates the sensor object on Bus 1 of the hardware.

Data Types: double

Properties

expand all

Note

The properties SampleRate, SamplesPerRead, ReadMode, OutputFormat, TimeFormat, SamplesAvailable, and SamplesRead are available only with the Sensor Fusion and Tracking Toolbox™ and Navigation Toolbox™. These properties can be set while you create the sensor object.

Except for TimeFormat, all the other properties are non-tunable, which means you cannot change their values once the object is locked. Objects are locked when you call the read function, and the release function unlocks them. If a property is tunable, you can change its value at any time.

The rate in samples/s at which data is read from the sensor.

Data Types: double

Number of samples read from the sensor in a single execution of the read function.

Data Types: double

Specify whether to return the latest or the oldest data samples. The number of samples depends on the SamplesPerRead value. The data read from the sensor is stored in the MATLAB buffer.

  • latest

    Provides the latest data samples available in the buffer. All previous data samples in the buffer are discarded. For example, if SamplesPerRead = 3, the latest three data samples read by the sensor are returned.

    The following figure illustrates how latest data samples are returned assuming S1 is the first sensor data stored in the buffer, S2 is the second data and so on and Sn is the last data stored in the buffer and SamplesPerRead property is set to 3 during sensor object creation.

  • oldest

    Provides the oldest data samples available in the buffer. In this case, no data samples are discarded. For example, if SamplesPerRead = 3, the first three data samples read are returned for the first read, the next three data samples are returned for the second read, and so on.

    The following figure illustrates how oldest data samples are returned assuming S1 is the first sensor data stored in the buffer, S2 is the second data and so on and Sn is the last data stored in the buffer and SamplesPerRead property is set to 3 during sensor object creation.

Data Types: character vector | string

This property is read-only.

Samplesread property outputs the values of samples read so far by executing read function. Samplesread is set to 0, when the object is created or when you release the object.

Data Types: double

Set the output format of the data returned by executing the read function.

When the OutputFormat is set to timetable, the data returned has the following fields:

  • Time — Time stamps in datetime or duration format

  • Pressure — Barometric air pressure in Pascals (Pa)

  • Temperature — Temperature in units of celsius

When the OutputFormat is set to matrix, the data is returned as matrices of pressure, temperature, and time stamps. The units for the sensor readings are the same as the timetable format.

Data Types: character vector | string

Set the format of the time displayed when the sensor data is read.

  • datetime — Displays the date and time at which the data is read.

  • duration — Displays the time elapsed in seconds after the sensor object is locked. The sensor object gets locked at the first call of the read function either after the object creation or after the execution of the release function.

Data Types: character vector | string

Object Functions

readPressureRead one sample of barometric air pressure data from the sensor
readTemperatureRead one sample of temperature from sensor
readRead real-time sensor data at a specified rate using Sensor Fusion and Tracking Toolbox or Navigation Toolbox
releaseRelease the sensor object
flushFlush the host buffer
infoRead information related to sensor

Examples

Create Connection to LPS22HB Sensor

Create an arduino object with the I2C library.

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

Create the sensor object.

pressureSensor = lps22hb(a)
pressureSensor = 

  lps22hb with properties: 

                 I2CAddress: 92 ("0x5C") 
                        Bus: 0
                     SCLPin: "A5" 
                     SDAPin: "A4" 

Show all properties, functions

Create LPS22HB Sensor Connection (with Sensor Fusion and Tracking Toolbox or Navigation Toolbox)

Create a sensor object with properties available only with the Sensor Fusion and Tracking Toolbox or Navigation Toolbox.

clear pressureSensor;
pressureSensor = lps22hb(a,'SampleRate',50,'SamplesPerRead',5,'ReadMode','Latest')
pressureSensor =
 
  lps22hb with properties:
 
                         I2CAddress: 92 ("0x5C")
                                Bus: 0
                             SCLPin: "A5"
                             SDAPin: "A4"
 
                         SampleRate: 100 (samples/s)
                     SamplesPerRead: 10 
                           ReadMode: "latest"   
                        SamplesRead: 0  
                   SamplesAvailable: 0  
 
Show all properties all functions

More About

expand all

See Also

Introduced in R2021a