Skip to content

improving_docs #16

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
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