Skip to content

Commit 92a97d5

Browse files
authored
Merge pull request #17 from jposada202020/improving_docs
improving_docs
2 parents 19241e3 + 107a424 commit 92a97d5

File tree

3 files changed

+57
-9
lines changed

3 files changed

+57
-9
lines changed

adafruit_mma8451.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@
1010
examples/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
"""
1431
try:
1532
import struct
@@ -64,10 +81,35 @@
6481

6582
class 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

docs/index.rst

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

26+
Adafruit Triple-Axis Accelerometer - ±2/4/8g @ 14-bit - MMA8451 Learning Guide <https://learn.adafruit.com/adafruit-mma8451-accelerometer-breakout/>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

31+
Adafruit Triple-Axis Accelerometer - ±2/4/8g @ 14-bit - MMA8451 <https://www.adafruit.com/product/2019>
2932

3033
.. toctree::
3134
:caption: Other Links

examples/mma8451_simpletest.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44
# Simple demo of reading the MMA8451 orientation every second.
55

66
import time
7-
87
import board
9-
import busio
10-
118
import adafruit_mma8451
129

1310

14-
# Initialize I2C bus.
15-
i2c = busio.I2C(board.SCL, board.SDA)
11+
# Create sensor object, communicating over the board's default I2C bus
12+
i2c = board.I2C() # uses board.SCL and board.SDA
1613

1714
# Initialize MMA8451 module.
1815
sensor = adafruit_mma8451.MMA8451(i2c)

0 commit comments

Comments
 (0)