Skip to content

Commit 5d9144d

Browse files
authored
Merge pull request #11 from jposada202020/improving_docs
improving_docs
2 parents d2c4801 + 17c00a1 commit 5d9144d

8 files changed

+72
-34
lines changed

README.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ 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_lsm303_accel
6564
66-
i2c = busio.I2C(board.SCL, board.SDA)
65+
i2c = board.I2C() # uses board.SCL and board.SDA
6766
sensor = adafruit_lsm303_accel.LSM303_Accel(i2c)
6867
6968
while True:

adafruit_lsm303_accel.py

+36-22
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2424
**Software and Dependencies:**
2525
26-
* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
26+
* Adafruit CircuitPython firmware for the supported boards:
2727
https://circuitpython.org/downloads
2828
* Adafruit's Bus Device library:
2929
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
@@ -124,7 +124,36 @@ class Range:
124124

125125

126126
class LSM303_Accel: # pylint:disable=too-many-instance-attributes
127-
"""Driver for the LSM303's accelerometer."""
127+
"""Driver for the LSM303's accelerometer.
128+
129+
:param ~busio.I2C i2c: The I2C bus the device is connected to.
130+
131+
132+
**Quickstart: Importing and using the device**
133+
134+
Here is an example of using the :class:`LSM303_Accel` class.
135+
First you will need to import the libraries to use the sensor
136+
137+
.. code-block:: python
138+
139+
import board
140+
import adafruit_lsm303_accel
141+
142+
Once this is done you can define your `board.I2C` object and define your sensor object
143+
144+
.. code-block:: python
145+
146+
i2c = board.I2C() # uses board.SCL and board.SDA
147+
sensor = adafruit_lsm303_accel.LSM303_Accel(i2c)
148+
149+
Now you have access to the :attr:`acceleration` attribute
150+
151+
.. code-block:: python
152+
153+
acc_x, acc_y, acc_z = sensor.acceleration
154+
155+
156+
"""
128157

129158
# Class-level buffer for reading and writing data with the sensor.
130159
# This reduces memory allocations but means the code is not re-entrant or
@@ -141,22 +170,7 @@ class LSM303_Accel: # pylint:disable=too-many-instance-attributes
141170

