Skip to content

Commit 31996aa

Browse files
Merge pull request #17 from jposada202020/improving_docs
improving_docs
2 parents c882f45 + 85f4b1f commit 31996aa

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

adafruit_mpl3115a2.py

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@
77
====================================================
88
99
CircuitPython module for the MPL3115A2 barometric pressure & temperature sensor.
10-
See examples/simpletest.py for a demo of the usage.
1110
1211
* Author(s): Tony DiCola
12+
13+
Implementation Notes
14+
--------------------
15+
16+
**Hardware:**
17+
18+
* `Adafruit MPL3115A2 - I2C Barometric Pressure/Altitude/Temperature Sensor
19+
<https://www.adafruit.com/product/1893>`_
20+
21+
**Software and Dependencies:**
22+
23+
* Adafruit CircuitPython firmware for the supported boards:
24+
https://circuitpython.org/downloads
25+
26+
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
27+
1328
"""
1429
import time
1530

@@ -80,12 +95,37 @@
8095

8196

8297
class MPL3115A2:
83-
"""Instance of the MPL3115A2 sensor. Must specify the following parameters
84-
when creating an instance of this device:
85-
- i2c: The I2C bus connected to the sensor.
98+
"""Instance of the MPL3115A2 sensor.
99+
100+
:param ~busio.I2C i2c: The I2C bus the MPL3115A2 is connected to.
101+
:param int address: The I2C device address. Defaults to :const:`0x60`
102+
103+
**Quickstart: Importing and using the MPL3115A2**
104+
105+
Here is an example of using the :class:`MPL3115A2` class.
106+
First you will need to import the libraries to use the sensor
107+
108+
.. code-block:: python
109+
110+
import board
111+
import adafruit_mpl3115a2
112+
113+
Once this is done you can define your `board.I2C` object and define your sensor object
114+
115+
.. code-block:: python
116+
117+
i2c = board.I2C() # uses board.SCL and board.SDA
118+
sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
119+
120+
Now you have access to the :attr:`temperature`, :attr:`pressure`
121+
and :attr:`altitude` attributes
122+
123+
.. code-block:: python
124+
125+
temperature = sensor.temperature
126+
pressure = sensor.pressure
127+
altitude = sensor.altitude
86128
87-
In addition you can specify the following optional keyword arguments:
88-
- address: The I2C address of the device if it's different from the default.
89129
"""
90130

91131
# Class level buffer to reduce memory usage and allocations.
@@ -184,7 +224,7 @@ def altitude(self):
184224
"""Read the altitude as calculated based on the sensor pressure and
185225
previously configured pressure at sea-level. This will return a
186226
value in meters. Set the sea-level pressure by updating the
187-
sealevel_pressure property first to get a more accurate altitude value.
227+
:attr:`sealevel_pressure` property first to get a more accurate altitude value.
188228
"""
189229
# First poll for a measurement to be finished.
190230
self._poll_reg1(_MPL3115A2_CTRL_REG1_OST)
@@ -230,7 +270,7 @@ def temperature(self):
230270
@property
231271
def sealevel_pressure(self):
232272
"""Read and write the pressure at sea-level used to calculate altitude.
233-
You must look this up from a local weather or meteorlogical report for
273+
You must look this up from a local weather or meteorological report for
234274
the best accuracy. This is a value in Pascals.
235275
"""
236276
# Read the sea level pressure in bars.

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+
MPL3115A2 - I2C Barometric Pressure/Altitude/Temperature Sensor Learning Guide <https://learn.adafruit.com/using-mpl3115a2-with-circuitpython>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

31+
MPL3115A2 - I2C Barometric Pressure/Altitude/Temperature Sensor <https://www.adafruit.com/product/1893>
32+
2933
.. toctree::
3034
:caption: Other Links
3135

examples/mpl3115a2_simpletest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44
# Simple demo of the MPL3115A2 sensor.
55
# Will read the pressure and temperature and print them out every second.
66
import time
7-
87
import board
9-
import busio
10-
118
import adafruit_mpl3115a2
129

1310

14-
# Initialize the I2C bus.
15-
i2c = busio.I2C(board.SCL, board.SDA)
11+
# Create sensor object, communicating over the board's default I2C bus
12+
i2c = board.I2C() # uses board.SCL and board.SDA
1613

1714
# Initialize the MPL3115A2.
1815
sensor = adafruit_mpl3115a2.MPL3115A2(i2c)
1916
# Alternatively you can specify a different I2C address for the device:
2017
# sensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x10)
2118

2219
# You can configure the pressure at sealevel to get better altitude estimates.
23-
# This value has to be looked up from your local weather forecast or meteorlogical
20+
# This value has to be looked up from your local weather forecast or meteorological
2421
# reports. It will change day by day and even hour by hour with weather
2522
# changes. Remember altitude estimation from barometric pressure is not exact!
2623
# Set this to a value in pascals:

0 commit comments

Comments
 (0)