MicroPython MMA8452Q Library

mma8452q

MicroPython Driver for the NXP MMA8452Q Accelerometer

  • Author(s): Jose D. Montoya

class micropython_mma8452q.mma8452q.MMA8452Q(i2c, address: int = 0x1C)

Driver for the MMA8452Q Sensor connected over I2C.

Parameters:
  • i2c (I2C) – The I2C bus the MMA8452Q is connected to.

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

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

Here is an example of using the MMA8452Q class. First you will need to import the libraries to use the sensor

from machine import Pin, I2C
from micropython_mma8452q import mma8452q

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

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
mma8452q = mma8452q.MMA8452Q(i2c)

Now you have access to the attributes

magx, magy, magz = mma8452q.acceleration
property acceleration: Tuple[float, float, float]

Acceleration measured by the sensor in \(m/s^2\).

property data_rate: str

Sensor data_rate

Mode

Value

mma8451.DATARATE_800HZ

0b000

mma8451.DATARATE_400HZ

0b001

mma8451.DATARATE_200HZ

0b010

mma8451.DATARATE_100HZ

0b011

mma8451.DATARATE_50HZ

0b100

mma8451.DATARATE_12_5HZ

0b101

mma8451.DATARATE_6_25HZ

0b110

mma8451.DATARATE_1_56HZ

0b111

property high_pass_filter: str

Sensor high_pass_filter

Mode

Value

mma8451.HPF_DISABLED

0b0

mma8451.HPF_ENABLED

0b1

property high_pass_filter_cutoff: str

Sensor high_pass_filter_cutoff sets the high-pass filter cutoff frequency for removal of the offset and slower changing acceleration data. In order to filter the acceleration data high_pass_filter must be enabled.

Mode

Value

mma8451.CUTOFF_16HZ

0b00

mma8451.CUTOFF_8HZ

0b01

mma8451.CUTOFF_4HZ

0b10

mma8451.CUTOFF_2HZ

0b11

property operation_mode: str

Sensor operation_mode

Mode

Value

mma8451.STANDBY_MODE

0b0

mma8451.ACTIVE_MODE

0b1

property scale_range: str

Sensor scale_range

Mode

Value

mma8451.RANGE_2G

0b00

mma8451.RANGE_4G

0b01

mma8451.RANGE_8G

0b10