diff --git a/README.rst b/README.rst index 1aadd9b..b8f94fc 100644 --- a/README.rst +++ b/README.rst @@ -29,6 +29,8 @@ These drivers depends on: * `NeoPixel `_ * `DS3231 `_ * `ST7735R `_ +* `ADXL34x `_ +* `ADT7410 `_ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading diff --git a/adafruit_featherwing/tempmotion_featherwing.py b/adafruit_featherwing/tempmotion_featherwing.py new file mode 100755 index 0000000..bb70530 --- /dev/null +++ b/adafruit_featherwing/tempmotion_featherwing.py @@ -0,0 +1,119 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_featherwing.tempmotion_featherwing` +==================================================== + +Helper for using the `Adafruit ADXL343 + ADT7410 Sensor FeatherWing +`_. + +* Author(s): Melissa LeBlanc-Williams +""" + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" + +import board +import adafruit_adxl34x +import adafruit_adt7410 + +class TempMotionFeatherWing: + """Class helper representing an `Adafruit ADXL343 + ADT7410 Sensor FeatherWing + `_. + + Automatically uses the feather's I2C bus.""" + def __init__(self, adxl343_address=0x53, adt7410_address=0x48, i2c=None): + if i2c is None: + i2c = board.I2C() + self._adxl343 = adafruit_adxl34x.ADXL345(i2c, address=adxl343_address) + self._adt7410 = adafruit_adt7410.ADT7410(i2c, address=adt7410_address) + + @property + def temperature(self): + """Returns ADT7410 Temperature""" + return self._adt7410.temperature + + @property + def status(self): + """Returns the ADT7410 Status""" + return self._adt7410.status + + @property + def configuration(self): + """Returns the ADT7410 Configuration""" + return self._adt7410.configuration + + @configuration.setter + def configuration(self, val): + self._adt7410.configuration = val + + @property + def acceleration(self): + """Returns the ADXL343 Acceleration""" + return self._adxl343.acceleration + + @property + def events(self): + """Returns the ADXL343 Enabled Events""" + return self._adxl343.events + + def enable_motion_detection(self, **kwargs): + """Enable motion detection""" + self._adxl343.enable_motion_detection(**kwargs) + + def disable_motion_detection(self): + """Disable motion detection""" + self._adxl343.disable_motion_detection() + + def enable_freefall_detection(self, **kwargs): + """Enable freefall detection""" + self._adxl343.enable_freefall_detection(**kwargs) + + def disable_freefall_detection(self): + """Disable freefall detection""" + self._adxl343.disable_freefall_detection() + + def enable_tap_detection(self, **kwargs): + """Enable freefall detection""" + self._adxl343.enable_tap_detection(**kwargs) + + def disable_tap_detection(self): + """Disable freefall detection""" + self._adxl343.disable_tap_detection() + + @property + def data_rate(self): + """The data rate of the sensor.""" + return self._adxl343.data_rate + + @data_rate.setter + def data_rate(self, val): + self._adxl343.data_rate = val + + @property + def range(self): + """The measurement range of the sensor.""" + return self._adxl343.range + + @range.setter + def range(self, val): + self._adxl343.range = val diff --git a/docs/api.rst b/docs/api.rst index 3d0c389..77997cc 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -27,3 +27,6 @@ .. automodule:: adafruit_featherwing.minitft_featherwing :members: + +.. automodule:: adafruit_featherwing.tempmotion_featherwing + :members: diff --git a/docs/examples.rst b/docs/examples.rst index dec7d88..88ab7ee 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -43,6 +43,10 @@ Ensure your device works with this simple test. :caption: examples/featherwing_minitft_simpletest.py :linenos: +.. literalinclude:: ../examples/featherwing_tempmotion_simpletest.py + :caption: examples/featherwing_tempmotion_simpletest.py + :linenos: + Other Examples --------------- diff --git a/examples/featherwing_tempmotion_simpletest.py b/examples/featherwing_tempmotion_simpletest.py new file mode 100644 index 0000000..30b4b07 --- /dev/null +++ b/examples/featherwing_tempmotion_simpletest.py @@ -0,0 +1,13 @@ +""" +This example will show the current temperature in the Serial Console +whenever the FeatherWing senses that it has been tapped +""" + +import time +from adafruit_featherwing import tempmotion_featherwing +temp_motion = tempmotion_featherwing.TempMotionFeatherWing() +temp_motion.enable_tap_detection() +while True: + if temp_motion.events['tap']: + print("The temperature is %f"%temp_motion.temperature) + time.sleep(1) diff --git a/requirements.txt b/requirements.txt index a0f7a50..ce7aa7c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,5 @@ adafruit-circuitpython-dotstar adafruit-circuitpython-neopixel adafruit-circuitpython-ds3231 adafruit-circuitpython-gps +adafruit-circuitpython-adxl34x +adafruit-circuitpython-adt7410 diff --git a/setup.py b/setup.py index 643597f..faebf0a 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,8 @@ 'adafruit-circuitpython-register', 'adafruit-circuitpython-ina219', 'adafruit-circuitpython-seesaw', 'adafruit-circuitpython-ht16k33', 'adafruit-circuitpython-dotstar', 'adafruit-circuitpython-neopixel', - 'adafruit-circuitpython-ds3231', 'adafruit-circuitpython-gps'], + 'adafruit-circuitpython-ds3231', 'adafruit-circuitpython-gps', + 'adafruit-circuitpython-adxl34x', 'adafruit-circuitpython-adt7410'], # Choose your license license='MIT',