Skip to content

Commit

Permalink
Merge pull request #16 from jposada202020/master
Browse files Browse the repository at this point in the history
improving_docs
  • Loading branch information
jposada202020 committed Apr 26, 2021
2 parents d774f38 + 02579e4 commit f441875
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 16 deletions.
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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_lis3mdl
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = adafruit_lis3mdl.LIS3MDL(i2c)
while True:
Expand Down
32 changes: 29 additions & 3 deletions adafruit_lis3mdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
https://circuitpython.org/downloads
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
Expand Down Expand Up @@ -188,8 +188,34 @@ class OperationMode(CV):

class LIS3MDL:
"""Driver for the LIS3MDL 3-axis magnetometer.
:param ~busio.I2C i2c_bus: The I2C bus the LIS3MDL is connected to.
:param address: The I2C slave address of the sensor
:param address: The I2C device address. Defaults to :const:`0x1C`
**Quickstart: Importing and using the device**
Here is an example of using the :class:`LIS3MDL` class.
First you will need to import the libraries to use the sensor
.. code-block:: python
import board
import adafruit_lis3mdl
Once this is done you can define your `board.I2C` object and define your sensor object
.. code-block:: python
i2c = board.I2C()
sensor = adafruit_lis3mdl.LIS3MDL(i2c)
Now you have access to the :attr:`magnetic` attribute
.. code-block:: python
mag_x, mag_y, mag_z = sensor.magnetic
"""

_chip_id = ROUnaryStruct(_LIS3MDL_WHOAMI, "<b")
Expand Down Expand Up @@ -279,7 +305,7 @@ def data_rate(self, value):

@property
def performance_mode(self):
"""Sets the 'performance mode' of the sensor. Must be a `PerformanceMode`.
"""Sets the 'performance mode' of the sensor. Must be a ``PerformanceMode``.
Note that `performance_mode` affects the available data rate and will be
automatically changed by setting ``data_rate`` to certain values."""

Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.. automodule:: adafruit_lis3mdl
:members:
:exclude-members: CV, Range, PerformanceMode
30 changes: 30 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ensure your device works with this simple test.
:caption: examples/lis3mdl_simpletest.py
:linenos:


Compass Example
---------------

Expand All @@ -15,3 +16,32 @@ Use the magnetometer to calculate compass headings.
.. literalinclude:: ../examples/lis3mdl_compass.py
:caption: examples/lis3mdl_compass.py
:linenos:


Data Rate Example
-----------------

Test each data rate

.. literalinclude:: ../examples/lis3mdl_data_rate_test.py
:caption: examples/lis3mdl_data_rate_test.py
:linenos:


LSM6DS Test
---------------

Test the LSM6DS device

.. literalinclude:: ../examples/lis3mdl_lsm6ds_test.py
:caption: examples/lis3mdl_lsm6ds_test.py
:linenos:

Range Test
---------------

Test each range

.. literalinclude:: ../examples/lis3mdl_range_test.py
:caption: examples/lis3mdl_range_test.py
:linenos:
3 changes: 1 addition & 2 deletions examples/lis3mdl_compass.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import time
from math import atan2, degrees
import board
import busio
import adafruit_lis3mdl

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = adafruit_lis3mdl.LIS3MDL(i2c)


Expand Down
3 changes: 1 addition & 2 deletions examples/lis3mdl_data_rate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
# pylint: disable=no-member
import time
import board
import busio
from adafruit_lis3mdl import LIS3MDL, Rate, PerformanceMode

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = LIS3MDL(i2c)

current_rate = Rate.RATE_155_HZ
Expand Down
5 changes: 3 additions & 2 deletions examples/lis3mdl_lsm6ds_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

from adafruit_lis3mdl import LIS3MDL

accel_gyro = LSM6DS(board.I2C())
mag = LIS3MDL(board.I2C())
i2c = board.I2C() # uses board.SCL and board.SDA
accel_gyro = LSM6DS(i2c)
mag = LIS3MDL(i2c)

while True:
acceleration = accel_gyro.acceleration
Expand Down
3 changes: 1 addition & 2 deletions examples/lis3mdl_range_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
# pylint: disable=no-member
import time
import board
import busio
from adafruit_lis3mdl import LIS3MDL, Range

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = LIS3MDL(i2c)

while True:
Expand Down
3 changes: 1 addition & 2 deletions examples/lis3mdl_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

import time
import board
import busio
import adafruit_lis3mdl

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = adafruit_lis3mdl.LIS3MDL(i2c)

while True:
Expand Down

0 comments on commit f441875

Please sign in to comment.