Skip to content

improving_docs - No functionality added #13

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 2 commits into from
Apr 27, 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
6 changes: 2 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,17 @@ 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_lis2mdl

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

while True:
mag_x, mag_y, mag_z = sensor.magnetic

print('Magnetometer (gauss): ({0:10.3f}, {1:10.3f}, {2:10.3f})'.format(mag_x, mag_y, mag_z))
print('')
time.sleep(1.0)
Expand Down
34 changes: 28 additions & 6 deletions adafruit_lis2mdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@

**Software and Dependencies:**

* Adafruit CircuitPython firmware:
* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads
* Adafruit's Bus Device library:
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
* Adafruit's Register library:
https://github.com/adafruit/Adafruit_CircuitPython_Register
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
"""

from time import sleep
Expand Down Expand Up @@ -91,7 +89,31 @@ class LIS2MDL: # pylint: disable=too-many-instance-attributes
"""
Driver for the LIS2MDL 3-axis magnetometer.

:param busio.I2C i2c_bus: The I2C bus the LIS2MDL 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:`LIS2MDL` class.
First you will need to import the libraries to use the sensor

.. code-block:: python

import board
import adafruit_lis2mdl

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_lis2mdl.LIS2MDL(i2c)

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

.. code-block:: python

mag_x, mag_y, mag_z = sensor.magnetic


"""

Expand Down
23 changes: 22 additions & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,29 @@ Ensure your device works with these simple tests.
:caption: examples/lis2mdl_simpletest.py
:linenos:

Interrupt Example
-----------------

Example showing how to use the interrupts

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

examples/lis2mdl_interrupt.py
Compass Example
---------------

Example showing how to use the compass capabilities of the device

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

Calibrate Test
--------------

Calibrate the magnetometer and print out the hard-iron calibrations

.. literalinclude:: ../examples/lis2mdl_calibrate.py
:caption: examples/lis2mdl_calibrate.py
:linenos:
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Table of Contents
.. toctree::
:caption: Tutorials

Triple-axis Accelerometer+Magnetometer (Compass) Board - LSM303 <https://learn.adafruit.com/lsm303-accelerometer-slash-compass-breakout/downloads>

.. toctree::
:caption: Related Products

Expand Down
3 changes: 1 addition & 2 deletions examples/lis2mdl_calibrate.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_lis2mdl

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
magnetometer = adafruit_lis2mdl.LIS2MDL(i2c)

# calibration for magnetometer X (min, max), Y and Z
Expand Down
3 changes: 1 addition & 2 deletions examples/lis2mdl_compass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import time
import math
import board
import busio
import adafruit_lis2mdl

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

# You will need the calibration values from your magnetometer calibration
Expand Down
3 changes: 1 addition & 2 deletions examples/lis2mdl_interrupt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

import time
import board
import busio
import adafruit_lis2mdl

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
lis = adafruit_lis2mdl.LIS2MDL(i2c)
lis.interrupt_threshold = 80
lis.interrupt_enabled = True
Expand Down
3 changes: 1 addition & 2 deletions examples/lis2mdl_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_lis2mdl

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

while True:
Expand Down