Simple test

Ensure your device works with this simple test.

examples/lps35hw_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# SPDX-FileCopyrightText: 2019 Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import board
import adafruit_lps35hw

i2c = board.I2C()
lps = adafruit_lps35hw.LPS35HW(i2c)

while True:
    print("Pressure: %.2f hPa" % lps.pressure)
    print("Temperature: %.2f C" % lps.temperature)
    print("")
    time.sleep(1)

Relative Pressure

Set the current pressure as zero hPa and make measurements relative to that pressure, even negative

examples/lps35hw_relative.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# SPDX-FileCopyrightText: 2019 Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import board
import adafruit_lps35hw

i2c = board.I2C()
lps = adafruit_lps35hw.LPS35HW(i2c)

# set the current pressure as zero hPa and make measurements
# relative to that pressure, even negative!
lps.zero_pressure()
while True:
    print("Pressure: %.2f hPa" % lps.pressure)
    print("")
    time.sleep(0.5)

Threshold Setting

Setting the pressure threshold to act as a trigger

examples/lps35hw_high_threshold.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# SPDX-FileCopyrightText: 2019 Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import board
import adafruit_lps35hw

i2c = board.I2C()
lps = adafruit_lps35hw.LPS35HW(i2c)

# You may need to adjust the threshold to something closer
# to the current pressure where the sensor is
lps.pressure_threshold = 1030

lps.high_threshold_enabled = True

while True:
    print("Pressure: %.2f hPa" % lps.pressure)
    print("Threshhold exceeded: %s" % lps.high_threshold_exceeded)
    print("")
    time.sleep(1)

Using Filter

Using the filter parameter to filter out high-frequency noise

examples/lps35hw_filter.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# SPDX-FileCopyrightText: 2019 Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import board
import adafruit_lps35hw


i2c = board.I2C()
lps = adafruit_lps35hw.LPS35HW(i2c)

lps.low_pass_enabled = True
while True:
    print("Pressure: %.2f hPa" % lps.pressure)
    print("")
    time.sleep(0.125)

Data Rate

Data rate example

examples/lps35hw_data_rate.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# SPDX-FileCopyrightText: 2019 Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import board
from adafruit_lps35hw import LPS35HW, DataRate

i2c = board.I2C()
lps = LPS35HW(i2c)

lps.data_rate = DataRate.ONE_SHOT
lps.take_measurement()


while True:
    print("Pressure: %.2f hPa" % lps.pressure)
    print("")
    time.sleep(1)
    print("Pressure: %.2f hPa" % lps.pressure)
    print("")
    time.sleep(1)
    print("Pressure: %.2f hPa" % lps.pressure)
    print("")
    time.sleep(1)

    # take another measurement
    lps.take_measurement()

    print("New Pressure: %.2f hPa" % lps.pressure)
    print("")
    time.sleep(1)