Skip to content

improving_docs #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
89 changes: 75 additions & 14 deletions adafruit_l3gd20.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

**Hardware:**

* `L3GD20H Triple-Axis Gyro Breakout Board <https://www.adafruit.com/product/1032>`_
* Adafruit `L3GD20H Triple-Axis Gyro Breakout Board <https://www.adafruit.com/product/1032>`_

**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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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, "<hhh")
Expand Down Expand Up @@ -240,11 +276,36 @@ class L3GD20_SPI(L3GD20):
"""
Driver for L3GD20 Gyroscope using SPI communications

:param ~busio.SPI spi_busio: initialized busio SPI class
:param ~busio.SPI spi_busio: The SPI bus the device is connected to
:param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal
:param int rng: the optional range value: L3DS20_RANGE_250DPS(default), L3DS20_RANGE_500DPS, or
L3DS20_RANGE_2000DPS
:param baudrate: spi baud rate default is 100000
:param int rng: range value. Defaults to :const:`L3DS20_RANGE_250DPS`.
:param baudrate: SPI baud rate. Defaults to :const:`100000`
: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_SPI` 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.SPI` object and define your sensor object

.. code-block:: python

spi = board.SPI()
sensor = adafruit_l3gd20.L3GD20_SPI(spi)

Now you have access to the :attr:`gyro` attribute

.. code-block:: python

gyro_data = sensor.gyro


"""

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Table of Contents
.. toctree::
:caption: Tutorials

Adafruit Triple Axis Gyro Breakout <https://learn.adafruit.com/adafruit-triple-axis-gyro-breakout>
Adafruit Triple Axis Gyro Breakout Learning Guide <https://learn.adafruit.com/adafruit-triple-axis-gyro-breakout>

.. toctree::
:caption: Related Products
Expand Down
5 changes: 2 additions & 3 deletions examples/l3gd20_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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,
Expand Down