From a6581a96ef01c40336fbd2bc57e02e59b987b91b Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 27 Apr 2021 11:18:43 -0400 Subject: [PATCH] improving_docs --- README.rst | 5 ++--- adafruit_lsm303dlh_mag.py | 26 +++++++++++++++++++++++++- docs/examples.rst | 14 ++++++++++++++ docs/index.rst | 5 +++++ examples/lsm303dlh_mag_compass.py | 3 +-- examples/lsm303dlh_mag_fast.py | 3 +-- examples/lsm303dlh_mag_simpletest.py | 3 +-- 7 files changed, 49 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index c4f72a2..f6c4c0e 100644 --- a/README.rst +++ b/README.rst @@ -55,14 +55,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_lsm303dlh_mag - i2c = busio.I2C(board.SCL, board.SDA) + i2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c) while True: diff --git a/adafruit_lsm303dlh_mag.py b/adafruit_lsm303dlh_mag.py index 16d0aff..f0af616 100644 --- a/adafruit_lsm303dlh_mag.py +++ b/adafruit_lsm303dlh_mag.py @@ -89,7 +89,31 @@ class LSM303DLH_Mag: """Driver for the Driver for the LSM303DLH's 'magnetometer. - :param busio.I2C i2c_bus: The I2C bus the LSM303DLH is connected to. + :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:`LSM303DLH_Mag` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + import adafruit_lsm303dlh_mag + + 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_lsm303dlh_mag.LSM303DLH_Mag(i2c) + + Now you have access to the :attr:`magnetic` attribute + + .. code-block:: python + + mag_x, mag_y, mag_z = sensor.magnetic """ diff --git a/docs/examples.rst b/docs/examples.rst index 648a157..7345319 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -7,6 +7,20 @@ Ensure your device works with these simple tests. :caption: examples/lsm303dlh_mag_simpletest.py :linenos: +Fast Data Reading Example +------------------------- + +Fast readings example + .. literalinclude:: ../examples/lsm303dlh_mag_fast.py :caption: examples/lsm303dlh_mag_fast.py :linenos: + +Compass Example +--------------- + +Magnetic compass example + +.. literalinclude:: ../examples/lsm303dlh_mag_compass.py + :caption: examples/lsm303dlh_mag_compass.py + :linenos: diff --git a/docs/index.rst b/docs/index.rst index a8d0ec9..3cfe518 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,6 +23,11 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit LIS3DH Triple-Axis Accelerometer Breakout Learning Guide + + Circuit Playground Express Learning Guide + + .. toctree:: :caption: Related Products diff --git a/examples/lsm303dlh_mag_compass.py b/examples/lsm303dlh_mag_compass.py index f291b2c..bcf5d1b 100644 --- a/examples/lsm303dlh_mag_compass.py +++ b/examples/lsm303dlh_mag_compass.py @@ -5,10 +5,9 @@ import time from math import atan2, degrees import board -import busio import adafruit_lsm303dlh_mag -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c) diff --git a/examples/lsm303dlh_mag_fast.py b/examples/lsm303dlh_mag_fast.py index 201bc56..56d4074 100644 --- a/examples/lsm303dlh_mag_fast.py +++ b/examples/lsm303dlh_mag_fast.py @@ -4,10 +4,9 @@ """ Read data from the magnetometer and print it out, ASAP! """ import board -import busio import adafruit_lsm303dlh_mag -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c) while True: diff --git a/examples/lsm303dlh_mag_simpletest.py b/examples/lsm303dlh_mag_simpletest.py index dc12cd5..1fc5675 100644 --- a/examples/lsm303dlh_mag_simpletest.py +++ b/examples/lsm303dlh_mag_simpletest.py @@ -5,10 +5,9 @@ import time import board -import busio import adafruit_lsm303dlh_mag -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c) while True: