Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding_sea_level_pressure_property
  • Loading branch information
jposada202020 committed May 27, 2021
commit 36c7fca80646d5b3f39225c813124b6eb2c75285
12 changes: 8 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Introduction
:target: https://github.com/adafruit/Adafruit_CircuitPython_DPS310/actions
:alt: Build Status

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: Code Style: Black

Library for the DPS310 Precision Barometric Pressure Sensor


Expand Down Expand Up @@ -72,14 +76,14 @@ Usage Example
print("")
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:


Known Issues
============
Library extensive features might not be compatible with memory limited boards.
Library extensive features might not be compatible with memory limited boards. For these kind of
boards you need to use the ``adafruit_dps310/basic.mpy``, the file needs to be in the ``mpy``
format in order to fit in memory.
For boards with more memory available you could use the code present
in ``adafruit_dps310/dps310_advanced.py``. For usage refer to ``dps310_simpletest_advanced.py``
in ``adafruit_dps310/advanced.py``. For usage refer to ``dps310_simpletest_advanced.py``


Contributing
Expand Down
17 changes: 8 additions & 9 deletions adafruit_dps310/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ class SampleCount(CV):
# pylint: enable=unnecessary-pass

_DPS310_DEFAULT_ADDRESS = const(0x77) # DPS310 default i2c address
#_DPS310_DEVICE_ID = const(0x10) # DPS310 device identifier
# _DPS310_DEVICE_ID = const(0x10) # DPS310 device identifier

#_DPS310_PRSB2 = const(0x00) # Highest byte of pressure data
#_DPS310_TMPB2 = const(0x03) # Highest byte of temperature data
# _DPS310_PRSB2 = const(0x00) # Highest byte of pressure data
# _DPS310_TMPB2 = const(0x03) # Highest byte of temperature data
_DPS310_PRSCFG = const(0x06) # Pressure configuration
_DPS310_TMPCFG = const(0x07) # Temperature configuration
#_DPS310_MEASCFG = const(0x08) # Sensor configuration
#_DPS310_CFGREG = const(0x09) # Interrupt/FIFO configuration
#_DPS310_RESET = const(0x0C) # Soft reset
#_DPS310_PRODREVID = const(0x0D) # Register that contains the part ID
#_DPS310_TMPCOEFSRCE = const(0x28) # Temperature calibration src
# _DPS310_MEASCFG = const(0x08) # Sensor configuration
# _DPS310_CFGREG = const(0x09) # Interrupt/FIFO configuration
# _DPS310_RESET = const(0x0C) # Soft reset
# _DPS310_PRODREVID = const(0x0D) # Register that contains the part ID
# _DPS310_TMPCOEFSRCE = const(0x28) # Temperature calibration src


class DPS310_Advanced(DPS310):
Expand Down Expand Up @@ -199,7 +199,6 @@ class DPS310_Advanced(DPS310):
def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
super().__init__(i2c_bus, _DPS310_DEFAULT_ADDRESS)


def initialize(self):
"""Initialize the sensor to continuous measurement"""

Expand Down
19 changes: 16 additions & 3 deletions adafruit_dps310/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
1040384,
2088960,
)
self.sea_level_pressure = 1013.25
"""Pressure in hectoPascals at sea level. Used to calibrate :attr:`altitude`."""
self._sea_level_pressure = 1013.25

self.initialize()

def initialize(self):
Expand Down Expand Up @@ -223,7 +223,9 @@ def pressure(self):
def altitude(self):
"""The altitude based on the sea level pressure (:attr:`sea_level_pressure`) -
which you must enter ahead of time)"""
return 44330 * (1.0 - math.pow(self.pressure / self.sea_level_pressure, 0.1903))
return 44330 * (
1.0 - math.pow(self.pressure / self._sea_level_pressure, 0.1903)
)

@property
def temperature(self):
Expand All @@ -232,6 +234,17 @@ def temperature(self):
_temperature = _scaled_rawtemp * self._c1 + self._c0 / 2.0
return _temperature

@property
def sea_level_pressure(self):
"""The local sea level pressure in hectoPascals (aka millibars). This is used
for calculation of :attr:`altitude`. Values are typically in the range
980 - 1030."""
return self._sea_level_pressure

@sea_level_pressure.setter
def sea_level_pressure(self, value):
self._sea_level_pressure = value

def wait_temperature_ready(self):
"""Wait until a temperature measurement is available."""

Expand Down
6 changes: 5 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
autodoc_mock_imports = ["adafruit_register", "adafruit_bus_device"]
autodoc_mock_imports = [
"adafruit_register",
"adafruit_bus_device",
"micropython",
]


intersphinx_mapping = {
Expand Down