Skip to content

Commit 2eb66bb

Browse files
Merge pull request #9 from jposada202020/improving_docs
improving_docs
2 parents a38c991 + 16f2c2f commit 2eb66bb

File tree

3 files changed

+101
-21
lines changed

3 files changed

+101
-21
lines changed

adafruit_lps35hw.py

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,54 @@ class DataRate: # pylint: disable=too-few-public-methods
114114
class LPS35HW: # pylint: disable=too-many-instance-attributes
115115
"""Driver for the ST LPS35HW MEMS pressure sensor
116116
117-
:param ~busio.I2C i2c_bus: The I2C bus the LPS34HW is connected to.
118-
:param address: The I2C device address for the sensor. Default is ``0x5d`` but will accept
119-
``0x5c`` when the ``SDO`` pin is connected to Ground.
117+
:param ~busio.I2C i2c_bus: The I2C bus the LPS35HW is connected to.
118+
:param int address: The I2C device address for the sensor. Default is :const:`0x5d`
119+
but will accept :const:`0x5c` when the ``SDO`` pin is connected to Ground.
120+
121+
122+
**Quickstart: Importing and using the LPS35HW**
123+
124+
Here is an example of using the :class:`LPS35HW` class.
125+
First you will need to import the libraries to use the sensor
126+
127+
.. code-block:: python
128+
129+
import board
130+
import adafruit_lps35hw
131+
132+
Once this is done you can define your `board.I2C` object and define your sensor object
133+
134+
.. code-block:: python
135+
136+
i2c = board.I2C() # uses board.SCL and board.SDA
137+
lps = adafruit_lps35hw.LPS35HW(i2c)
138+
139+
Now you have access to the :attr:`temperature` and :attr:`pressure` attributes.
140+
Temperature is in Celsius and Pressure is in hPa.
141+
142+
.. code-block:: python
143+
144+
temperature = lps.temperature
145+
pressure = lps.pressure
146+
120147
121148
"""
122149

123150
data_rate = RWBits(3, _CTRL_REG1, 4)
124-
"""The rate at which the sensor measures ``pressure`` and ``temperature``. ``data_rate`` should
125-
be set to one of the values of ``adafruit_lps35hw.DataRate``. Note that setting ``data_rate``
126-
to ``DataRate.ONE_SHOT`` places the sensor into a low-power shutdown mode where measurements to
127-
update ``pressure`` and ``temperature`` are only taken when ``take_measurement`` is called."""
151+
"""The rate at which the sensor measures :attr:`pressure` and :attr:`temperature`.
152+
``data_rate`` should be set to one of the values of :meth:`adafruit_lps35hw.DataRate`.
153+
154+
.. note::
155+
Setting ``data_rate`` to :const:`DataRate.ONE_SHOT` places the sensor
156+
into a low-power shutdown mode where measurements to update
157+
:attr:`pressure` and :attr:`temperature` are only taken
158+
when :meth:`take_measurement` is called.
159+
160+
"""
128161

