10
10
examples/simpletest.py for a demo of the usage.
11
11
12
12
* Author(s): Tony DiCola
13
+
14
+ Implementation Notes
15
+ --------------------
16
+
17
+ **Hardware:**
18
+
19
+ * Adafruit `Triple-Axis Accelerometer - ±2/4/8g @ 14-bit - MMA8451
20
+ <https://www.adafruit.com/product/2019>`_
21
+
22
+
23
+ **Software and Dependencies:**
24
+
25
+ * Adafruit CircuitPython firmware for the supported boards:
26
+ https://circuitpython.org/downloads
27
+ * Adafruit's Bus Device library:
28
+ https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
29
+
13
30
"""
14
31
try :
15
32
import struct
64
81
65
82
class MMA8451 :
66
83
"""MMA8451 accelerometer. Create an instance by specifying:
67
- - i2c: The I2C bus connected to the sensor.
68
84
69
- Optionally specify:
70
- - address: The I2C address of the sensor if not the default of 0x1D.
85
+ :param ~busio.I2C i2c: The I2C bus the device is connected to.
86
+ :param int address: The I2C device address. Defaults to :const:`0x1D`
87
+
88
+
89
+ **Quickstart: Importing and using the device**
90
+
91
+ Here is an example of using the :class:`MMA8451` class.
92
+ First you will need to import the libraries to use the sensor
93
+
94
+ .. code-block:: python
95
+
96
+ import board
97
+ import adafruit_mma8451
98
+
99
+ Once this is done you can define your `board.I2C` object and define your sensor object
100
+
101
+ .. code-block:: python
102
+
103
+ i2c = board.I2C() # uses board.SCL and board.SDA
104
+ sensor = adafruit_mma8451.MMA8451(i2c)
105
+
106
+ Now you have access to the :attr:`acceleration` and :attr:`orientation` attributes
107
+
108
+ .. code-block:: python
109
+
110
+ acc_x, acc_y, acc_z = sensor.acceleration
111
+ orientation = sensor.orientation
112
+
71
113
"""
72
114
73
115
# Class-level buffer to reduce allocations and fragmentation.
@@ -124,9 +166,11 @@ def _write_u8(self, address, val):
124
166
@property
125
167
def range (self ):
126
168
"""Get and set the range of the sensor. Must be a value of:
169
+
127
170
- RANGE_8G: +/- 8g
128
171
- RANGE_4G: +/- 4g (the default)
129
172
- RANGE_2G: +/- 2g
173
+
130
174
"""
131
175
return self ._read_u8 (_MMA8451_REG_XYZ_DATA_CFG ) & 0x03
132
176
@@ -141,6 +185,7 @@ def range(self, val):
141
185
@property
142
186
def data_rate (self ):
143
187
"""Get and set the data rate of the sensor. Must be a value of:
188
+
144
189
- DATARATE_800HZ: 800Hz (the default)
145
190
- DATARATE_400HZ: 400Hz
146
191
- DATARATE_200HZ: 200Hz
@@ -149,6 +194,7 @@ def data_rate(self):
149
194
- DATARATE_12_5HZ: 12.5Hz
150
195
- DATARATE_6_25HZ: 6.25Hz
151
196
- DATARATE_1_56HZ: 1.56Hz
197
+
152
198
"""
153
199
return (self ._read_u8 (_MMA8451_REG_CTRL_REG1 ) >> 3 ) & _MMA8451_DATARATE_MASK
154
200
@@ -166,7 +212,7 @@ def acceleration(self):
166
212
# pylint: disable=no-else-return
167
213
# This needs to be refactored when it can be tested
168
214
"""Get the acceleration measured by the sensor. Will return a 3-tuple
169
- of X, Y, Z axis acceleration values in m/s^2.
215
+ of X, Y, Z axis acceleration values in :math:` m/s^2` .
170
216
"""
171
217
# Read 6 bytes for 16-bit X, Y, Z values.
172
218
self ._read_into (_MMA8451_REG_OUT_X_MSB , self ._BUFFER , count = 6 )
@@ -201,6 +247,7 @@ def acceleration(self):
201
247
@property
202
248
def orientation (self ):
203
249
"""Get the orientation of the MMA8451. Will return a value of:
250
+
204
251
- PL_PUF: Portrait, up, front
205
252
- PL_PUB: Portrait, up, back
206
253
- PL_PDF: Portrait, down, front
@@ -209,5 +256,6 @@ def orientation(self):
209
256
- PL_LRB: Landscape, right, back
210
257
- PL_LLF: Landscape, left, front
211
258
- PL_LLB: Landscape, left, back
259
+
212
260
"""
213
261
return self ._read_u8 (_MMA8451_REG_PL_STATUS ) & 0x07
0 commit comments