142171
_act_threshold = UnaryStruct(_REG_ACCEL_ACT_THS_A, "B")
143172
_act_duration = UnaryStruct(_REG_ACCEL_ACT_DUR_A, "B")
144-
"""
145-
.. code-block:: python
146-
147-
import board
148-
i2c = board.I2C()
149-
150-
import adafruit_lsm303_accel
151-
accel = adafruit_lsm303_accel.LSM303_Accel(i2c)
152173

153-
accel._act_threshold = 20
154-
accel._act_duration = 1
155-
accel._int2_activity_enable = True
156-
157-
# toggle pins, defaults to False
158-
accel._int_pin_active_low = True
159-
"""
160174
_data_rate = RWBits(4, _REG_ACCEL_CTRL_REG1_A, 4)
161175
_enable_xyz = RWBits(3, _REG_ACCEL_CTRL_REG1_A, 0)
162176
_raw_accel_data = StructArray(_REG_ACCEL_OUT_X_L_A, "<h", 3)
@@ -211,10 +225,10 @@ def set_tap(
211225
:param int threshold: A threshold for the tap detection. The higher the value the less\
212226
sensitive the detection. This changes based on the accelerometer range. Good values\
213227
are 5-10 for 16G, 10-20 for 8G, 20-40 for 4G, and 40-80 for 2G.
214-
:param int time_limit: TIME_LIMIT register value (default 10).
215-
:param int time_latency: TIME_LATENCY register value (default 20).
216-
:param int time_window: TIME_WINDOW register value (default 255).
217-
:param int click_cfg: CLICK_CFG register value.
228+
:param int time_limit: TIME_LIMIT register value. Defaults to :const:`10`
229+
:param int time_latency: TIME_LATENCY register value. Defaults to :const:`20`
230+
:param int time_window: TIME_WINDOW register value. Defaults to :const:`255`
231+
:param int tap_cfg: CLICK_CFG register value. Defaults to `None`
218232
219233
"""
220234

@@ -250,7 +264,7 @@ def set_tap(
250264
def tapped(self):
251265
"""
252266
True if a tap was detected recently. Whether its a single tap or double tap is
253-
determined by the tap param on ``set_tap``. ``tapped`` may be True over
267+
determined by the tap param on :meth:`set_tap`. :attr:`tapped` may be True over
254268
multiple reads even if only a single tap or single double tap occurred.
255269
"""
256270
tap_src = self._tap_src

docs/examples.rst

+25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ Ensure your device works with these simple tests.
77
:caption: examples/lsm303_simpletest.py
88
:linenos:
99

10+
Fast Acceleration Example
11+
-------------------------
12+
13+
Example to demonstrate fast acceleration data acquisition
14+
1015
.. literalinclude:: ../examples/lsm303_accel_fast.py
1116
:caption: examples/lsm303_fast_accel.py
1217
:linenos:
18+
19+
20+
Inclinometer Example
21+
-------------------------
22+
23+
Demonstrate inclinometer example
24+
25+
.. literalinclude:: ../examples/lsm303_accel_inclinometer.py
26+
:caption: examples/lsm303_accel_inclinometer.py
27+
:linenos:
28+
29+
30+
Tap Detection Example
31+
-------------------------
32+
33+
Tap detection example
34+
35+
.. literalinclude:: ../examples/lsm303_accel_tap_detection.py
36+
:caption: examples/lsm303_accel_tap_detection.py
37+
:linenos:

docs/index.rst

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26+
Triple-axis Accelerometer+Magnetometer (Compass) Board - LSM303 Learning Guide <https://learn.adafruit.com/lsm303-accelerometer-slash-compass-breakout>
27+
28+
FLORA Accelerometer/Compass Sensor - LSM303 Learning Guide <https://learn.adafruit.com/flora-accelerometer/>
29+
2630
.. toctree::
2731
:caption: Related Products
2832

examples/lsm303_accel_fast.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
""" Read data from the accelerometer and print it out, ASAP! """
55

66
import board
7-
import busio
8-
97
import adafruit_lsm303_accel
108

11-
i2c = busio.I2C(board.SCL, board.SDA)
9+
i2c = board.I2C() # uses board.SCL and board.SDA
1210
sensor = adafruit_lsm303_accel.LSM303_Accel(i2c)
11+
1312
while True:
1413
accel_x, accel_y, accel_z = sensor.acceleration
1514
print("{0:10.3f} {1:10.3f} {2:10.3f}".format(accel_x, accel_y, accel_z))

examples/lsm303_accel_inclinometer.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
import time
77
from math import atan2, degrees
88
import board
9-
import busio
109
import adafruit_lsm303_accel
1110

1211

13-
i2c = busio.I2C(board.SCL, board.SDA)
12+
i2c = board.I2C() # uses board.SCL and board.SDA
1413
sensor = adafruit_lsm303_accel.LSM303_Accel(i2c)
1514

1615

examples/lsm303_accel_simpletest.py

+1-2
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_lsm303_accel
109

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

1413
while True:

examples/lsm303_accel_tap_detection.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
# SPDX-License-Identifier: MIT
33

44
import board
5-
import busio
65
import adafruit_lsm303_accel
76

8-
i2c = busio.I2C(board.SCL, board.SDA)
7+
i2c = board.I2C() # uses board.SCL and board.SDA
98
accel = adafruit_lsm303_accel.LSM303_Accel(i2c)
109
accel.range = adafruit_lsm303_accel.Range.RANGE_8G
1110
accel.set_tap(1, 30)

0 commit comments

Comments
 (0)