mpu6886

CircuitPython helper library for the MPU6886 6-DoF Accelerometer and Gyroscope

  • Author(s): Taiki Komoda

Implementation Notes

Software and Dependencies:

class mpu6886.ClockSource

Allowed values for clock_source.

  • ClockSource.CLKSEL_INTERNAL_8MHz

  • ClockSource.CLKSEL_INTERNAL_X

  • ClockSource.CLKSEL_INTERNAL_Y

  • ClockSource.CLKSEL_INTERNAL_Z

  • ClockSource.CLKSEL_EXTERNAL_32

  • ClockSource.CLKSEL_EXTERNAL_19

  • ClockSource.CLKSEL_RESERVED

  • ClockSource.CLKSEL_STOP

class mpu6886.GyroRange

Allowed values for gyro_range.

  • GyroRange.RANGE_250_DPS

  • GyroRange.RANGE_500_DPS

  • GyroRange.RANGE_1000_DPS

  • GyroRange.RANGE_2000_DPS

class mpu6886.MPU6886(i2c_bus: I2C, address: int = 104)

Driver for the MPU6886 6-DoF accelerometer and gyroscope.

Parameters:
  • i2c_bus (I2C) – The I2C bus the device is connected to

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

Quickstart: Importing and using the device

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

import board
import mpu6886

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 = mpu6886.MPU6886(i2c)

Now you have access to the acceleration, gyro and temperature attributes

acc_x, acc_y, acc_z = sensor.acceleration
gyro_x, gyro_y, gyro_z = sensor.gyro
temperature = sensor.temperature
property acceleration: Tuple[float, float, float]

Acceleration X, Y, and Z axis data in \(m/s^2\)

property accelerometer_range: int

The measurement range of all accelerometer axes. Must be a Range

property clock_source: int

The clock source for the sensor

property cycle: bool

Enable or disable periodic measurement at a rate set by cycle_rate(). If the sensor was in sleep mode, it will be waken up to cycle

property cycle_rate: int

The rate that measurements are taken while in cycle mode. Must be a Rate

property gyro: Tuple[float, float, float]

Gyroscope X, Y, and Z axis data in \(rad/s\)

property gyro_range: int

The measurement range of all gyroscope axes. Must be a GyroRange

classmethod reset() None

Reinitialize the sensor

sample_rate_divisor = 25

The sample rate divisor. See the datasheet for additional detail

sleep = 107

Shuts down the accelerometers and gyroscopes, saving power. No new data will be recorded until the sensor is taken out of sleep by setting to False

property temperature: float

The current temperature in º Celsius

class mpu6886.Range

Allowed values for accelerometer_range.

  • Range.RANGE_2_G

  • Range.RANGE_4_G

  • Range.RANGE_8_G

  • Range.RANGE_16_G

class mpu6886.Rate

Allowed values for cycle_rate.

  • Rate.CYCLE_1_25_HZ

  • Rate.CYCLE_5_HZ

  • Rate.CYCLE_20_HZ

  • Rate.CYCLE_40_HZ