Skip to content

Commit 5226f2d

Browse files
committed
improving_docs
1 parent 088d4bc commit 5226f2d

File tree

7 files changed

+55
-25
lines changed

7 files changed

+55
-25
lines changed

README.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ To install in a virtual environment in your current project:
5353
5454
Usage Example
5555
=============
56-
::
56+
.. code:: python3
5757
5858
import time
5959
import board
60-
import busio
6160
import adafruit_adxl34x
62-
i2c = busio.I2C(board.SCL, board.SDA)
61+
62+
i2c = board.I2C() # uses board.SCL and board.SDA
6363
accelerometer = adafruit_adxl34x.ADXL345(i2c)
64+
6465
while True:
6566
print("%f %f %f"%accelerometer.acceleration)
6667
time.sleep(1)

adafruit_adxl34x.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@
1212
1313
Based on drivers by K. Townsend and Tony DiCola
1414
15+
1516
Implementation Notes
1617
--------------------
1718
1819
**Hardware:**
19-
https://www.adafruit.com/product/1231
20+
21+
* Adafruit `ADXL345 Digital Accelerometer
22+
<https://www.adafruit.com/product/1231>`_ (Product ID: 1231)
2023
2124
**Software and Dependencies:**
2225
2326
* Adafruit CircuitPython firmware for the supported boards:
24-
https://github.com/adafruit/circuitpython/releases
27+
https://circuitpython.org/downloads
2528
2629
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
2730
"""
@@ -140,8 +143,32 @@ class Range: # pylint: disable=too-few-public-methods
140143
class ADXL345:
141144
"""Driver for the ADXL345 3 axis accelerometer
142145
143-
:param ~busio.I2C i2c_bus: The I2C bus the ADXL345 is connected to.
144-
:param address: The I2C device address for the sensor. Default is ``0x53``.
146+
:param ~busio.I2C i2c: The I2C bus the ADXL345 is connected to.
147+
:param address: The I2C device address for the sensor. Default is :const:`0x53`.
148+
149+
**Quickstart: Importing and using the device**
150+
151+
Here is an example of using the :class:`ADXL345` class.
152+
First you will need to import the libraries to use the sensor
153+
154+
.. code-block:: python
155+
156+
import board
157+
import adafruit_adxl34x
158+
159+
Once this is done you can define your `board.I2C` object and define your sensor object
160+
161+
.. code-block:: python
162+
163+
i2c = board.I2C() # uses board.SCL and board.SDA
164+
accelerometer = adafruit_adxl34x.ADXL343(i2c)
165+
166+
167+
Now you have access to the :attr:`acceleration` attribute
168+
169+
.. code-block:: python
170+
171+
acceleration = accelerometer.acceleration
145172
146173
"""
147174

@@ -158,7 +185,7 @@ def __init__(self, i2c, address=_ADXL345_DEFAULT_ADDRESS):
158185

159186
@property
160187
def acceleration(self):
161-
"""The x, y, z acceleration values returned in a 3-tuple in m / s ^ 2."""
188+
"""The x, y, z acceleration values returned in a 3-tuple in :math:`m / s ^ 2`"""
162189
x, y, z = unpack("<hhh", self._read_register(_REG_DATAX0, 6))
163190
x = x * _ADXL345_MG2G_MULTIPLIER * _STANDARD_GRAVITY
164191
y = y * _ADXL345_MG2G_MULTIPLIER * _STANDARD_GRAVITY
@@ -168,7 +195,8 @@ def acceleration(self):
168195
@property
169196
def events(self):
170197
"""
171-
``events`` will return a dictionary with a key for each event type that has been enabled.
198+
:attr:`events` will return a dictionary with a key for each
199+
event type that has been enabled.
172200
The possible keys are:
173201
174202
+------------+----------------------------------------------------------------------------+
@@ -255,11 +283,13 @@ def enable_freefall_detection(self, *, threshold=10, time=25):
255283
register as dropped. The scale factor is 62.5 mg/LSB.
256284
257285
:param int time: The amount of time that acceleration on all axes must be less than\
258-
``threshhold`` to register as dropped. The scale factor is 5 ms/LSB. Values between 100 ms\
286+
``threshold`` to register as dropped. The scale factor is 5 ms/LSB. Values between 100 ms\
259287
and 350 ms (20 to 70) are recommended.
260288
261289
If you wish to set them yourself rather than using the defaults,
262-
you must use keyword arguments::
290+
you must use keyword arguments:
291+
292+
.. code-block:: python
263293
264294
accelerometer.enable_freefall_detection(time=30)
265295
@@ -294,19 +324,20 @@ def enable_tap_detection(
294324
:param int threshold: A threshold for the tap detection. The scale factor is 62.5 mg/LSB\
295325
The higher the value the less sensitive the detection.
296326
297-
298-
:param int duration: This caps the duration of the impulse above ``threshhold``.\
327+
:param int duration: This caps the duration of the impulse above ``threshold``.\
299328
Anything above ``duration`` won't register as a tap. The scale factor is 625 µs/LSB
300329
301-
:param int latency(double tap only): The length of time after the initial impulse\
330+
:param int latency: (double tap only) The length of time after the initial impulse\
302331
falls below ``threshold`` to start the window looking for a second impulse.\
303332
The scale factor is 1.25 ms/LSB.
304333
305-
:param int window(double tap only): The length of the window in which to look for a\
334+
:param int window: (double tap only) The length of the window in which to look for a\
306335
second tap. The scale factor is 1.25 ms/LSB
307336
308337
If you wish to set them yourself rather than using the defaults,
309-
you must use keyword arguments::
338+
you must use keyword arguments:
339+
340+
.. code-block:: python
310341
311342
accelerometer.enable_tap_detection(duration=30, threshold=25)
312343

docs/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26+
ADXL345 - Triple-Axis Accelerometer (+-2g/4g/8g/16g) w/ I2C/SPI Learning Guide <https://learn.adafruit.com/adxl345-digital-accelerometer>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

29-
.. https://www.adafruit.com/product/1231
31+
ADXL345 - Triple-Axis Accelerometer (+-2g/4g/8g/16g) w/ I2C/SPI <https://www.adafruit.com/product/1231>
3032

3133

3234
.. toctree::

examples/adxl34x_freefall_detection_test.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_adxl34x
87

9-
i2c = busio.I2C(board.SCL, board.SDA)
8+
i2c = board.I2C() # uses board.SCL and board.SDA
109

1110
# For ADXL343
1211
accelerometer = adafruit_adxl34x.ADXL343(i2c)

examples/adxl34x_motion_detection_test.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_adxl34x
87

9-
i2c = busio.I2C(board.SCL, board.SDA)
8+
i2c = board.I2C() # uses board.SCL and board.SDA
109

1110
# For ADXL343
1211
accelerometer = adafruit_adxl34x.ADXL343(i2c)

examples/adxl34x_simpletest.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_adxl34x
87

9-
i2c = busio.I2C(board.SCL, board.SDA)
8+
i2c = board.I2C() # uses board.SCL and board.SDA
109

1110
# For ADXL343
1211
accelerometer = adafruit_adxl34x.ADXL343(i2c)

examples/adxl34x_tap_detection_test.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_adxl34x
87

9-
i2c = busio.I2C(board.SCL, board.SDA)
8+
i2c = board.I2C() # uses board.SCL and board.SDA
109

1110
# For ADXL343
1211
accelerometer = adafruit_adxl34x.ADXL343(i2c)

0 commit comments

Comments
 (0)