Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import adafruit_dps310
i2c = board.I2C() # uses board.SCL and board.SDA
dps310 = adafruit_dps310.DPS310(i2c)
while True:
print("Temperature = %.2f *C" % dps310.temperature)
print("Pressure = %.2f hPa" % dps310.pressure)
print("")
time.sleep(1.0)
|
Lower Power Weather Station¶
Example showing how to configure the sensor for continuous measurement with rates, sampling counts and mode optimized for low power
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 32 33 34 35 36 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
Configure the sensor for continuous measurement with rates,
sampling counts and mode optmized for low power, as recommended
in Infineon's datasheet:
https://www.infineon.com/dgdl/Infineon-DPS310-DS-v01_00-EN.pdf
"""
# (disable pylint warnings for adafruit_dps310.{SampleCount,Rate,Mode}.*
# as they are generated dynamically)
# pylint: disable=no-member
import time
import board
import adafruit_dps310
i2c = board.I2C() # uses board.SCL and board.SDA
dps310 = adafruit_dps310.DPS310(i2c)
dps310.reset()
dps310.pressure_oversample_count = adafruit_dps310.SampleCount.COUNT_2
dps310.pressure_rate = adafruit_dps310.Rate.RATE_1_HZ
dps310.temperature_oversample_count = adafruit_dps310.SampleCount.COUNT_16
dps310.temperature_rate = adafruit_dps310.Rate.RATE_1_HZ
dps310.mode = adafruit_dps310.Mode.CONT_PRESTEMP
dps310.wait_temperature_ready()
dps310.wait_pressure_ready()
while True:
print("Temperature = %.2f *C" % dps310.temperature)
print("Pressure = %.2f hPa" % dps310.pressure)
print("")
time.sleep(10.0)
|