-
Notifications
You must be signed in to change notification settings - Fork 4
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
mini lint #2
Changes from 10 commits
8a361eb
21ee013
2245f07
6b0ad22
7335a0b
4c26bef
c67bc99
acb4c75
4a97ba5
65240fd
68f3d7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 RuntimeError("Min PSI must be < max!") | ||
self._psimax = psi_max | ||
self._psimin = psi_min | ||
# That's pretty much it, there's no ID register :( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The no ID register is a super bummer. I hesitate to recommend conditionals for the I would check that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added! |
||
|
||
@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 | ||
sommersoft marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", "busio", "micropython"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently this one got lost on my initial review too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, fixed! |
||
|
||
|
||
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)} | ||
|
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Adafruit-Blinka | ||
adafruit-circuitpython-busdevice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit-noid alert: shouldn't this be a ValueError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, fixed!