Skip to content

Commit 5c3512d

Browse files
authored
Merge pull request #13 from jposada202020/improving_docs
improving_docs - No functionality added
2 parents e45439c + a5a8dfb commit 5c3512d

File tree

8 files changed

+58
-19
lines changed

8 files changed

+58
-19
lines changed

README.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,17 @@ To install in a virtual environment in your current project:
5656
Usage Example
5757
=============
5858

59-
.. code-block:: python
59+
.. code-block:: python3
6060
6161
import time
6262
import board
63-
import busio
6463
import adafruit_lis2mdl
6564
66-
i2c = busio.I2C(board.SCL, board.SDA)
65+
i2c = board.I2C() # uses board.SCL and board.SDA
6766
sensor = adafruit_lis2mdl.LIS2MDL(i2c)
6867
6968
while True:
7069
mag_x, mag_y, mag_z = sensor.magnetic
71-
7270
print('Magnetometer (gauss): ({0:10.3f}, {1:10.3f}, {2:10.3f})'.format(mag_x, mag_y, mag_z))
7371
print('')
7472
time.sleep(1.0)

adafruit_lis2mdl.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323
2424
**Software and Dependencies:**
2525
26-
* Adafruit CircuitPython firmware:
26+
* Adafruit CircuitPython firmware for the supported boards:
2727
https://circuitpython.org/downloads
28-
* Adafruit's Bus Device library:
29-
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
30-
* Adafruit's Register library:
31-
https://github.com/adafruit/Adafruit_CircuitPython_Register
28+
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
29+
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
3230
"""
3331

3432
from time import sleep
@@ -91,7 +89,31 @@ class LIS2MDL: # pylint: disable=too-many-instance-attributes
9189
"""
9290
Driver for the LIS2MDL 3-axis magnetometer.
9391
94-
:param busio.I2C i2c_bus: The I2C bus the LIS2MDL is connected to.
92+
:param ~busio.I2C i2c: The I2C bus the device is connected to
93+
94+
**Quickstart: Importing and using the device**
95+
96+
Here is an example of using the :class:`LIS2MDL` class.
97+
First you will need to import the libraries to use the sensor
98+
99+
.. code-block:: python
100+
101+
import board
102+
import adafruit_lis2mdl
103+
104+
Once this is done you can define your `board.I2C` object and define your sensor object
105+
106+
.. code-block:: python
107+
108+
i2c = board.I2C() # uses board.SCL and board.SDA
109+
sensor = adafruit_lis2mdl.LIS2MDL(i2c)
110+
111+
Now you have access to the :attr:`magnetic` attribute
112+
113+
.. code-block:: python
114+
115+
mag_x, mag_y, mag_z = sensor.magnetic
116+
95117
96118
"""
97119

docs/examples.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,29 @@ Ensure your device works with these simple tests.
77
:caption: examples/lis2mdl_simpletest.py
88
:linenos:
99

10+
Interrupt Example
11+
-----------------
12+
13+
Example showing how to use the interrupts
14+
1015
.. literalinclude:: ../examples/lis2mdl_interrupt.py
1116
:caption: examples/lis2mdl_interrupt.py
1217
:linenos:
1318

14-
examples/lis2mdl_interrupt.py
19+
Compass Example
20+
---------------
21+
22+
Example showing how to use the compass capabilities of the device
23+
24+
.. literalinclude:: ../examples/lis2mdl_compass.py
25+
:caption: examples/lis2mdl_compass.py
26+
:linenos:
27+
28+
Calibrate Test
29+
--------------
30+
31+
Calibrate the magnetometer and print out the hard-iron calibrations
32+
33+
.. literalinclude:: ../examples/lis2mdl_calibrate.py
34+
:caption: examples/lis2mdl_calibrate.py
35+
:linenos:

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26+
Triple-axis Accelerometer+Magnetometer (Compass) Board - LSM303 <https://learn.adafruit.com/lsm303-accelerometer-slash-compass-breakout/downloads>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

examples/lis2mdl_calibrate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
import time
77
import board
8-
import busio
98
import adafruit_lis2mdl
109

11-
i2c = busio.I2C(board.SCL, board.SDA)
10+
i2c = board.I2C() # uses board.SCL and board.SDA
1211
magnetometer = adafruit_lis2mdl.LIS2MDL(i2c)
1312

1413
# calibration for magnetometer X (min, max), Y and Z

examples/lis2mdl_compass.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import time
77
import math
88
import board
9-
import busio
109
import adafruit_lis2mdl
1110

12-
i2c = busio.I2C(board.SCL, board.SDA)
11+
i2c = board.I2C() # uses board.SCL and board.SDA
1312
sensor = adafruit_lis2mdl.LIS2MDL(i2c)
1413

1514
# You will need the calibration values from your magnetometer calibration

examples/lis2mdl_interrupt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
import time
55
import board
6-
import busio
76
import adafruit_lis2mdl
87

9-
i2c = busio.I2C(board.SCL, board.SDA)
8+
i2c = board.I2C() # uses board.SCL and board.SDA
109
lis = adafruit_lis2mdl.LIS2MDL(i2c)
1110
lis.interrupt_threshold = 80
1211
lis.interrupt_enabled = True

examples/lis2mdl_simpletest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
import time
77
import board
8-
import busio
98
import adafruit_lis2mdl
109

11-
i2c = busio.I2C(board.SCL, board.SDA)
10+
i2c = board.I2C() # uses board.SCL and board.SDA
1211
sensor = adafruit_lis2mdl.LIS2MDL(i2c)
1312

1413
while True:

0 commit comments

Comments
 (0)