Skip to content

improving_docs #17

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 1 commit 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
56 changes: 48 additions & 8 deletions adafruit_mpl3115a2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,24 @@
====================================================

CircuitPython module for the MPL3115A2 barometric pressure & temperature sensor.
See examples/simpletest.py for a demo of the usage.

* Author(s): Tony DiCola

Implementation Notes
--------------------

**Hardware:**

* `Adafruit MPL3115A2 - I2C Barometric Pressure/Altitude/Temperature Sensor
<https://www.adafruit.com/product/1893>`_

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads

* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice

"""
import time

Expand Down Expand Up @@ -80,12 +95,37 @@


class MPL3115A2:
"""Instance of the MPL3115A2 sensor. Must specify the following parameters
when creating an instance of this device:
- i2c: The I2C bus connected to the sensor.
"""Instance of the MPL3115A2 sensor.

:param ~busio.I2C i2c: The I2C bus the MPL3115A2 is connected to.
:param int address: The I2C device address. Defaults to :const:`0x60`

**Quickstart: Importing and using the MPL3115A2**

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

.. code-block:: python

import board
import adafruit_mpl3115a2

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
sensor = adafruit_mpl3115a2.MPL3115A2(i2c)

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

.. code-block:: python

temperature = sensor.temperature
pressure = sensor.pressure
altitude = sensor.altitude

In addition you can specify the following optional keyword arguments:
- address: The I2C address of the device if it's different from the default.
"""

# Class level buffer to reduce memory usage and allocations.
Expand Down Expand Up @@ -184,7 +224,7 @@ def altitude(self):
"""Read the altitude as calculated based on the sensor pressure and
previously configured pressure at sea-level. This will return a
value in meters. Set the sea-level pressure by updating the
sealevel_pressure property first to get a more accurate altitude value.
:attr:`sealevel_pressure` property first to get a more accurate altitude value.
"""
# First poll for a measurement to be finished.
self._poll_reg1(_MPL3115A2_CTRL_REG1_OST)
Expand Down Expand Up @@ -230,7 +270,7 @@ def temperature(self):
@property
def sealevel_pressure(self):
"""Read and write the pressure at sea-level used to calculate altitude.
You must look this up from a local weather or meteorlogical report for
You must look this up from a local weather or meteorological report for
the best accuracy. This is a value in Pascals.
"""
# Read the sea level pressure in bars.
Expand Down
4 changes: 4 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ Table of Contents
.. toctree::
:caption: Tutorials

MPL3115A2 - I2C Barometric Pressure/Altitude/Temperature Sensor Learning Guide <https://learn.adafruit.com/using-mpl3115a2-with-circuitpython>

.. toctree::
:caption: Related Products

MPL3115A2 - I2C Barometric Pressure/Altitude/Temperature Sensor <https://www.adafruit.com/product/1893>

.. toctree::
:caption: Other Links

Expand Down
9 changes: 3 additions & 6 deletions examples/mpl3115a2_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@
# Simple demo of the MPL3115A2 sensor.
# Will read the pressure and temperature and print them out every second.
import time

import board
import busio

import adafruit_mpl3115a2


# Initialize the I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)
# Create sensor object, communicating over the board's default I2C bus
i2c = board.I2C() # uses board.SCL and board.SDA

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

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