adafruit_mma8451
¶
CircuitPython module for the MMA8451 3 axis accelerometer. See examples/simpletest.py for a demo of the usage.
- Author(s): Tony DiCola
Implementation Notes¶
Hardware:
Software and Dependencies:
- Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
-
class
adafruit_mma8451.
MMA8451
(i2c, *, address=29)¶ MMA8451 accelerometer. Create an instance by specifying:
Parameters: Quickstart: Importing and using the device
Here is an example of using the
MMA8451
class. First you will need to import the libraries to use the sensorimport board import adafruit_mma8451
Once this is done you can define your
board.I2C
object and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_mma8451.MMA8451(i2c)
Now you have access to the
acceleration
andorientation
attributesacc_x, acc_y, acc_z = sensor.acceleration orientation = sensor.orientation
-
acceleration
¶ Get the acceleration measured by the sensor. Will return a 3-tuple of X, Y, Z axis acceleration values in \(m/s^2\).
-
data_rate
¶ Get and set the data rate of the sensor. Must be a value of:
- DATARATE_800HZ: 800Hz (the default)
- DATARATE_400HZ: 400Hz
- DATARATE_200HZ: 200Hz
- DATARATE_100HZ: 100Hz
- DATARATE_50HZ: 50Hz
- DATARATE_12_5HZ: 12.5Hz
- DATARATE_6_25HZ: 6.25Hz
- DATARATE_1_56HZ: 1.56Hz
-
orientation
¶ Get the orientation of the MMA8451. Will return a value of:
- PL_PUF: Portrait, up, front
- PL_PUB: Portrait, up, back
- PL_PDF: Portrait, down, front
- PL_PDB: Portrait, down, back
- PL_LRF: Landscape, right, front
- PL_LRB: Landscape, right, back
- PL_LLF: Landscape, left, front
- PL_LLB: Landscape, left, back
-
range
¶ Get and set the range of the sensor. Must be a value of:
- RANGE_8G: +/- 8g
- RANGE_4G: +/- 4g (the default)
- RANGE_2G: +/- 2g
-