Skip to content

Commit 23070d5

Browse files
authored
Merge pull request #29 from jposada202020/improving_docs
improving_docs
2 parents 06dd7d3 + 1ed1fc4 commit 23070d5

File tree

3 files changed

+82
-23
lines changed

3 files changed

+82
-23
lines changed

adafruit_lsm9ds1.py

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
2525
**Software and Dependencies:**
2626
27-
* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
28-
https://github.com/adafruit/circuitpython/releases
29-
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
27+
* Adafruit CircuitPython firmware for the supported boards:
28+
https://circuitpython.org/downloads
29+
* Adafruit's Bus Device library:
30+
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
3031
"""
3132

3233
__version__ = "0.0.0-auto.0"
@@ -166,10 +167,12 @@ def __init__(self):
166167
@property
167168
def accel_range(self):
168169
"""The accelerometer range. Must be a value of:
170+
169171
- ACCELRANGE_2G
170172
- ACCELRANGE_4G
171173
- ACCELRANGE_8G
172174
- ACCELRANGE_16G
175+
173176
"""
174177
reg = self._read_u8(_XGTYPE, _LSM9DS1_REGISTER_CTRL_REG6_XL)
175178
return (reg & 0b00011000) & 0xFF
@@ -193,10 +196,12 @@ def accel_range(self, val):
193196
@property
194197
def mag_gain(self):
195198
"""The magnetometer gain. Must be a value of:
199+
196200
- MAGGAIN_4GAUSS
197201
- MAGGAIN_8GAUSS
198202
- MAGGAIN_12GAUSS
199203
- MAGGAIN_16GAUSS
204+
200205
"""
201206
reg = self._read_u8(_MAGTYPE, _LSM9DS1_REGISTER_CTRL_REG2_M)
202207
return (reg & 0b01100000) & 0xFF
@@ -220,9 +225,11 @@ def mag_gain(self, val):
220225
@property
221226
def gyro_scale(self):
222227
"""The gyroscope scale. Must be a value of:
223-
- GYROSCALE_245DPS
224-
- GYROSCALE_500DPS
225-
- GYROSCALE_2000DPS
228+
229+
* GYROSCALE_245DPS
230+
* GYROSCALE_500DPS
231+
* GYROSCALE_2000DPS
232+
226233
"""
227234
reg = self._read_u8(_XGTYPE, _LSM9DS1_REGISTER_CTRL_REG1_G)
228235
return (reg & 0b00011000) & 0xFF
@@ -255,7 +262,7 @@ def read_accel_raw(self):
255262
@property
256263
def acceleration(self):
257264
"""The accelerometer X, Y, Z axis values as a 3-tuple of
258-
m/s^2 values.
265+
:math:`m/s^2` values.
259266
"""
260267
raw = self.read_accel_raw()
261268
return map(
@@ -345,18 +352,44 @@ def _write_u8(self, sensor_type, address, val):
345352
class LSM9DS1_I2C(LSM9DS1):
346353
"""Driver for the LSM9DS1 connect over I2C.
347354
348-
:param ~busio.I2C i2c: The I2C bus object used to connect to the LSM9DS1.
349-
350-
.. note:: This object should be shared among other driver classes that use the
351-
same I2C bus (SDA & SCL pins) to connect to different I2C devices.
355+
:param ~busio.I2C i2c: The I2C bus the device is connected to
352356
353357
:param int mag_address: A 8-bit integer that represents the i2c address of the
354-
LSM9DS1's magnetometer. Options are limited to ``0x1C`` or ``0x1E``.
355-
Defaults to ``0x1E``.
358+
LSM9DS1's magnetometer. Options are limited to :const:`0x1C` or :const:`0x1E`
359+
Defaults to :const:`0x1E`.
356360
357361
:param int xg_address: A 8-bit integer that represents the i2c address of the
358-
LSM9DS1's accelerometer and gyroscope. Options are limited to ``0x6A`` or ``0x6B``.
359-
Defaults to ``0x6B``.
362+
LSM9DS1's accelerometer and gyroscope. Options are limited to :const:`0x6A`
363+
or :const:`0x6B`. Defaults to :const:`0x6B`.
364+
365+
366+
**Quickstart: Importing and using the device**
367+
368+
Here is an example of using the :class:`LSM9DS1` class.
369+
First you will need to import the libraries to use the sensor
370+
371+
.. code-block:: python
372+
373+
import board
374+
import adafruit_lsm9ds1
375+
376+
Once this is done you can define your `board.I2C` object and define your sensor object
377+
378+
.. code-block:: python
379+
380+
i2c = board.I2C() # uses board.SCL and board.SDA
381+
sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)
382+
383+
Now you have access to the :attr:`acceleration`, :attr:`magnetic`
384+
:attr:`gyro` and :attr:`temperature` attributes
385+
386+
.. code-block:: python
387+
388+
acc_x, acc_y, acc_z = sensor.acceleration
389+
mag_x, mag_y, mag_z = sensor.magnetic
390+
gyro_x, gyro_y, gyro_z = sensor.gyro
391+
temp = sensor.temperature
392+
360393
361394
"""
362395

@@ -412,17 +445,42 @@ def _write_u8(self, sensor_type, address, val):
412445
class LSM9DS1_SPI(LSM9DS1):
413446
"""Driver for the LSM9DS1 connect over SPI.
414447
415-
:param ~busio.SPI spi: The SPI bus object used to connect to the LSM9DS1.
416-
417-
.. note:: This object should be shared among other driver classes that use the
418-
same SPI bus (SCK, MISO, MOSI pins) to connect to different SPI devices.
448+
:param ~busio.SPI spi: The SPI bus the device is connected to
419449
420450
:param ~digitalio.DigitalInOut mcs: The digital output pin connected to the
421451
LSM9DS1's CSM (Chip Select Magnetometer) pin.
422452
423453
:param ~digitalio.DigitalInOut xgcs: The digital output pin connected to the
424454
LSM9DS1's CSAG (Chip Select Accelerometer/Gyroscope) pin.
425455
456+
457+
**Quickstart: Importing and using the device**
458+
459+
Here is an example of using the :class:`LSM9DS1` class.
460+
First you will need to import the libraries to use the sensor
461+
462+
.. code-block:: python
463+
464+
import board
465+
import adafruit_lsm9ds1
466+
467+
Once this is done you can define your `board.SPI` object and define your sensor object
468+
469+
.. code-block:: python
470+
471+
spi = board.SPI()
472+
sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi)
473+
474+
Now you have access to the :attr:`acceleration`, :attr:`magnetic`
475+
:attr:`gyro` and :attr:`temperature` attributes
476+
477+
.. code-block:: python
478+
479+
acc_x, acc_y, acc_z = sensor.acceleration
480+
mag_x, mag_y, mag_z = sensor.magnetic
481+
gyro_x, gyro_y, gyro_z = sensor.gyro
482+
temp = sensor.temperature
483+
426484
"""
427485

428486
# pylint: disable=no-member

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26+
Adafruit 9-DOF Accel/Mag/Gyro+Temp Breakout Board - LSM9DS1 Learning Guide <https://learn.adafruit.com/adafruit-lsm9ds1-accelerometer-plus-gyro-plus-magnetometer-9-dof-breakout/overview>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

examples/lsm9ds1_simpletest.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
# Will print the acceleration, magnetometer, and gyroscope values every second.
66
import time
77
import board
8-
import busio
98
import adafruit_lsm9ds1
109

11-
# I2C connection:
12-
i2c = busio.I2C(board.SCL, board.SDA)
10+
# Create sensor object, communicating over the board's default I2C bus
11+
i2c = board.I2C() # uses board.SCL and board.SDA
1312
sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)
1413

1514
# SPI connection:
1615
# from digitalio import DigitalInOut, Direction
17-
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
16+
# spi = board.SPI()
1817
# csag = DigitalInOut(board.D5)
1918
# csag.direction = Direction.OUTPUT
2019
# csag.value = True

0 commit comments

Comments
 (0)