1010examples/simpletest.py for a demo of the usage.
1111
1212* 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+
1330"""
1431try :
1532 import struct
6481
6582class MMA8451 :
6683 """MMA8451 accelerometer. Create an instance by specifying:
67- - i2c: The I2C bus connected to the sensor.
6884
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+
71113 """
72114
73115 # Class-level buffer to reduce allocations and fragmentation.
@@ -124,9 +166,11 @@ def _write_u8(self, address, val):
124166 @property
125167 def range (self ):
126168 """Get and set the range of the sensor. Must be a value of:
169+
127170 - RANGE_8G: +/- 8g
128171 - RANGE_4G: +/- 4g (the default)
129172 - RANGE_2G: +/- 2g
173+
130174 """
131175 return self ._read_u8 (_MMA8451_REG_XYZ_DATA_CFG ) & 0x03
132176
@@ -141,6 +185,7 @@ def range(self, val):
141185 @property
142186 def data_rate (self ):
143187 """Get and set the data rate of the sensor. Must be a value of:
188+
144189 - DATARATE_800HZ: 800Hz (the default)
145190 - DATARATE_400HZ: 400Hz
146191 - DATARATE_200HZ: 200Hz
@@ -149,6 +194,7 @@ def data_rate(self):
149194 - DATARATE_12_5HZ: 12.5Hz
150195 - DATARATE_6_25HZ: 6.25Hz
151196 - DATARATE_1_56HZ: 1.56Hz
197+
152198 """
153199 return (self ._read_u8 (_MMA8451_REG_CTRL_REG1 ) >> 3 ) & _MMA8451_DATARATE_MASK
154200
@@ -166,7 +212,7 @@ def acceleration(self):
166212 # pylint: disable=no-else-return
167213 # This needs to be refactored when it can be tested
168214 """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` .
170216 """
171217 # Read 6 bytes for 16-bit X, Y, Z values.
172218 self ._read_into (_MMA8451_REG_OUT_X_MSB , self ._BUFFER , count = 6 )
@@ -201,6 +247,7 @@ def acceleration(self):
201247 @property
202248 def orientation (self ):
203249 """Get the orientation of the MMA8451. Will return a value of:
250+
204251 - PL_PUF: Portrait, up, front
205252 - PL_PUB: Portrait, up, back
206253 - PL_PDF: Portrait, down, front
@@ -209,5 +256,6 @@ def orientation(self):
209256 - PL_LRB: Landscape, right, back
210257 - PL_LLF: Landscape, left, front
211258 - PL_LLB: Landscape, left, back
259+
212260 """
213261 return self ._read_u8 (_MMA8451_REG_PL_STATUS ) & 0x07
0 commit comments