Simple test

Ensure your device works with this simple test. For low memory capacity boards

examples/dps310_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5
 6import board
 7
 8from adafruit_dps310.basic import DPS310
 9
10i2c = board.I2C()  # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
12dps310 = DPS310(i2c)
13
14while True:
15    print(f"Temperature = {dps310.temperature:.2f} *C")
16    print(f"Pressure = {dps310.pressure:.2f} hPa")
17    print("")
18    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

examples/dps310_simpletest_advanced.py
 1# SPDX-FileCopyrightText: 2021 Jose David M.
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5
 6import board
 7
 8from adafruit_dps310.advanced import DPS310_Advanced as DPS310
 9
10i2c = board.I2C()  # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
12dps310 = DPS310(i2c)
13
14while True:
15    print(f"Temperature = {dps310.temperature:.2f} *C")
16    print(f"Pressure = {dps310.pressure:.2f} hPa")
17    print("")
18    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

examples/dps310_low_power_weather_station.py
 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
11import time
12
13import board
14
15from adafruit_dps310 import advanced
16
17i2c = board.I2C()  # uses board.SCL and board.SDA
18# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
19dps310 = advanced.DPS310_Advanced(i2c)
20
21dps310.reset()
22dps310.pressure_oversample_count = advanced.SampleCount.COUNT_2
23dps310.pressure_rate = advanced.Rate.RATE_1_HZ
24dps310.temperature_oversample_count = advanced.SampleCount.COUNT_16
25dps310.temperature_rate = advanced.Rate.RATE_1_HZ
26dps310.mode = advanced.Mode.CONT_PRESTEMP
27dps310.wait_temperature_ready()
28dps310.wait_pressure_ready()
29
30while True:
31    print(f"Temperature = {dps310.temperature:.2f} *C")
32    print(f"Pressure = {dps310.pressure:.2f} hPa")
33    print("")
34    time.sleep(10.0)

DisplayIO Simpletest

This is a simple test for boards with built-in display.

examples/dps310_displayio_simpletest.py
 1# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
 2# SPDX-FileCopyrightText: 2024 Jose D. Montoya
 3#
 4# SPDX-License-Identifier: MIT
 5
 6import time
 7
 8import board
 9from adafruit_display_text.bitmap_label import Label
10from displayio import Group
11from terminalio import FONT
12
13from adafruit_dps310.basic import DPS310
14
15# Simple demo of using the built-in display.
16# create a main_group to hold anything we want to show on the display.
17main_group = Group()
18# Initialize I2C bus and sensor.
19i2c = board.I2C()  # uses board.SCL and board.SDA
20dps310 = DPS310(i2c)
21
22# Create Label(s) to show the readings. If you have a very small
23# display you may need to change to scale=1.
24display_output_label = Label(FONT, text="", scale=2)
25
26# place the label(s) in the middle of the screen with anchored positioning
27display_output_label.anchor_point = (0, 0)
28display_output_label.anchored_position = (
29    4,
30    board.DISPLAY.height // 2 - 60,
31)
32
33# add the label(s) to the main_group
34main_group.append(display_output_label)
35
36# set the main_group as the root_group of the built-in DISPLAY
37board.DISPLAY.root_group = main_group
38
39# begin main loop
40while True:
41    # update the text of the label(s) to show the sensor readings
42    display_output_label.text = (
43        f"Temperature:{dps310.temperature:.2f} C\nPressure:{dps310.pressure:.2f} hPa"
44    )
45    # wait for a bit
46    time.sleep(0.5)