Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2019 Bryan Siepert, written for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4import time
5import board
6import adafruit_lps35hw
7
8i2c = board.I2C() # uses board.SCL and board.SDA
9# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
10lps = adafruit_lps35hw.LPS35HW(i2c)
11
12while True:
13 print("Pressure: %.2f hPa" % lps.pressure)
14 print("Temperature: %.2f C" % lps.temperature)
15 print("")
16 time.sleep(1)
Relative Pressure¶
Set the current pressure as zero hPa and make measurements relative to that pressure, even negative
1# SPDX-FileCopyrightText: 2019 Bryan Siepert, written for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4import time
5import board
6import adafruit_lps35hw
7
8i2c = board.I2C() # uses board.SCL and board.SDA
9# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
10lps = adafruit_lps35hw.LPS35HW(i2c)
11
12# set the current pressure as zero hPa and make measurements
13# relative to that pressure, even negative!
14lps.zero_pressure()
15while True:
16 print("Pressure: %.2f hPa" % lps.pressure)
17 print("")
18 time.sleep(0.5)
Threshold Setting¶
Setting the pressure threshold to act as a trigger
1# SPDX-FileCopyrightText: 2019 Bryan Siepert, written for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4import time
5import board
6import adafruit_lps35hw
7
8i2c = board.I2C() # uses board.SCL and board.SDA
9# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
10lps = adafruit_lps35hw.LPS35HW(i2c)
11
12# You may need to adjust the threshold to something closer
13# to the current pressure where the sensor is
14lps.pressure_threshold = 1030
15
16lps.high_threshold_enabled = True
17
18while True:
19 print("Pressure: %.2f hPa" % lps.pressure)
20 print("Threshhold exceeded: %s" % lps.high_threshold_exceeded)
21 print("")
22 time.sleep(1)
Using Filter¶
Using the filter parameter to filter out high-frequency noise
1# SPDX-FileCopyrightText: 2019 Bryan Siepert, written for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4import time
5import board
6import adafruit_lps35hw
7
8
9i2c = board.I2C() # uses board.SCL and board.SDA
10# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
11lps = adafruit_lps35hw.LPS35HW(i2c)
12
13lps.low_pass_enabled = True
14while True:
15 print("Pressure: %.2f hPa" % lps.pressure)
16 print("")
17 time.sleep(0.125)
Data Rate¶
Data rate example
1# SPDX-FileCopyrightText: 2019 Bryan Siepert, written for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4import time
5import board
6from adafruit_lps35hw import LPS35HW, DataRate
7
8i2c = board.I2C() # uses board.SCL and board.SDA
9# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
10lps = LPS35HW(i2c)
11
12lps.data_rate = DataRate.ONE_SHOT
13lps.take_measurement()
14
15
16while True:
17 print("Pressure: %.2f hPa" % lps.pressure)
18 print("")
19 time.sleep(1)
20 print("Pressure: %.2f hPa" % lps.pressure)
21 print("")
22 time.sleep(1)
23 print("Pressure: %.2f hPa" % lps.pressure)
24 print("")
25 time.sleep(1)
26
27 # take another measurement
28 lps.take_measurement()
29
30 print("New Pressure: %.2f hPa" % lps.pressure)
31 print("")
32 time.sleep(1)