From 17c00a117f5b877f6bf7fc30709bdc0b83fbddb3 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 27 Apr 2021 11:08:26 -0400 Subject: [PATCH] improving_docs --- README.rst | 5 +-- adafruit_lsm303_accel.py | 58 ++++++++++++++++---------- docs/examples.rst | 25 +++++++++++ docs/index.rst | 4 ++ examples/lsm303_accel_fast.py | 5 +-- examples/lsm303_accel_inclinometer.py | 3 +- examples/lsm303_accel_simpletest.py | 3 +- examples/lsm303_accel_tap_detection.py | 3 +- 8 files changed, 72 insertions(+), 34 deletions(-) diff --git a/README.rst b/README.rst index 2d495c7..79b8a38 100644 --- a/README.rst +++ b/README.rst @@ -56,14 +56,13 @@ To install in a virtual environment in your current project: Usage Example ============= -.. code-block:: python +.. code-block:: python3 import time import board - import busio import adafruit_lsm303_accel - i2c = busio.I2C(board.SCL, board.SDA) + i2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lsm303_accel.LSM303_Accel(i2c) while True: diff --git a/adafruit_lsm303_accel.py b/adafruit_lsm303_accel.py index be6d85e..726d9bc 100644 --- a/adafruit_lsm303_accel.py +++ b/adafruit_lsm303_accel.py @@ -23,7 +23,7 @@ **Software and Dependencies:** -* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: +* Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice @@ -124,7 +124,36 @@ class Range: class LSM303_Accel: # pylint:disable=too-many-instance-attributes - """Driver for the LSM303's accelerometer.""" + """Driver for the LSM303's accelerometer. + + :param ~busio.I2C i2c: The I2C bus the device is connected to. + + + **Quickstart: Importing and using the device** + + Here is an example of using the :class:`LSM303_Accel` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + import adafruit_lsm303_accel + + 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 + sensor = adafruit_lsm303_accel.LSM303_Accel(i2c) + + Now you have access to the :attr:`acceleration` attribute + + .. code-block:: python + + acc_x, acc_y, acc_z = sensor.acceleration + + + """ # Class-level buffer for reading and writing data with the sensor. # This reduces memory allocations but means the code is not re-entrant or @@ -141,22 +170,7 @@ class LSM303_Accel: # pylint:disable=too-many-instance-attributes _act_threshold = UnaryStruct(_REG_ACCEL_ACT_THS_A, "B") _act_duration = UnaryStruct(_REG_ACCEL_ACT_DUR_A, "B") - """ - .. code-block:: python - - import board - i2c = board.I2C() - - import adafruit_lsm303_accel - accel = adafruit_lsm303_accel.LSM303_Accel(i2c) - accel._act_threshold = 20 - accel._act_duration = 1 - accel._int2_activity_enable = True - - # toggle pins, defaults to False - accel._int_pin_active_low = True - """ _data_rate = RWBits(4, _REG_ACCEL_CTRL_REG1_A, 4) _enable_xyz = RWBits(3, _REG_ACCEL_CTRL_REG1_A, 0) _raw_accel_data = StructArray(_REG_ACCEL_OUT_X_L_A, " + + FLORA Accelerometer/Compass Sensor - LSM303 Learning Guide + .. toctree:: :caption: Related Products diff --git a/examples/lsm303_accel_fast.py b/examples/lsm303_accel_fast.py index be0036d..87d21c1 100644 --- a/examples/lsm303_accel_fast.py +++ b/examples/lsm303_accel_fast.py @@ -4,12 +4,11 @@ """ Read data from the accelerometer and print it out, ASAP! """ import board -import busio - import adafruit_lsm303_accel -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lsm303_accel.LSM303_Accel(i2c) + while True: accel_x, accel_y, accel_z = sensor.acceleration print("{0:10.3f} {1:10.3f} {2:10.3f}".format(accel_x, accel_y, accel_z)) diff --git a/examples/lsm303_accel_inclinometer.py b/examples/lsm303_accel_inclinometer.py index ebe90a3..fdbb4a4 100644 --- a/examples/lsm303_accel_inclinometer.py +++ b/examples/lsm303_accel_inclinometer.py @@ -6,11 +6,10 @@ import time from math import atan2, degrees import board -import busio import adafruit_lsm303_accel -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lsm303_accel.LSM303_Accel(i2c) diff --git a/examples/lsm303_accel_simpletest.py b/examples/lsm303_accel_simpletest.py index 519fe82..790158a 100644 --- a/examples/lsm303_accel_simpletest.py +++ b/examples/lsm303_accel_simpletest.py @@ -5,10 +5,9 @@ import time import board -import busio import adafruit_lsm303_accel -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lsm303_accel.LSM303_Accel(i2c) while True: diff --git a/examples/lsm303_accel_tap_detection.py b/examples/lsm303_accel_tap_detection.py index 51525b2..4b8dd14 100644 --- a/examples/lsm303_accel_tap_detection.py +++ b/examples/lsm303_accel_tap_detection.py @@ -2,10 +2,9 @@ # SPDX-License-Identifier: MIT import board -import busio import adafruit_lsm303_accel -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA accel = adafruit_lsm303_accel.LSM303_Accel(i2c) accel.range = adafruit_lsm303_accel.Range.RANGE_8G accel.set_tap(1, 30)