lps22h — LPS22HB/HH pressure sensor
Driver for the ST LPS22HB / LPS22HH MEMS nano pressure sensor over I2C. The device exposes both barometric pressure and a die temperature reading, and can run either continuously or in single-shot (“one-shot”) mode where each measurement is triggered explicitly by the host.
Example:
import time
from machine import Pin, I2C
from lps22h import LPS22H
bus = I2C(1, scl=Pin(15), sda=Pin(14))
lps = LPS22H(bus, oneshot=False)
while True:
print("Pressure: %.2f hPa Temperature: %.2f C" %
(lps.pressure(), lps.temperature()))
time.sleep_ms(10)
Classes
- class lps22h.LPS22H(bus: machine.I2C, address: int = 0x5C, oneshot: bool = False)
Construct an
LPS22Hinstance and configure the device with BDU enabled and the low-pass filter active.busA configured
machine.I2Cbus the sensor is attached to.address7-bit I2C address of the device. Defaults to
0x5C; some boards strap the SDO pin high which selects0x5D.oneshotIf
True, the device starts in one-shot mode and each call topressure()ortemperature()triggers a fresh conversion and waits for it to finish. IfFalse, the ODR is set to 1 Hz and readings return the most recent continuous sample.
- set_oneshot_mode(oneshot: bool) None
Switch the device between continuous and one-shot acquisition modes at runtime. Updates the ODR field of
CTRL_REG1accordingly.
- pressure() float
Return the absolute atmospheric pressure in hectopascals (hPa). In one-shot mode this triggers a new conversion and blocks until the pressure data-ready flag is set.