129162
low_pass_enabled = RWBit(_CTRL_REG1, 3)
130163
"""True if the low pass filter is enabled. Setting to `True` will reduce the sensor bandwidth
131-
from ``data_rate/2`` to ``data_rate/9``, filtering out high-frequency noise."""
164+
from :math:`data_rate/2` to :math:`data_rate/9`, filtering out high-frequency noise."""
132165

133166
_raw_temperature = UnaryStruct(_TEMP_OUT_L, "<h")
134167
_raw_pressure = ROBits(24, _PRESS_OUT_XL, 0, 3)
@@ -181,7 +214,7 @@ def pressure(self):
181214

182215
@property
183216
def temperature(self):
184-
"""The current temperature measurement in degrees C"""
217+
"""The current temperature measurement in degrees Celsius"""
185218
return self._raw_temperature / 100.0
186219

187220
def reset(self):
@@ -192,26 +225,27 @@ def reset(self):
192225
pass
193226

194227
def take_measurement(self):
195-
"""Update the value of ``pressure`` and ``temperature`` by taking a single measurement.
196-
Only meaningful if ``data_rate`` is set to ``ONE_SHOT``"""
228+
"""Update the value of :attr:`pressure` and :attr:`temperature`
229+
by taking a single measurement. Only meaningful if ``data_rate``
230+
is set to ``ONE_SHOT``"""
197231
self._one_shot = True
198232
while self._one_shot:
199233
pass
200234

201235
def zero_pressure(self):
202-
"""Set the current pressure as zero and report the ``pressure`` relative to it"""
236+
"""Set the current pressure as zero and report the :attr:`pressure` relative to it"""
203237
self._auto_zero = True
204238
while self._auto_zero:
205239
pass
206240

207241
def reset_pressure(self):
208-
"""Reset ``pressure`` to be reported as the measured absolute value"""
242+
"""Reset :attr:`pressure` to be reported as the measured absolute value"""
209243
self._reset_zero = True
210244

211245
@property
212246
def pressure_threshold(self):
213-
"""The high presure threshold. Use ``high_threshold_enabled`` or ``high_threshold_enabled``
214-
to use it"""
247+
"""The high pressure threshold. Use :attr:`high_threshold_enabled`
248+
or :attr:`high_threshold_enabled` to use it"""
215249
return self._pressure_threshold / 16
216250

217251
@pressure_threshold.setter
@@ -231,8 +265,12 @@ def high_threshold_enabled(self, value):
231265

232266
@property
233267
def low_threshold_enabled(self):
234-
"""Set to `True` or `False` to enable or disable the low pressure threshold. **Note the
235-
low pressure threshold only works in relative mode**"""
268+
"""Set to `True` or `False` to enable or disable the low pressure threshold.
269+
270+
.. note::
271+
The low pressure threshold only works in relative mode
272+
273+
"""
236274
return self._interrupts_enabled and self._interrupt_low
237275

238276
@low_threshold_enabled.setter
@@ -242,12 +280,14 @@ def low_threshold_enabled(self, value):
242280

243281
@property
244282
def high_threshold_exceeded(self):
245-
"""Returns `True` if the pressure high threshold has been exceeded. Must be enabled by
246-
setting ``high_threshold_enabled`` to `True` and setting a ``pressure_threshold``."""
283+
"""Returns `True` if the pressure high threshold has been exceeded.
284+
Must be enabled by setting :attr:`high_threshold_enabled` to `True`
285+
and setting a :attr:`pressure_threshold`."""
247286
return self._pressure_high
248287

249288
@property
250289
def low_threshold_exceeded(self):
251-
"""Returns `True` if the pressure low threshold has been exceeded. Must be enabled by
252-
setting ``high_threshold_enabled`` to `True` and setting a ``pressure_threshold``."""
290+
"""Returns `True` if the pressure low threshold has been exceeded.
291+
Must be enabled by setting :attr:`high_threshold_enabled`
292+
to `True` and setting a :attr:`pressure_threshold`."""
253293
return self._pressure_low

docs/examples.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,39 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/lps35hw_simpletest.py
77
:caption: examples/lps35hw_simpletest.py
88
:linenos:
9+
10+
Relative Pressure
11+
-----------------
12+
13+
Set the current pressure as zero hPa and make measurements relative to that pressure, even negative
14+
15+
.. literalinclude:: ../examples/lps35hw_relative.py
16+
:caption: examples/lps35hw_relative.py
17+
:linenos:
18+
19+
Threshold Setting
20+
-----------------
21+
22+
Setting the pressure threshold to act as a trigger
23+
24+
.. literalinclude:: ../examples/lps35hw_high_threshold.py
25+
:caption: examples/lps35hw_high_threshold.py
26+
:linenos:
27+
28+
Using Filter
29+
------------
30+
31+
Using the filter parameter to filter out high-frequency noise
32+
33+
.. literalinclude:: ../examples/lps35hw_filter.py
34+
:caption: examples/lps35hw_filter.py
35+
:linenos:
36+
37+
Data Rate
38+
---------
39+
40+
Data rate example
41+
42+
.. literalinclude:: ../examples/lps35hw_data_rate.py
43+
:caption: examples/lps35hw_data_rate.py
44+
:linenos:

docs/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26+
Adafruit LPS33/LPS35 Water Resistant Pressure Sensor Learning Guide <https://learn.adafruit.com/lps35hw-water-resistant-pressure-sensor>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

31+
Adafruit LPS33/LPS35 Water Resistant Pressure Sensor <https://www.adafruit.com/product/4258>
32+
2933
.. toctree::
3034
:caption: Other Links
3135

0 commit comments

Comments
 (0)