12
12
13
13
Based on drivers by K. Townsend and Tony DiCola
14
14
15
+
15
16
Implementation Notes
16
17
--------------------
17
18
18
19
**Hardware:**
19
- https://www.adafruit.com/product/1231
20
+
21
+ * Adafruit `ADXL345 Digital Accelerometer
22
+ <https://www.adafruit.com/product/1231>`_ (Product ID: 1231)
20
23
21
24
**Software and Dependencies:**
22
25
23
26
* Adafruit CircuitPython firmware for the supported boards:
24
- https://github.com/adafruit/circuitpython/releases
27
+ https://circuitpython.org/downloads
25
28
26
29
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
27
30
"""
@@ -140,8 +143,32 @@ class Range: # pylint: disable=too-few-public-methods
140
143
class ADXL345 :
141
144
"""Driver for the ADXL345 3 axis accelerometer
142
145
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
145
172
146
173
"""
147
174
@@ -158,7 +185,7 @@ def __init__(self, i2c, address=_ADXL345_DEFAULT_ADDRESS):
158
185
159
186
@property
160
187
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` """
162
189
x , y , z = unpack ("<hhh" , self ._read_register (_REG_DATAX0 , 6 ))
163
190
x = x * _ADXL345_MG2G_MULTIPLIER * _STANDARD_GRAVITY
164
191
y = y * _ADXL345_MG2G_MULTIPLIER * _STANDARD_GRAVITY
@@ -168,7 +195,8 @@ def acceleration(self):
168
195
@property
169
196
def events (self ):
170
197
"""
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.
172
200
The possible keys are:
173
201
174
202
+------------+----------------------------------------------------------------------------+
@@ -255,11 +283,13 @@ def enable_freefall_detection(self, *, threshold=10, time=25):
255
283
register as dropped. The scale factor is 62.5 mg/LSB.
256
284
257
285
: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\
259
287
and 350 ms (20 to 70) are recommended.
260
288
261
289
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
263
293
264
294
accelerometer.enable_freefall_detection(time=30)
265
295
@@ -294,19 +324,20 @@ def enable_tap_detection(
294
324
:param int threshold: A threshold for the tap detection. The scale factor is 62.5 mg/LSB\
295
325
The higher the value the less sensitive the detection.
296
326
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``.\
299
328
Anything above ``duration`` won't register as a tap. The scale factor is 625 µs/LSB
300
329
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\
302
331
falls below ``threshold`` to start the window looking for a second impulse.\
303
332
The scale factor is 1.25 ms/LSB.
304
333
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\
306
335
second tap. The scale factor is 1.25 ms/LSB
307
336
308
337
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
310
341
311
342
accelerometer.enable_tap_detection(duration=30, threshold=25)
312
343
0 commit comments