Compare commits
15 commits
remove-bad
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eaa2f7e23c | ||
|
|
14cc8ab38a | ||
|
|
59631d72c4 | ||
|
|
631dfa3c19 | ||
|
|
d76bd2f3c1 | ||
|
|
43e0e072ac | ||
|
|
5ab5e920a7 | ||
|
|
178a0cfdb2 | ||
|
|
f30cee1a41 | ||
|
|
85e178bbcd | ||
|
|
3eab93e7e0 | ||
|
|
e008d91861 | ||
|
|
e03ab8d701 | ||
|
|
0ae21598ac | ||
|
|
811f99f7d2 |
3 changed files with 114 additions and 11 deletions
12
README.rst
12
README.rst
|
|
@ -6,7 +6,7 @@ Introduction
|
||||||
:alt: Documentation Status
|
:alt: Documentation Status
|
||||||
|
|
||||||
.. image:: https://img.shields.io/discord/327254708534116352.svg
|
.. image:: https://img.shields.io/discord/327254708534116352.svg
|
||||||
:target: https://discord.gg/nBQh6qu
|
:target: https://adafru.it/discord
|
||||||
:alt: Discord
|
:alt: Discord
|
||||||
|
|
||||||
.. image:: https://github.com/adafruit/Adafruit_CircuitPython_DPS310/workflows/Build%20CI/badge.svg
|
.. image:: https://github.com/adafruit/Adafruit_CircuitPython_DPS310/workflows/Build%20CI/badge.svg
|
||||||
|
|
@ -73,6 +73,16 @@ Usage Example
|
||||||
print("")
|
print("")
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
|
|
||||||
|
Caveat: by default the library initializes the IC with constant temperature and pressure measurements at 64Hz with 64 samples. It is not possible to change the IC's mode, temperature_oversample_count or pressure_oversample_count on-the-fly so resetting the IC and operation parameteres is required. For instance, to set the mode to continuous pressure measurement at 1Hz with 2 samples:
|
||||||
|
|
||||||
|
.. code-block:: python3
|
||||||
|
|
||||||
|
dps310.reset()
|
||||||
|
dps310.pressure_oversample_count = adafruit_dps310.SampleCount.COUNT_2
|
||||||
|
dps310.pressure_rate = adafruit_dps310.Rate.RATE_1_HZ
|
||||||
|
dps310.mode = adafruit_dps310.Mode.CONT_PRESSURE
|
||||||
|
dps310.wait_pressure_ready()
|
||||||
|
|
||||||
|
|
||||||
Contributing
|
Contributing
|
||||||
============
|
============
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ _DPS310_RESET = 0x0C # Soft reset
|
||||||
_DPS310_PRODREVID = 0x0D # Register that contains the part ID
|
_DPS310_PRODREVID = 0x0D # Register that contains the part ID
|
||||||
_DPS310_TMPCOEFSRCE = 0x28 # Temperature calibration src
|
_DPS310_TMPCOEFSRCE = 0x28 # Temperature calibration src
|
||||||
|
|
||||||
|
# pylint: enable=bad-whitespace
|
||||||
# pylint: disable=no-member,unnecessary-pass
|
# pylint: disable=no-member,unnecessary-pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -202,6 +203,10 @@ class DPS310:
|
||||||
|
|
||||||
_calib_coeff_temp_src_bit = ROBit(_DPS310_TMPCOEFSRCE, 7)
|
_calib_coeff_temp_src_bit = ROBit(_DPS310_TMPCOEFSRCE, 7)
|
||||||
|
|
||||||
|
_reg0e = RWBits(8, 0x0E, 0)
|
||||||
|
_reg0f = RWBits(8, 0x0F, 0)
|
||||||
|
_reg62 = RWBits(8, 0x62, 0)
|
||||||
|
|
||||||
def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
|
def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
|
||||||
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
|
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
|
||||||
|
|
||||||
|
|
@ -233,13 +238,9 @@ class DPS310:
|
||||||
self.initialize()
|
self.initialize()
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
"""Reset the sensor to the default state"""
|
"""Initialize the sensor to continuous measurement"""
|
||||||
|
|
||||||
self._reset()
|
self.reset()
|
||||||
self._read_calibration()
|
|
||||||
|
|
||||||
# make sure we're using the temperature source used for calibration
|
|
||||||
self._temp_measurement_src_bit = self._calib_coeff_temp_src_bit
|
|
||||||
|
|
||||||
self.pressure_rate = Rate.RATE_64_HZ
|
self.pressure_rate = Rate.RATE_64_HZ
|
||||||
self.pressure_oversample_count = SampleCount.COUNT_64
|
self.pressure_oversample_count = SampleCount.COUNT_64
|
||||||
|
|
@ -248,17 +249,35 @@ class DPS310:
|
||||||
self.mode = Mode.CONT_PRESTEMP
|
self.mode = Mode.CONT_PRESTEMP
|
||||||
|
|
||||||
# wait until we have at least one good measurement
|
# wait until we have at least one good measurement
|
||||||
|
self.wait_temperature_ready()
|
||||||
|
self.wait_pressure_ready()
|
||||||
|
|
||||||
while (self._temp_ready is False) or (self._pressure_ready is False):
|
# (https://github.com/Infineon/DPS310-Pressure-Sensor#temperature-measurement-issue)
|
||||||
sleep(0.001)
|
# similar to DpsClass::correctTemp(void) from infineon's c++ library
|
||||||
|
def _correct_temp(self):
|
||||||
|
"""Correct temperature readings on ICs with a fuse bit problem"""
|
||||||
|
self._reg0e = 0xA5
|
||||||
|
self._reg0f = 0x96
|
||||||
|
self._reg62 = 0x02
|
||||||
|
self._reg0e = 0
|
||||||
|
self._reg0f = 0
|
||||||
|
|
||||||
def _reset(self):
|
# perform a temperature measurement
|
||||||
"""Perform a soft-reset on the sensor"""
|
# the most recent temperature will be saved internally
|
||||||
|
# and used for compensation when calculating pressure
|
||||||
|
_unused = self._raw_temperature
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
"""Reset the sensor"""
|
||||||
self._reset_register = 0x89
|
self._reset_register = 0x89
|
||||||
# wait for hardware reset to finish
|
# wait for hardware reset to finish
|
||||||
sleep(0.010)
|
sleep(0.010)
|
||||||
while not self._sensor_ready:
|
while not self._sensor_ready:
|
||||||
sleep(0.001)
|
sleep(0.001)
|
||||||
|
self._correct_temp()
|
||||||
|
self._read_calibration()
|
||||||
|
# make sure we're using the temperature source used for calibration
|
||||||
|
self._temp_measurement_src_bit = self._calib_coeff_temp_src_bit
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pressure(self):
|
def pressure(self):
|
||||||
|
|
@ -295,11 +314,51 @@ class DPS310:
|
||||||
"""Returns true if there is a temperature reading ready"""
|
"""Returns true if there is a temperature reading ready"""
|
||||||
return self._temp_ready
|
return self._temp_ready
|
||||||
|
|
||||||
|
def wait_temperature_ready(self):
|
||||||
|
"""Wait until a temperature measurement is available.
|
||||||
|
|
||||||
|
To avoid waiting indefinitely this function raises an
|
||||||
|
error if the sensor isn't configured for temperate measurements,
|
||||||
|
ie. ``Mode.ONE_TEMPERATURE``, ``Mode.CONT_TEMP`` or ``Mode.CONT_PRESTEMP``.
|
||||||
|
See the `Mode` documentation for details.
|
||||||
|
"""
|
||||||
|
if (
|
||||||
|
self._mode_bits == Mode.IDLE
|
||||||
|
or self._mode_bits == Mode.ONE_PRESSURE
|
||||||
|
or self._mode_bits == Mode.CONT_PRESSURE
|
||||||
|
):
|
||||||
|
raise RuntimeError(
|
||||||
|
"Sensor mode is set to idle or pressure measurement,\
|
||||||
|
can't wait for a temperature measurement"
|
||||||
|
)
|
||||||
|
while self._temp_ready is False:
|
||||||
|
sleep(0.001)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pressure_ready(self):
|
def pressure_ready(self):
|
||||||
"""Returns true if pressure readings are ready"""
|
"""Returns true if pressure readings are ready"""
|
||||||
return self._pressure_ready
|
return self._pressure_ready
|
||||||
|
|
||||||
|
def wait_pressure_ready(self):
|
||||||
|
"""Wait until a pressure measurement is available
|
||||||
|
|
||||||
|
To avoid waiting indefinitely this function raises an
|
||||||
|
error if the sensor isn't configured for pressure measurements,
|
||||||
|
ie. ``Mode.ONE_PRESSURE``, ``Mode.CONT_PRESSURE`` or ``Mode.CONT_PRESTEMP``
|
||||||
|
See the `Mode` documentation for details.
|
||||||
|
"""
|
||||||
|
if (
|
||||||
|
self._mode_bits == Mode.IDLE
|
||||||
|
or self._mode_bits == Mode.ONE_TEMPERATURE
|
||||||
|
or self._mode_bits == Mode.CONT_TEMP
|
||||||
|
):
|
||||||
|
raise RuntimeError(
|
||||||
|
"Sensor mode is set to idle or temperature measurement,\
|
||||||
|
can't wait for a pressure measurement"
|
||||||
|
)
|
||||||
|
while self._pressure_ready is False:
|
||||||
|
sleep(0.001)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mode(self):
|
def mode(self):
|
||||||
"""The measurement mode. Must be a `Mode`. See the `Mode` documentation for details"""
|
"""The measurement mode. Must be a `Mode`. See the `Mode` documentation for details"""
|
||||||
|
|
|
||||||
34
examples/dps310_low_power_weather_station.py
Normal file
34
examples/dps310_low_power_weather_station.py
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
"""
|
||||||
|
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 busio
|
||||||
|
import adafruit_dps310
|
||||||
|
|
||||||
|
i2c = busio.I2C(board.SCL, 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)
|
||||||
Loading…
Reference in a new issue