CircuitPython module for the MMA8451 3 axis accelerometer. See examples/ for a demo of the usage.

  • Author(s): Tony DiCola

Implementation Notes


Software and Dependencies:

class adafruit_mma8451.MMA8451(i2c: busio.I2C, *, address: int = 29)

MMA8451 accelerometer. Create an instance by specifying:

  • i2c (I2C) – The I2C bus the device is connected to.

  • address (int) – The I2C device address. Defaults to 0x1D

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 sensor

import board
import adafruit_mma8451

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
sensor = adafruit_mma8451.MMA8451(i2c)

Now you have access to the acceleration and orientation attributes

acc_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: 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

property orientation: int

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

property range: int

Get and set the range of the sensor. Must be a value of:

  • RANGE_8G: +/- 8g

  • RANGE_4G: +/- 4g (the default)

  • RANGE_2G: +/- 2g