27
27
28
28
**Software and Dependencies:**
29
29
30
- * Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
31
- https://github.com/adafruit/circuitpython/releases
30
+ * Adafruit CircuitPython firmware for the supported boards:
31
+ https://circuitpython.org/downloads
32
32
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
33
33
"""
34
34
85
85
86
86
87
87
class LIS3DH :
88
- """Driver base for the LIS3DH accelerometer."""
88
+ """Driver base for the LIS3DH accelerometer.
89
+
90
+ :param digitalio.DigitalInOut int1. pin on the sensor that would
91
+ act as an in interrupt
92
+ :param digitalio.DigitalInOut int2. pin on the sensor that would
93
+ act as an in interrupt
94
+
95
+ """
89
96
90
97
def __init__ (self , int1 = None , int2 = None ):
91
98
# Check device ID.
@@ -115,10 +122,22 @@ def __init__(self, int1=None, int2=None):
115
122
116
123
@property
117
124
def data_rate (self ):
118
- """The data rate of the accelerometer. Can be DATA_RATE_400_HZ, DATA_RATE_200_HZ,
119
- DATA_RATE_100_HZ, DATA_RATE_50_HZ, DATA_RATE_25_HZ, DATA_RATE_10_HZ,
120
- DATA_RATE_1_HZ, DATA_RATE_POWERDOWN, DATA_RATE_LOWPOWER_1K6HZ, or
121
- DATA_RATE_LOWPOWER_5KHZ."""
125
+ """The data rate of the accelerometer.
126
+
127
+ Could have the following values:
128
+
129
+ * DATA_RATE_400_HZ
130
+ * DATA_RATE_200_HZ
131
+ * DATA_RATE_100_HZ
132
+ * DATA_RATE_50_HZ
133
+ * DATA_RATE_25_HZ
134
+ * DATA_RATE_10_HZ
135
+ * DATA_RATE_1_HZ
136
+ * DATA_RATE_POWERDOWN
137
+ * DATA_RATE_LOWPOWER_1K6HZ
138
+ * DATA_RATE_LOWPOWER_5KHZ.
139
+
140
+ """
122
141
ctl1 = self ._read_register_byte (_REG_CTRL1 )
123
142
return (ctl1 >> 4 ) & 0x0F
124
143
@@ -131,8 +150,16 @@ def data_rate(self, rate):
131
150
132
151
@property
133
152
def range (self ):
134
- """The range of the accelerometer. Can be RANGE_2_G, RANGE_4_G, RANGE_8_G, or
135
- RANGE_16_G."""
153
+ """The range of the accelerometer.
154
+
155
+ Could have the following values:
156
+
157
+ * RANGE_2_G
158
+ * RANGE_4_G
159
+ * RANGE_8_G
160
+ * RANGE_16_G.
161
+
162
+ """
136
163
ctl4 = self ._read_register_byte (_REG_CTRL4 )
137
164
return (ctl4 >> 4 ) & 0x03
138
165
@@ -145,7 +172,8 @@ def range(self, range_value):
145
172
146
173
@property
147
174
def acceleration (self ):
148
- """The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2."""
175
+ """The x, y, z acceleration values returned
176
+ in a 3-tuple and are in :math:`m / s ^ 2`"""
149
177
divider = 1
150
178
accel_range = self .range
151
179
if accel_range == RANGE_16_G :
@@ -167,21 +195,23 @@ def acceleration(self):
167
195
return AccelerationTuple (x , y , z )
168
196
169
197
def shake (self , shake_threshold = 30 , avg_count = 10 , total_delay = 0.1 ):
170
- """
171
- Detect when the accelerometer is shaken. Optional parameters:
198
+ """Detect when the accelerometer is shaken. Optional parameters:
199
+
200
+ :param int shake_threshold: Increase or decrease to change shake sensitivity.
201
+ This requires a minimum value of 10.
202
+ 10 is the total acceleration if the board is not
203
+ moving, therefore anything less than
204
+ 10 will erroneously report a constant shake detected.
205
+ Defaults to :const:`30`
172
206
173
- :param shake_threshold: Increase or decrease to change shake sensitivity. This
174
- requires a minimum value of 10. 10 is the total
175
- acceleration if the board is not moving, therefore
176
- anything less than 10 will erroneously report a constant
177
- shake detected. (Default 30)
207
+ :param int avg_count: The number of readings taken and used for the average
208
+ acceleration. Default to :const:`10`
178
209
179
- :param avg_count : The number of readings taken and used for the average
180
- acceleration. (Default 10)
210
+ :param float total_delay : The total time in seconds it takes to obtain avg_count
211
+ readings from acceleration. Defaults to :const:`0.1`
181
212
182
- :param total_delay: The total time in seconds it takes to obtain avg_count
183
- readings from acceleration. (Default 0.1)
184
213
"""
214
+
185
215
shake_accel = (0 , 0 , 0 )
186
216
for _ in range (avg_count ):
187
217
# shake_accel creates a list of tuples from acceleration data.
@@ -198,7 +228,7 @@ def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1):
198
228
return total_accel > shake_threshold
199
229
200
230
def read_adc_raw (self , adc ):
201
- """Retrieve the raw analog to digital converter value. ADC must be a
231
+ """Retrieve the raw analog to digital converter value. ADC must be a
202
232
value 1, 2, or 3.
203
233
"""
204
234
if adc < 1 or adc > 3 :
@@ -230,18 +260,19 @@ def read_adc_mV(self, adc): # pylint: disable=invalid-name
230
260
def tapped (self ):
231
261
"""
232
262
True if a tap was detected recently. Whether its a single tap or double tap is
233
- determined by the tap param on `` set_tap``. `` tapped` ` may be True over
263
+ determined by the tap param on :attr:` set_tap`. :attr:` tapped` may be True over
234
264
multiple reads even if only a single tap or single double tap occurred if the
235
265
interrupt (int) pin is not specified.
236
266
237
- The following example uses ``i2c` ` and specifies the interrupt pin:
267
+ The following example uses `board.I2C ` and specifies the interrupt pin:
238
268
239
269
.. code-block:: python
240
270
241
271
import adafruit_lis3dh
242
272
import digitalio
273
+ import board
243
274
244
- i2c = busio .I2C(board.SCL, board.SDA)
275
+ i2c = board .I2C() # uses board.SCL and board.SDA
245
276
int1 = digitalio.DigitalInOut(board.D11) # pin connected to interrupt
246
277
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
247
278
lis3dh.range = adafruit_lis3dh.RANGE_8_G
@@ -275,10 +306,11 @@ def set_tap(
275
306
the accelerometer range. Good values are 5-10 for 16G,
276
307
10-20 for 8G, 20-40 for 4G, and 40-80 for 2G.
277
308
278
- :param int time_limit: TIME_LIMIT register value (default 10).
279
- :param int time_latency: TIME_LATENCY register value (default 20).
280
- :param int time_window: TIME_WINDOW register value (default 255).
309
+ :param int time_limit: TIME_LIMIT register value. Defaults to :const:`10`
310
+ :param int time_latency: TIME_LATENCY register value. Defaults to :const:`20`
311
+ :param int time_window: TIME_WINDOW register value. Defaults to :const:` 255`
281
312
:param int click_cfg: CLICK_CFG register value.
313
+
282
314
"""
283
315
if (tap < 0 or tap > 2 ) and click_cfg is None :
284
316
raise ValueError (
@@ -324,7 +356,37 @@ def _write_register_byte(self, register, value):
324
356
325
357
326
358
class LIS3DH_I2C (LIS3DH ):
327
- """Driver for the LIS3DH accelerometer connected over I2C."""
359
+ """Driver for the LIS3DH accelerometer connected over I2C.
360
+
361
+ :param ~busio.I2C i2c: The I2C bus the LIS3DH is connected to.
362
+ :param address: The I2C device address. Defaults to :const:`0x18`
363
+
364
+
365
+ **Quickstart: Importing and using the device**
366
+
367
+ Here is an example of using the :class:`LIS3DH_I2C` class.
368
+ First you will need to import the libraries to use the sensor
369
+
370
+ .. code-block:: python
371
+
372
+ import board
373
+ import adafruit_lis3dh
374
+
375
+ Once this is done you can define your `board.I2C` object and define your sensor object
376
+
377
+ .. code-block:: python
378
+
379
+ i2c = board.I2C() # uses board.SCL and board.SDA
380
+ lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c)
381
+
382
+ Now you have access to the :attr:`acceleration` attribute
383
+
384
+ .. code-block:: python
385
+
386
+ acc_x, acc_y, acc_z = lis3dh.acceleration
387
+
388
+
389
+ """
328
390
329
391
def __init__ (self , i2c , * , address = 0x18 , int1 = None , int2 = None ):
330
392
import adafruit_bus_device .i2c_device as i2c_device # pylint: disable=import-outside-toplevel
@@ -348,7 +410,36 @@ def _write_register_byte(self, register, value):
348
410
349
411
350
412
class LIS3DH_SPI (LIS3DH ):
351
- """Driver for the LIS3DH accelerometer connected over SPI."""
413
+ """Driver for the LIS3DH accelerometer connected over SPI.
414
+
415
+ :param ~busio.I2C i2c: The I2C bus the LIS3DH is connected to.
416
+ :param address: The I2C device address. Defaults to :const:`0x18`
417
+
418
+
419
+ **Quickstart: Importing and using the device**
420
+
421
+ Here is an example of using the :class:`LIS3DH_SPI` class.
422
+ First you will need to import the libraries to use the sensor
423
+
424
+ .. code-block:: python
425
+
426
+ import board
427
+ import adafruit_lis3dh
428
+
429
+ Once this is done you can define your `board.SPI` object and define your sensor object
430
+
431
+ .. code-block:: python
432
+
433
+ i2c = board.SPI()
434
+ lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi)
435
+
436
+ Now you have access to the :attr:`acceleration` attribute
437
+
438
+ .. code-block:: python
439
+
440
+ acc_x, acc_y, acc_z = lis3dh.acceleration
441
+
442
+ """
352
443
353
444
def __init__ (self , spi , cs , * , baudrate = 100000 , int1 = None , int2 = None ):
354
445
import adafruit_bus_device .spi_device as spi_device # pylint: disable=import-outside-toplevel
0 commit comments