Skip to main content

LPS22HH Pico Driver

Micropython library for the ST LPS22HH and the LPS27HH pressure sensor over SPI or I2C

Overview

The LPS22HH and LPS27HH sensors are high-resolution digital output pressure sensors manufactured by STMicroelectronics. This driver enables seamless integration of the sensors with the Raspberry Pi Pico.

Features

  • Interface to communicate with the LPS22HH and LPS27HH pressure sensor.
  • Reading of pressure and temperature values
  • Configuration of registers via dedicated functions
  • Communication via SPI or I2C
  • Designed to be compatible with the Raspberry Pi Pico running on Micropython. Other boards not tested

Installation

Use pip (see Python Package Index )

> pip install lps22hh

or

Use mip (see MicroPython Package management):

> mpremote mip install github:cbraissant/lps22hh-pico-driver

Getting Started

As the sensor can be used either with SPI or I2C, the first step is to initialize the interface.

For SPI:

from machine import SPI, Pin
from lps22hh import LPS22HH

# Create a new SPI device, and assign the pins corresponding to your device
cs_pin = Pin(1, Pin.OUT)
spi = SPI(0, baudrate=1000000, firstbit=SPI.MSB, sck=Pin(2), mosi=Pin(3), miso=Pin(0))

# Create a new instance of the LPS22HH sensor
sensor = LPS22HH(spi, cs_pin)

For I2C:

import time
from machine import I2C, Pin
from lps22hh import LPS22HH

# Create a new I2C device, and assign the pins corresponding to your device
i2c = I2C(1, sda=Pin(6), scl=Pin(7))

# Create a new instance of the Lps22hh sensor
sensor = LPS22HH(interface=i2c, address=0x5D)

And then interact with the device

# By default, the device is in power-down mode and the ODR need to be changed
# for the device to take continuous measurements
sensor.data_rate = 200

# The Block Data Update (BDU) is used to inhibit the update of the output
# registers until all output registers parts are read, to avoids reading values
# from different sample times
sensor.block_data_update = 1

while True:
    if sensor.new_pressure_data:
        print(sensor.pressure)

Remarks

Some microcontrollers, like the RP2040 start faster than the pressure sensor. To make sure the sensor has time to boot, a delay must be introduced before the definition of the instance.

...
from lps22hh import LPS22HH

# The RP2040 starts faster than the LPSxxHH pressure sensor and a delay must be introduced
time.sleep_ms(100)

# Create a new I2C device, and assign the pins corresponding to your device
i2c = I2C(1, sda=Pin(6), scl=Pin(7))
...

See the I2C or SPI examples for the full code.

TODO

  • FIFO functionalities
  • Interrupts
  • I3C communications

Contributing

Contributions to this project are welcome. If you find any issues, have suggestions for improvements, or want to add new features, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. Feel free to use, modify, and distribute the code in accordance with the terms of the license.

Metadata

Release files for lps22hh 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lps22hh 1.0.0
File Size Uploaded Provenance Actions
lps22hh-1.0.0.tar.gz 9.1 kB Without provenance Details for lps22hh-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lps22hh 1.0.0
File Interpreter ABI Platform Actions
lps22hh-1.0.0-py3-none-any.whl Python 3 none any Details for lps22hh-1.0.0-py3-none-any.whl

Total release size: 17.8 kB

Release files / lps22hh-1.0.0.tar.gz

Download URL lps22hh-1.0.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
69ce84420d2c6f2cf340a9302e3983e35472000ff466571b1e66a19ac8455bf4
BLAKE2b-256 checksum
How to use checksums
bdd0a5eba488c7f7955caaf276df08bffbaf466a14231dd8a6c600fcf9e4182e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / lps22hh-1.0.0-py3-none-any.whl

Download URL lps22hh-1.0.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9856efe478c6bf86f9573f850cbd2d60972c7eb1f573f5da4408852c4990c306
BLAKE2b-256 checksum
How to use checksums
8ae941c9d092eed471bdc98cb235d9e54b0a5e9b3f5a5988a837bd9147419acc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Security for lps22hh 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page