Skip to content

improving_docs #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ Usage Example

import time
import board
import busio
import adafruit_dps310

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA

dps310 = adafruit_dps310.DPS310(i2c)

Expand Down
42 changes: 33 additions & 9 deletions adafruit_dps310.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Mode(CV):


class Rate(CV):
"""Options for `pressure_rate` and `temperature_rate`"""
"""Options for :attr:`pressure_rate` and :attr:`temperature_rate`"""

pass

Expand All @@ -134,7 +134,7 @@ class Rate(CV):


class SampleCount(CV):
"""Options for `temperature_oversample_count` and `pressure_oversample_count`"""
"""Options for :attr:`temperature_oversample_count` and :attr:`pressure_oversample_count`"""

pass

Expand All @@ -157,7 +157,31 @@ class DPS310:
"""Library for the DPS310 Precision Barometric Pressure Sensor.

:param ~busio.I2C i2c_bus: The I2C bus the DPS310 is connected to.
:param address: The I2C slave address of the sensor
:param int address: The I2C device address. Defaults to :const:`0x77`

**Quickstart: Importing and using the DPS310**

Here is an example of using the :class:`DPS310` class.
First you will need to import the libraries to use the sensor

.. code-block:: python

import board
import adafruit_dps310

Once this is done you can define your `board.I2C` object and define your sensor object

.. code-block:: python

i2c = board.I2C() # uses board.SCL and board.SDA
dps310 = adafruit_dps310.DPS310(i2c)

Now you have access to the :attr:`temperature` and :attr:`pressure` attributes.

.. code-block:: python

temperature = dps310.temperature
pressure = dps310.pressure

"""
# Register definitions
Expand Down Expand Up @@ -219,7 +243,7 @@ def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
2088960,
)
self.sea_level_pressure = 1013.25
"""Pressure in hectoPascals at sea level. Used to calibrate `altitude`."""
"""Pressure in hectoPascals at sea level. Used to calibrate :attr:`altitude`."""
self.initialize()

def initialize(self):
Expand Down Expand Up @@ -289,13 +313,13 @@ def pressure(self):

@property
def altitude(self):
"""The altitude based on the sea level pressure (`sea_level_pressure`) - which you must
enter ahead of time)"""
"""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))

@property
def temperature(self):
"""The current temperature reading in degrees C"""
"""The current temperature reading in degrees Celsius"""
_scaled_rawtemp = self._raw_temperature / self._temp_scale
_temperature = _scaled_rawtemp * self._c1 + self._c0 / 2.0
return _temperature
Expand Down Expand Up @@ -375,7 +399,7 @@ def pressure_rate(self, value):

@property
def pressure_oversample_count(self):
"""The number of samples taken per pressure measurement. Must be a `SampleCount`"""
"""The number of samples taken per pressure measurement. Must be a ``SampleCount``"""
return self._pressure_osbits

@pressure_oversample_count.setter
Expand All @@ -400,7 +424,7 @@ def temperature_rate(self, value):

@property
def temperature_oversample_count(self):
"""The number of samples taken per temperature measurement. Must be a `SampleCount`"""
"""The number of samples taken per temperature measurement. Must be a ``SampleCount``"""
return self._temp_osbits

@temperature_oversample_count.setter
Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

.. automodule:: adafruit_dps310
:members:
:exclude-members: CV, SampleCount
10 changes: 10 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ Ensure your device works with this simple test.
.. literalinclude:: ../examples/dps310_simpletest.py
:caption: examples/dps310_simpletest.py
:linenos:

Lower Power Weather Station
---------------------------

Example showing how to configure the sensor for continuous measurement with rates,
sampling counts and mode optimized for low power

.. literalinclude:: ../examples/dps310_low_power_weather_station.py
:caption: examples/dps310_low_power_weather_station.py
:linenos:
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ Table of Contents
.. toctree::
:caption: Tutorials

Adafruit DPS310 Precision Barometric Pressure / Altitude Sensor Learning Guide <https://learn.adafruit.com/adafruit-dps310-precision-barometric-pressure-sensor/python-circuitpython>

.. toctree::
:caption: Related Products

Adafruit DPS310 Precision Barometric Pressure / Altitude Sensor <https://www.adafruit.com/product/4494>

.. toctree::
:caption: Other Links
Expand Down
3 changes: 1 addition & 2 deletions examples/dps310_low_power_weather_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

import time
import board
import busio
import adafruit_dps310

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA

dps310 = adafruit_dps310.DPS310(i2c)

Expand Down
4 changes: 1 addition & 3 deletions examples/dps310_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

import time
import board
import busio
import adafruit_dps310

i2c = busio.I2C(board.SCL, board.SDA)

i2c = board.I2C() # uses board.SCL and board.SDA
dps310 = adafruit_dps310.DPS310(i2c)

while True:
Expand Down