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:
- 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 sensorfrom machine import Pin, I2C from micropython_mma8452q import mma8452q
Once this is done you can define your
machine.I2C
object and define your sensor objecti2c = 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