From fe64873b9997e543740d4f7cbe3db4281a0f88b3 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Mon, 26 Apr 2021 09:51:06 -0400 Subject: [PATCH] improving_docs --- README.rst | 19 ++++---- adafruit_l3gd20.py | 89 +++++++++++++++++++++++++++++------ docs/index.rst | 2 +- examples/l3gd20_simpletest.py | 5 +- 4 files changed, 86 insertions(+), 29 deletions(-) diff --git a/README.rst b/README.rst index ece8109..c5ab627 100644 --- a/README.rst +++ b/README.rst @@ -56,33 +56,30 @@ Usage Example Of course, you must import the library to use it: -.. code:: python +.. code:: python3 import adafruit_l3gd20 -This driver takes an instantiated and active I2C object (from the `busio` or -the `bitbangio` library) as an argument to its constructor. The way to create -an I2C object depends on the board you are using. For boards with labeled SCL -and SDA pins, you can: +This driver takes an instantiated and active I2C object as an argument +to its constructor. -.. code:: python +.. code:: python3 - from busio import I2C - from board import SDA, SCL + import board - i2c = I2C(SCL, SDA) + i2c = board.I2C() Once you have the I2C object, you can create the sensor object: -.. code:: python +.. code:: python3 sensor = adafruit_l3gd20.L3GD20_I2C(i2c) And then you can start reading the measurements: -.. code:: python +.. code:: python3 print(sensor.gyro) diff --git a/adafruit_l3gd20.py b/adafruit_l3gd20.py index e3dec2f..b3e1d79 100644 --- a/adafruit_l3gd20.py +++ b/adafruit_l3gd20.py @@ -18,12 +18,12 @@ **Hardware:** -* `L3GD20H Triple-Axis Gyro Breakout Board `_ +* Adafruit `L3GD20H Triple-Axis Gyro Breakout Board `_ **Software and Dependencies:** * Adafruit CircuitPython firmware for the supported boards: - https://github.com/adafruit/circuitpython/releases + https://circuitpython.org/downloads * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register @@ -77,11 +77,22 @@ class L3GD20: """ Driver for the L3GD20 3-axis Gyroscope sensor. - :param int rng: a range value one of L3DS20_RANGE_250DPS (default), L3DS20_RANGE_500DPS, or - L3DS20_RANGE_2000DPS + :param int rng: a range value one of: - :param int rate: a rate value one of L3DS20_RATE_100HZ (default), L3DS20_RATE_200HZ, - L3DS20_RATE_400HZ, or L3DS20_RATE_800HZ + * :const:`L3DS20_RANGE_250DPS` + * :const:`L3DS20_RANGE_500DPS` + * :const:`L3DS20_RANGE_2000DPS` + + Defaults to :const:`L3DS20_RANGE_250DPS` + + :param int rate: a rate value one of + + * :const:`L3DS20_RATE_100HZ` + * :const:`L3DS20_RATE_200HZ` + * :const:`L3DS20_RATE_400HZ` + * :const:`L3DS20_RATE_800HZ` + + Defaults to :const:`L3DS20_RATE_100HZ` """ def __init__(self, rng=L3DS20_RANGE_250DPS, rate=L3DS20_RATE_100HZ): @@ -194,10 +205,35 @@ class L3GD20_I2C(L3GD20): """ Driver for L3GD20 Gyroscope using I2C communications - :param ~busio.I2C i2c: initialized busio I2C class - :param int rng: the optional range value: L3DS20_RANGE_250DPS(default), L3DS20_RANGE_500DPS, or - L3DS20_RANGE_2000DPS - :param address: the optional device address, 0x68 is the default address + :param ~busio.I2C i2c: The I2C bus the device is connected to + :param int rng: range value. Defaults to :const:`0x68` + :param int rate: rate value. Defaults to :const:`L3DS20_RATE_100HZ` + + + **Quickstart: Importing and using the device** + + Here is an example of using the :class:`L3GD20_I2C` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + import adafruit_l3gd20 + + 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_l3gd20.L3GD20_I2C(i2c) + + Now you have access to the :attr:`gyro` attribute + + .. code-block:: python + + gyro_data = sensor.gyro + + """ gyro_raw = Struct(_L3GD20_REGISTER_OUT_X_L_X80, " + Adafruit Triple Axis Gyro Breakout Learning Guide .. toctree:: :caption: Related Products diff --git a/examples/l3gd20_simpletest.py b/examples/l3gd20_simpletest.py index a6a4ca8..f4cb4e2 100644 --- a/examples/l3gd20_simpletest.py +++ b/examples/l3gd20_simpletest.py @@ -3,11 +3,10 @@ import time import board -import busio import adafruit_l3gd20 # Hardware I2C setup: -I2C = busio.I2C(board.SCL, board.SDA) +I2C = board.I2C() # uses board.SCL and board.SDA # Initializes L3GD20 object using default range, 250dps SENSOR = adafruit_l3gd20.L3GD20_I2C(I2C) # Initialize L3GD20 object using a custom range and output data rate (ODR). @@ -29,7 +28,7 @@ # Hardware SPI setup: # import digitalio # CS = digitalio.DigitalInOut(board.D5) -# SPIB = busio.SPI(board.SCK, board.MOSI, board.MISO) +# SPIB = board.SPI() # SENSOR = adafruit_l3gd20.L3GD20_SPI(SPIB, CS) # SENSOR = adafruit_l3gd20.L3GD20_I2C( # SPIB,