Skip to content

mini lint #2

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 11 commits into from
Sep 9, 2018
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ deploy:
tags: true

install:
- pip install -r requirements.txt
- pip install circuitpython-build-tools Sphinx sphinx-rtd-theme
- pip install --force-reinstall pylint==1.9.2

Expand Down
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

19 changes: 17 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Introduction
:target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_MPRLS
:alt: Build Status

.. todo:: Describe what the library does.
CircuitPython library to support Honeywell MPRLS digital pressure sensors.

Dependencies
=============
Expand All @@ -29,7 +29,22 @@ This is easily achieved by downloading
Usage Example
=============

.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
.. code-block:: python

import time
import board
import busio
import adafruit_mprls

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

# Simplest use, connect to default over I2C
mpr = adafruit_mprls.MPRLS(i2c, psi_min=0, psi_max=25)


while True:
print((mpr.pressure,))
time.sleep(1)

Contributing
============
Expand Down
102 changes: 93 additions & 9 deletions adafruit_mprls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`Adafruit_MPRLS`
`adafruit_mprls`
====================================================

.. todo:: Describe what the module does
CircuitPython library to support Honeywell MPRLS digital pressure sensors

* Author(s): ladyada

Expand All @@ -32,21 +32,105 @@

**Hardware:**

.. todo:: Add links to any specific hardware product page(s), or category page(s). Use unordered list & hyperlink rST
inline format: "* `Link Text <url>`_"

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases

.. todo:: Uncomment or remove the Bus Device and/or the Register library dependencies based on the library's use of either.

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

"""

# imports

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MPRLS.git"


import time
from adafruit_bus_device.i2c_device import I2CDevice
from digitalio import Direction
from micropython import const

# pylint: disable=bad-whitespace
_MPRLS_DEFAULT_ADDR = const(0x18)
# pylint: enable=bad-whitespace

class MPRLS:
"""
Driver base for the MPRLS pressure sensor
:param i2c_bus: The `busio.I2C` object to use. This is the only required parameter.
:param int addr: The optional I2C address, defaults to 0x18
:param microcontroller.Pin reset_pin: Optional digitalio pin for hardware resetting
:param microcontroller.Pin eoc_pin: Optional digitalio pin for getting End Of Conversion signal
:param float psi_min: The minimum pressure in PSI, defaults to 0
:param float psi_max: The maximum pressure in PSI, defaults to 25
"""

def __init__(self, i2c_bus, *, addr=_MPRLS_DEFAULT_ADDR,
reset_pin=None, eoc_pin=None, psi_min=0, psi_max=25):
# Init I2C
self._i2c = I2CDevice(i2c_bus, addr)
self._buffer = bytearray(4)

# Optional hardware reset pin
if reset_pin is not None:
reset_pin.direction = Direction.OUTPUT
reset_pin.value = True
reset_pin.value = False
time.sleep(0.01)
reset_pin.value = True
time.sleep(0.005) # Start up timing

# Optional end-of-conversion pin
self._eoc = eoc_pin
if eoc_pin is not None:
self._eoc.direction = Direction.INPUT

if psi_min >= psi_max:
raise ValueError("Min PSI must be < max!")
self._psimax = psi_max
self._psimin = psi_min
# That's pretty much it, there's no ID register :(

@property
def pressure(self):
"""The measured pressure, in hPa"""
return self._read_data()


def _read_data(self):
"""Read the status & 24-bit data reading"""
self._buffer[0] = 0xAA
self._buffer[1] = 0
self._buffer[2] = 0
with self._i2c as i2c:
# send command
i2c.write(self._buffer, end=3)
# ready busy flag/status
while True:
# check End of Convert pin first, if we can
if self._eoc is not None:
if self._eoc.value:
break
# or you can read the status byte
i2c.readinto(self._buffer, end=1)
if not self._buffer[0] & 0x20:
break
# no longer busy!
i2c.readinto(self._buffer, end=4)

# check other status bits
if self._buffer[0] & 0x01:
raise RuntimeError("Internal math saturation")
if self._buffer[0] & 0x04:
raise RuntimeError("Integrity failure")

# All is good, calculate the PSI and convert to hPA
raw_psi = (self._buffer[1] << 16) | (self._buffer[2] << 8) | self._buffer[3]
# use the 10-90 calibration curve
psi = (raw_psi - 0x19999A) * (self._psimax-self._psimin)
psi /= 0xE66666 - 0x19999A
psi += self._psimin
# convert PSI to hPA
return psi * 68.947572932
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# 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 = ["digitalio", "busio"]
autodoc_mock_imports = ["digitalio", "micropython"]


intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
Expand Down
6 changes: 0 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ Table of Contents
.. toctree::
:caption: Tutorials

.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
the toctree above for use later.

.. toctree::
:caption: Related Products

.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
the toctree above for use later.

.. toctree::
:caption: Other Links

Expand Down
22 changes: 22 additions & 0 deletions examples/mprls_simpletest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import time
import board
import busio
import adafruit_mprls

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

# Simplest use, connect to default over I2C
mpr = adafruit_mprls.MPRLS(i2c, psi_min=0, psi_max=25)

# You can also specify both reset and eoc pins
"""
import digitalio
reset = digitalio.DigitalInOut(board.D5)
eoc = digitalio.DigitalInOut(board.D6)
mpr = adafruit_mprls.MPRLS(i2c, eoc_pin=eoc, reset_pin=reset,
psi_min=0, psi_max=25)
"""

while True:
print((mpr.pressure,))
time.sleep(1)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Adafruit-Blinka
adafruit-circuitpython-busdevice