From ed9912323d1910e54c7ee1f9cf4d5e2f9bf9994b Mon Sep 17 00:00:00 2001 From: caternuson Date: Thu, 25 Aug 2022 15:34:09 -0700 Subject: [PATCH 1/3] add msa311 --- README.rst | 6 +- adafruit_msa301.py => adafruit_msa3xx.py | 159 +++++++++++------------ docs/api.rst | 2 +- docs/index.rst | 1 + examples/msa301_simpletest.py | 4 +- examples/msa301_tap_example.py | 4 +- examples/msa311_simpletest.py | 13 ++ pyproject.toml | 5 +- 8 files changed, 104 insertions(+), 90 deletions(-) rename adafruit_msa301.py => adafruit_msa3xx.py (79%) create mode 100644 examples/msa311_simpletest.py diff --git a/README.rst b/README.rst index 3c54ec6..d625a6f 100644 --- a/README.rst +++ b/README.rst @@ -17,7 +17,7 @@ Introduction :target: https://github.com/psf/black :alt: Code Style: Black -CircuitPython library for the MSA301 Accelerometer +CircuitPython library for the MSA301/MSA311 Accelerometers Dependencies @@ -63,10 +63,10 @@ Usage Example import time import board - import adafruit_msa301 + from adafruit_msa3xx import MSA301 i2c = board.I2C() # uses board.SCL and board.SDA - msa = adafruit_msa301.MSA301(i2c) + msa = MSA301(i2c) while True: print("%f %f %f"%msa.acceleration) diff --git a/adafruit_msa301.py b/adafruit_msa3xx.py similarity index 79% rename from adafruit_msa301.py rename to adafruit_msa3xx.py index 1b62c22..83ce414 100644 --- a/adafruit_msa301.py +++ b/adafruit_msa3xx.py @@ -3,10 +3,10 @@ # SPDX-License-Identifier: MIT """ -`MSA301` +`adafruit_msa3xx` ================================================================================ -CircuitPython library for the MSA301 Accelerometer +CircuitPython library for the MSA301 and MSA311 Accelerometers * Author(s): Bryan Siepert @@ -18,6 +18,8 @@ * Adafruit `MSA301 Triple Axis Accelerometer `_ +* Adafruit `MSA311 Triple Axis Accelerometer + `_ **Software and Dependencies:** @@ -30,7 +32,7 @@ """ __version__ = "0.0.0+auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MSA301.git" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython.git" from micropython import const from adafruit_register.i2c_struct import Struct, ROUnaryStruct @@ -39,25 +41,26 @@ import adafruit_bus_device.i2c_device as i2cdevice _MSA301_I2CADDR_DEFAULT = const(0x26) - -_MSA301_REG_PARTID = const(0x01) -_MSA301_REG_OUT_X_L = const(0x02) -_MSA301_REG_OUT_X_H = const(0x03) -_MSA301_REG_OUT_Y_L = const(0x04) -_MSA301_REG_OUT_Y_H = const(0x05) -_MSA301_REG_OUT_Z_L = const(0x06) -_MSA301_REG_OUT_Z_H = const(0x07) -_MSA301_REG_MOTIONINT = const(0x09) -_MSA301_REG_DATAINT = const(0x0A) -_MSA301_REG_RESRANGE = const(0x0F) -_MSA301_REG_ODR = const(0x10) -_MSA301_REG_POWERMODE = const(0x11) -_MSA301_REG_INTSET0 = const(0x16) -_MSA301_REG_INTSET1 = const(0x17) -_MSA301_REG_INTMAP0 = const(0x19) -_MSA301_REG_INTMAP1 = const(0x1A) -_MSA301_REG_TAPDUR = const(0x2A) -_MSA301_REG_TAPTH = const(0x2B) +_MSA311_I2CADDR_DEFAULT = const(0x62) + +_REG_PARTID = const(0x01) +_REG_OUT_X_L = const(0x02) +_REG_OUT_X_H = const(0x03) +_REG_OUT_Y_L = const(0x04) +_REG_OUT_Y_H = const(0x05) +_REG_OUT_Z_L = const(0x06) +_REG_OUT_Z_H = const(0x07) +_REG_MOTIONINT = const(0x09) +_REG_DATAINT = const(0x0A) +_REG_RESRANGE = const(0x0F) +_REG_ODR = const(0x10) +_REG_POWERMODE = const(0x11) +_REG_INTSET0 = const(0x16) +_REG_INTSET1 = const(0x17) +_REG_INTMAP0 = const(0x19) +_REG_INTMAP1 = const(0x1A) +_REG_TAPDUR = const(0x2A) +_REG_TAPTH = const(0x2B) _STANDARD_GRAVITY = 9.806 @@ -200,45 +203,39 @@ class TapDuration: # pylint: disable=too-few-public-methods,too-many-instance-a DURATION_700_MS = 0b111 # < 50 millis700 millis -class MSA301: # pylint: disable=too-many-instance-attributes - """Driver for the MSA301 Accelerometer. - - :param ~busio.I2C i2c_bus: The I2C bus the MSA is connected to. - - - **Quickstart: Importing and using the device** - - Here is an example of using the :class:`MSA301` class. - First you will need to import the libraries to use the sensor - - .. code-block:: python - - import board - import adafruit_msa301 - - 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 - msa = adafruit_msa301.MSA301(i2c) - - Now you have access to the :attr:`acceleration` attribute +class MSA3XX: # pylint: disable=too-many-instance-attributes + """Base driver class for the MSA301/311 Accelerometers. + """ - .. code-block:: python + _part_id = ROUnaryStruct(_REG_PARTID, " + Adafruit MSA311 Triple Axis Accelerometer .. toctree:: :caption: Other Links diff --git a/examples/msa301_simpletest.py b/examples/msa301_simpletest.py index 8ea9b54..93fc3bf 100755 --- a/examples/msa301_simpletest.py +++ b/examples/msa301_simpletest.py @@ -3,10 +3,10 @@ import time import board -import adafruit_msa301 +from adafruit_msa3xx import MSA301 i2c = board.I2C() # uses board.SCL and board.SDA -msa = adafruit_msa301.MSA301(i2c) +msa = MSA301(i2c) while True: print("%f %f %f" % msa.acceleration) diff --git a/examples/msa301_tap_example.py b/examples/msa301_tap_example.py index 72b6967..bb1dc03 100644 --- a/examples/msa301_tap_example.py +++ b/examples/msa301_tap_example.py @@ -3,10 +3,10 @@ import time import board -import adafruit_msa301 +from adafruit_msa3xx import MSA301 i2c = board.I2C() # uses board.SCL and board.SDA -msa = adafruit_msa301.MSA301(i2c) +msa = MSA301(i2c) msa.enable_tap_detection() diff --git a/examples/msa311_simpletest.py b/examples/msa311_simpletest.py new file mode 100644 index 0000000..9bd475a --- /dev/null +++ b/examples/msa311_simpletest.py @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +import time +import board +from adafruit_msa3xx import MSA311 + +i2c = board.I2C() # uses board.SCL and board.SDA +msa = MSA311(i2c) + +while True: + print("%f %f %f" % msa.acceleration) + time.sleep(0.5) diff --git a/pyproject.toml b/pyproject.toml index b94ec09..2c845c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ requires = [ [project] name = "adafruit-circuitpython-msa301" -description = "CircuitPython library for the MSA301 Accelerometer" +description = "CircuitPython library for the MSA301/MSA311 Accelerometers" version = "0.0.0+auto.0" readme = "README.rst" authors = [ @@ -24,6 +24,7 @@ keywords = [ "circuitpython", "micropython", "msa301", + "msa311", "accelerometer", "msa", ] @@ -39,7 +40,7 @@ classifiers = [ dynamic = ["dependencies", "optional-dependencies"] [tool.setuptools] -py-modules = ["adafruit_msa301"] +py-modules = ["adafruit_msa3xx"] [tool.setuptools.dynamic] dependencies = {file = ["requirements.txt"]} From ef1d33fe7adf769683e908e11f545cf4fa887057 Mon Sep 17 00:00:00 2001 From: caternuson Date: Thu, 25 Aug 2022 16:01:01 -0700 Subject: [PATCH 2/3] black and lint --- adafruit_msa3xx.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/adafruit_msa3xx.py b/adafruit_msa3xx.py index 83ce414..0499a67 100644 --- a/adafruit_msa3xx.py +++ b/adafruit_msa3xx.py @@ -204,8 +204,7 @@ class TapDuration: # pylint: disable=too-few-public-methods,too-many-instance-a class MSA3XX: # pylint: disable=too-many-instance-attributes - """Base driver class for the MSA301/311 Accelerometers. - """ + """Base driver class for the MSA301/311 Accelerometers.""" _part_id = ROUnaryStruct(_REG_PARTID, " Date: Thu, 25 Aug 2022 16:52:25 -0700 Subject: [PATCH 3/3] fix typo Co-authored-by: Dan Halbert --- adafruit_msa3xx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_msa3xx.py b/adafruit_msa3xx.py index 0499a67..870e9f3 100644 --- a/adafruit_msa3xx.py +++ b/adafruit_msa3xx.py @@ -32,7 +32,7 @@ """ __version__ = "0.0.0+auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython.git" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MSA301.git" from micropython import const from adafruit_register.i2c_struct import Struct, ROUnaryStruct