From 23c2c88197d795fc642ca2397f9cda5a42817fc2 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 15 Sep 2019 18:15:34 -0700 Subject: [PATCH 1/6] added option to change I2C address - I2C & SPI classes's docs now have an explanation of what their constructor's parameters are. - added missing information in readme about how to install on Raspberry Pi -implemented I2C address checking to ensure proper functionality when passing non-default addresses --- .gitignore | 3 ++- README.rst | 25 +++++++++++++++++++++++++ adafruit_lsm9ds1.py | 33 +++++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 55f127b..25030c4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ bundles *.DS_Store .eggs dist -**/*.egg-info \ No newline at end of file +**/*.egg-info +.vscode/settings.json diff --git a/README.rst b/README.rst index 824eff7..751acd5 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,31 @@ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading `the Adafruit library and driver bundle `_. +Installing from PyPI +===================== + +On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from +PyPI `_. To install for current user: + +.. code-block:: shell + + pip3 install adafruit-circuitpython-lsm9ds1 + +To install system-wide (this may be required in some cases): + +.. code-block:: shell + + sudo pip3 install adafruit-circuitpython-lsm9ds1 + +To install in a virtual environment in your current project: + +.. code-block:: shell + + mkdir project-name && cd project-name + python3 -m venv .env + source .env/bin/activate + pip3 install adafruit-circuitpython-lsm9ds1 + Usage Example ============= diff --git a/adafruit_lsm9ds1.py b/adafruit_lsm9ds1.py index 1238aa9..c2ea84e 100644 --- a/adafruit_lsm9ds1.py +++ b/adafruit_lsm9ds1.py @@ -363,12 +363,24 @@ def _write_u8(self, sensor_type, address, val): class LSM9DS1_I2C(LSM9DS1): - """Driver for the LSM9DS1 connect over I2C.""" + """Driver for the LSM9DS1 connect over I2C. - def __init__(self, i2c): - self._mag_device = i2c_device.I2CDevice(i2c, _LSM9DS1_ADDRESS_MAG) - self._xg_device = i2c_device.I2CDevice(i2c, _LSM9DS1_ADDRESS_ACCELGYRO) - super().__init__() + :param ~busio.I2C i2c: The I2C bus object used to connect to the LSM9DS1. + + .. note:: This object should be shared among other driver classes that use the same I2C bus (SDA & SCL pins) to connect to different I2C devices. + + :param int mag_address: A 16-bit integer that represents the i2c address of the LSM9DS1's magnetometer. Options are limited to ``0x1C`` or ``0x1E``. Defaults to ``0x1E``. + :param int xg_address: A 16-bit integer that represents the i2c address of the LSM9DS1's accelerometer and gyroscope. Options are limited to ``0x6A`` or ``0x6B``. Defaults to ``0x6B``. + + """ + + def __init__(self, i2c, mag_address=_LSM9DS1_ADDRESS_MAG, xg_address=_LSM9DS1_ADDRESS_ACCELGYRO): + if mag_address in (0x1c, 0x1e) and xg_address in (0x6a, 0x6b): + self._mag_device = i2c_device.I2CDevice(i2c, mag_address) + self._xg_device = i2c_device.I2CDevice(i2c, xg_address) + super().__init__() + else: + raise ValueError('address parmeters are incorrect. Read the docs at https://circuitpython.readthedocs.io/projects/lsm9ds1/en/latest/api.html#adafruit_lsm9ds1.LSM9DS1_I2C') def _read_u8(self, sensor_type, address): if sensor_type == _MAGTYPE: @@ -401,7 +413,16 @@ def _write_u8(self, sensor_type, address, val): class LSM9DS1_SPI(LSM9DS1): - """Driver for the LSM9DS1 connect over SPI.""" + """Driver for the LSM9DS1 connect over SPI. + + :param ~busio.SPI spi: The SPI bus object used to connect to the LSM9DS1. + + .. note:: This object should be shared among other driver classes that use the same SPI bus (SCK, MISO, MOSI pins) to connect to different SPI devices. + + :param ~digitalio.DigitalInOut mcs: The digital output pin connected to the LSM9DS1's CSM (Chip Select Magnetometer) pin. + :param ~digitalio.DigitalInOut xgcs: The digital output pin connected to the LSM9DS1's CSAG (Chip Select Accelerometer/Gyroscope) pin. + + """ # pylint: disable=no-member def __init__(self, spi, xgcs, mcs): self._mag_device = spi_device.SPIDevice(spi, mcs, baudrate=200000, phase=1, polarity=1) From 8c4a695dc3ee8b8d84faa08ec26e65c2d8d8a183 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 15 Sep 2019 18:46:56 -0700 Subject: [PATCH 2/6] line-to-long; I'm addicted to word wrap --- adafruit_lsm9ds1.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/adafruit_lsm9ds1.py b/adafruit_lsm9ds1.py index c2ea84e..af0bdaf 100644 --- a/adafruit_lsm9ds1.py +++ b/adafruit_lsm9ds1.py @@ -367,10 +367,15 @@ class LSM9DS1_I2C(LSM9DS1): :param ~busio.I2C i2c: The I2C bus object used to connect to the LSM9DS1. - .. note:: This object should be shared among other driver classes that use the same I2C bus (SDA & SCL pins) to connect to different I2C devices. + .. note:: This object should be shared among other driver classes that use the + same I2C bus (SDA & SCL pins) to connect to different I2C devices. - :param int mag_address: A 16-bit integer that represents the i2c address of the LSM9DS1's magnetometer. Options are limited to ``0x1C`` or ``0x1E``. Defaults to ``0x1E``. - :param int xg_address: A 16-bit integer that represents the i2c address of the LSM9DS1's accelerometer and gyroscope. Options are limited to ``0x6A`` or ``0x6B``. Defaults to ``0x6B``. + :param int mag_address: A 16-bit integer that represents the i2c address of the + LSM9DS1's magnetometer. Options are limited to ``0x1C`` or ``0x1E``. + Defaults to ``0x1E``. + :param int xg_address: A 16-bit integer that represents the i2c address of the + LSM9DS1's accelerometer and gyroscope. Options are limited to ``0x6A`` or ``0x6B``. + Defaults to ``0x6B``. """ @@ -380,7 +385,8 @@ def __init__(self, i2c, mag_address=_LSM9DS1_ADDRESS_MAG, xg_address=_LSM9DS1_AD self._xg_device = i2c_device.I2CDevice(i2c, xg_address) super().__init__() else: - raise ValueError('address parmeters are incorrect. Read the docs at https://circuitpython.readthedocs.io/projects/lsm9ds1/en/latest/api.html#adafruit_lsm9ds1.LSM9DS1_I2C') + raise ValueError('address parmeters are incorrect. Read the docs at ' + 'https://circuitpython.rtfd.io/projects/lsm9ds1/en/latest/api.html#adafruit_lsm9ds1.LSM9DS1_I2C') def _read_u8(self, sensor_type, address): if sensor_type == _MAGTYPE: @@ -417,10 +423,13 @@ class LSM9DS1_SPI(LSM9DS1): :param ~busio.SPI spi: The SPI bus object used to connect to the LSM9DS1. - .. note:: This object should be shared among other driver classes that use the same SPI bus (SCK, MISO, MOSI pins) to connect to different SPI devices. + .. note:: This object should be shared among other driver classes that use the + same SPI bus (SCK, MISO, MOSI pins) to connect to different SPI devices. - :param ~digitalio.DigitalInOut mcs: The digital output pin connected to the LSM9DS1's CSM (Chip Select Magnetometer) pin. - :param ~digitalio.DigitalInOut xgcs: The digital output pin connected to the LSM9DS1's CSAG (Chip Select Accelerometer/Gyroscope) pin. + :param ~digitalio.DigitalInOut mcs: The digital output pin connected to the + LSM9DS1's CSM (Chip Select Magnetometer) pin. + :param ~digitalio.DigitalInOut xgcs: The digital output pin connected to the + LSM9DS1's CSAG (Chip Select Accelerometer/Gyroscope) pin. """ # pylint: disable=no-member From 4f19cc007e42602571dde192db5ccd62e038fea7 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 15 Sep 2019 19:15:40 -0700 Subject: [PATCH 3/6] forgot I could run local checks w/ sphinx & pylint --- adafruit_lsm9ds1.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/adafruit_lsm9ds1.py b/adafruit_lsm9ds1.py index af0bdaf..5fb9b70 100644 --- a/adafruit_lsm9ds1.py +++ b/adafruit_lsm9ds1.py @@ -368,25 +368,27 @@ class LSM9DS1_I2C(LSM9DS1): :param ~busio.I2C i2c: The I2C bus object used to connect to the LSM9DS1. .. note:: This object should be shared among other driver classes that use the - same I2C bus (SDA & SCL pins) to connect to different I2C devices. + same I2C bus (SDA & SCL pins) to connect to different I2C devices. :param int mag_address: A 16-bit integer that represents the i2c address of the - LSM9DS1's magnetometer. Options are limited to ``0x1C`` or ``0x1E``. - Defaults to ``0x1E``. + LSM9DS1's magnetometer. Options are limited to ``0x1C`` or ``0x1E``. + Defaults to ``0x1E``. + :param int xg_address: A 16-bit integer that represents the i2c address of the - LSM9DS1's accelerometer and gyroscope. Options are limited to ``0x6A`` or ``0x6B``. - Defaults to ``0x6B``. + LSM9DS1's accelerometer and gyroscope. Options are limited to ``0x6A`` or ``0x6B``. + Defaults to ``0x6B``. """ - - def __init__(self, i2c, mag_address=_LSM9DS1_ADDRESS_MAG, xg_address=_LSM9DS1_ADDRESS_ACCELGYRO): + def __init__(self, i2c, mag_address=_LSM9DS1_ADDRESS_MAG, + xg_address=_LSM9DS1_ADDRESS_ACCELGYRO): if mag_address in (0x1c, 0x1e) and xg_address in (0x6a, 0x6b): self._mag_device = i2c_device.I2CDevice(i2c, mag_address) self._xg_device = i2c_device.I2CDevice(i2c, xg_address) super().__init__() else: raise ValueError('address parmeters are incorrect. Read the docs at ' - 'https://circuitpython.rtfd.io/projects/lsm9ds1/en/latest/api.html#adafruit_lsm9ds1.LSM9DS1_I2C') + 'circuitpython.rtfd.io/projects/lsm9ds1/en/latest' + '/api.html#adafruit_lsm9ds1.LSM9DS1_I2C') def _read_u8(self, sensor_type, address): if sensor_type == _MAGTYPE: @@ -424,12 +426,13 @@ class LSM9DS1_SPI(LSM9DS1): :param ~busio.SPI spi: The SPI bus object used to connect to the LSM9DS1. .. note:: This object should be shared among other driver classes that use the - same SPI bus (SCK, MISO, MOSI pins) to connect to different SPI devices. + same SPI bus (SCK, MISO, MOSI pins) to connect to different SPI devices. :param ~digitalio.DigitalInOut mcs: The digital output pin connected to the - LSM9DS1's CSM (Chip Select Magnetometer) pin. + LSM9DS1's CSM (Chip Select Magnetometer) pin. + :param ~digitalio.DigitalInOut xgcs: The digital output pin connected to the - LSM9DS1's CSAG (Chip Select Accelerometer/Gyroscope) pin. + LSM9DS1's CSAG (Chip Select Accelerometer/Gyroscope) pin. """ # pylint: disable=no-member From 23d3e3a8c7f2984839002059041266cdb571a5db Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 15 Sep 2019 19:21:44 -0700 Subject: [PATCH 4/6] oops - blind CnP --- README.rst | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.rst b/README.rst index 751acd5..a17d41c 100644 --- a/README.rst +++ b/README.rst @@ -43,15 +43,6 @@ To install system-wide (this may be required in some cases): sudo pip3 install adafruit-circuitpython-lsm9ds1 -To install in a virtual environment in your current project: - -.. code-block:: shell - - mkdir project-name && cd project-name - python3 -m venv .env - source .env/bin/activate - pip3 install adafruit-circuitpython-lsm9ds1 - Usage Example ============= From 835eeba72dcefeec35c3c5ddd76063430fafd33f Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 15 Sep 2019 21:16:11 -0700 Subject: [PATCH 5/6] only saw 1/2 the message removed install in readme --- README.rst | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/README.rst b/README.rst index a17d41c..824eff7 100644 --- a/README.rst +++ b/README.rst @@ -27,22 +27,6 @@ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading `the Adafruit library and driver bundle `_. -Installing from PyPI -===================== - -On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from -PyPI `_. To install for current user: - -.. code-block:: shell - - pip3 install adafruit-circuitpython-lsm9ds1 - -To install system-wide (this may be required in some cases): - -.. code-block:: shell - - sudo pip3 install adafruit-circuitpython-lsm9ds1 - Usage Example ============= From 96282bba8809cf08a3c4fd85f89146bc471f2a0a Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 15 Sep 2019 22:15:42 -0700 Subject: [PATCH 6/6] typo: 16-bit to 8-bit --- adafruit_lsm9ds1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_lsm9ds1.py b/adafruit_lsm9ds1.py index 5fb9b70..49bb683 100644 --- a/adafruit_lsm9ds1.py +++ b/adafruit_lsm9ds1.py @@ -370,11 +370,11 @@ class LSM9DS1_I2C(LSM9DS1): .. note:: This object should be shared among other driver classes that use the same I2C bus (SDA & SCL pins) to connect to different I2C devices. - :param int mag_address: A 16-bit integer that represents the i2c address of the + :param int mag_address: A 8-bit integer that represents the i2c address of the LSM9DS1's magnetometer. Options are limited to ``0x1C`` or ``0x1E``. Defaults to ``0x1E``. - :param int xg_address: A 16-bit integer that represents the i2c address of the + :param int xg_address: A 8-bit integer that represents the i2c address of the LSM9DS1's accelerometer and gyroscope. Options are limited to ``0x6A`` or ``0x6B``. Defaults to ``0x6B``.