Simple test¶
Ensure your device works with this simple test. For low memory capacity boards
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5import board
6from adafruit_dps310.basic import DPS310
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
10dps310 = DPS310(i2c)
11
12while True:
13 print("Temperature = %.2f *C" % dps310.temperature)
14 print("Pressure = %.2f hPa" % dps310.pressure)
15 print("")
16 time.sleep(1.0)
Simple test advanced¶
This is a more advance example that shows the full feature library to use with boards where memory allows to use it
1# SPDX-FileCopyrightText: 2021 Jose David M.
2# SPDX-License-Identifier: MIT
3
4import time
5import board
6from adafruit_dps310.advanced import DPS310_Advanced as DPS310
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
10dps310 = DPS310(i2c)
11
12while True:
13 print("Temperature = %.2f *C" % dps310.temperature)
14 print("Pressure = %.2f hPa" % dps310.pressure)
15 print("")
16 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# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""
5Configure the sensor for continuous measurement with rates,
6sampling counts and mode optimized for low power, as recommended
7in Infineon's datasheet:
8https://www.infineon.com/dgdl/Infineon-DPS310-DS-v01_00-EN.pdf
9"""
10
11# (disable pylint warnings for adafruit_dps310.{SampleCount,Rate,Mode}.*
12# as they are generated dynamically)
13# pylint: disable=no-member
14
15import time
16import board
17from adafruit_dps310 import advanced
18
19i2c = board.I2C() # uses board.SCL and board.SDA
20# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
21dps310 = advanced.DPS310_Advanced(i2c)
22
23dps310.reset()
24dps310.pressure_oversample_count = advanced.SampleCount.COUNT_2
25dps310.pressure_rate = advanced.Rate.RATE_1_HZ
26dps310.temperature_oversample_count = advanced.SampleCount.COUNT_16
27dps310.temperature_rate = advanced.Rate.RATE_1_HZ
28dps310.mode = advanced.Mode.CONT_PRESTEMP
29dps310.wait_temperature_ready()
30dps310.wait_pressure_ready()
31
32while True:
33 print("Temperature = %.2f *C" % dps310.temperature)
34 print("Pressure = %.2f hPa" % dps310.pressure)
35 print("")
36 time.sleep(10.0)