API Reference
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: I2C, *, address: int = 29)
MMA8451 accelerometer. Create an instance by specifying:
- Parameters:
Quickstart: Importing and using the device
Here is an example of using the
MMA8451class. 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.I2Cobject and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_mma8451.MMA8451(i2c)
Now you have access to the
accelerationandorientationattributesacc_x, acc_y, acc_z = sensor.acceleration orientation = sensor.orientation
- property acceleration: Tuple[float, float, float]
Get the acceleration measured by the sensor. Will return a 3-tuple of X, Y, Z axis acceleration values in \(m/s^2\).
- property data_rate: int
Get and set the data rate of the sensor. Must be a value of:
DATARATE_800HZ: 800Hz (the default)DATARATE_400HZ: 400HzDATARATE_200HZ: 200HzDATARATE_100HZ: 100HzDATARATE_50HZ: 50HzDATARATE_12_5HZ: 12.5HzDATARATE_6_25HZ: 6.25HzDATARATE_1_56HZ: 1.56Hz
- property orientation: int
Get the orientation of the MMA8451. Will return a value of:
PL_PUF: Portrait, up, frontPL_PUB: Portrait, up, backPL_PDF: Portrait, down, frontPL_PDB: Portrait, down, backPL_LRF: Landscape, right, frontPL_LRB: Landscape, right, backPL_LLF: Landscape, left, frontPL_LLB: Landscape, left, back