Table of Contents

Class Mpu6500

Namespace
Iot.Device.Imu
Assembly
Iot.Device.Mpu9250.dll

MPU6500 - gyroscope, accelerometer and temperature sensor

[Interface("MPU6500 - gyroscope, accelerometer and temperature sensor")]
public class Mpu6500
Inheritance
Mpu6500
Derived

Constructors

Mpu6500(I2cDevice)

Initialize the MPU6500

public Mpu6500(I2cDevice i2cDevice)

Parameters

i2cDevice I2cDevice

The I2C device

Fields

DefaultI2cAddress

Default address for MPU9250

public const byte DefaultI2cAddress = 104

Field Value

byte

SecondI2cAddress

Second address for MPU9250

public const byte SecondI2cAddress = 105

Field Value

byte

Properties

AccelerationScale

Get the real accelerometer bandwidth. This allows to calculate the real degree per second

[Property]
public float AccelerationScale { get; }

Property Value

float

AccelerometerBandwidth

Get or set the accelerometer bandwidth

[Property]
public AccelerometerBandwidth AccelerometerBandwidth { get; set; }

Property Value

AccelerometerBandwidth

AccelerometerBias

Accelerometer bias data

[Property]
public Vector3 AccelerometerBias { get; }

Property Value

Vector3

AccelerometerLowPowerFrequency

Set or get the accelerometer low power mode

[Property]
public AccelerometerLowPowerFrequency AccelerometerLowPowerFrequency { get; set; }

Property Value

AccelerometerLowPowerFrequency

AccelerometerRange

Get or set the accelerometer range

[Property]
public AccelerometerRange AccelerometerRange { get; set; }

Property Value

AccelerometerRange

DisableModes

Get or set the elements to disable. It can be any axes of the accelerometer and or the gyroscope

public DisableModes DisableModes { get; set; }

Property Value

DisableModes

FifoCount

Get the number of elements to read from the FIFO (First In First Out) buffer

public uint FifoCount { get; }

Property Value

uint

FifoModes

Get or set the FIFO (First In First Out) modes

public FifoModes FifoModes { get; set; }

Property Value

FifoModes

GyroscopeBandwidth

Get or set the gyroscope bandwidth

[Property]
public GyroscopeBandwidth GyroscopeBandwidth { get; set; }

Property Value

GyroscopeBandwidth

GyroscopeBias

Gyroscope bias data

[Property]
public Vector3 GyroscopeBias { get; }

Property Value

Vector3

GyroscopeRange

Get or set the gyroscope range

[Property]
public GyroscopeRange GyroscopeRange { get; set; }

Property Value

GyroscopeRange

GyroscopeScale

Get the real gyroscope bandwidth. This allows to calculate the real angular rate in degree per second

[Property]
public float GyroscopeScale { get; }

Property Value

float

SampleRateDivider

Get or set the sample diver mode

[Property]
public byte SampleRateDivider { get; set; }

Property Value

byte

Methods

CalibrateGyroscopeAccelerometer()

Perform full calibration the gyroscope and the accelerometer It will automatically adjust as well the offset stored in the device The result bias will be stored in the AcceloremeterBias and GyroscopeBias

[Command]
public GyroscopeAccelerometer CalibrateGyroscopeAccelerometer()

Returns

GyroscopeAccelerometer

Gyroscope and accelerometer bias

Dispose()

Cleanup everything

public void Dispose()

GetAccelerometer()

Get the accelerometer in G

[Telemetry("Acceleration")]
public Vector3 GetAccelerometer()

Returns

Vector3

Remarks

Vector axes are the following: +Z +Y \ | / \ | / |/ /|
/ |
/ |
+X

GetGyroscopeReading()

Get the gyroscope in degrees per seconds

[Telemetry("AngularRate")]
public Vector3 GetGyroscopeReading()

Returns

Vector3

Remarks

Vector axes are the following: +Z +Y \ | / \ | / |/ /|
/ |
/ |
+X

GetTemperature()

Get the temperature

[Telemetry("Temperature")]
public Temperature GetTemperature()

Returns

Temperature

ReadByteFromSlaveDevice(I2cChannel, byte, byte, SpanByte)

Read data from any of the I2C slave attached to the MPU9250

public void ReadByteFromSlaveDevice(I2cChannel i2cChannel, byte address, byte register, SpanByte readBytes)

Parameters

i2cChannel I2cChannel

The slave channel to attached to the I2C device

address byte

The I2C address of the slave I2C element

register byte

The register to read from the slave I2C element

readBytes SpanByte

The read data

ReadFifo(SpanByte)

Read data in the FIFO (First In First Out) buffer, read as many data as the size of readData byte span You should read the number of data available in the FifoCount property then read them here. You will read only data you have selected in FifoModes. Data are in the order of the Register from 0x3B to 0x60. ACCEL_XOUT_H and ACCEL_XOUT_L ACCEL_YOUT_H and ACCEL_YOUT_L ACCEL_ZOUT_H and ACCEL_ZOUT_L TEMP_OUT_H and TEMP_OUT_L GYRO_XOUT_H and GYRO_XOUT_L GYRO_YOUT_H and GYRO_YOUT_L GYRO_ZOUT_H and GYRO_ZOUT_L EXT_SENS_DATA_00 to EXT_SENS_DATA_24

public void ReadFifo(SpanByte readData)

Parameters

readData SpanByte

Data which will be read

RunGyroscopeAccelerometerSelfTest()

Run a self test and returns the gyroscope and accelerometer vectores a. If factory Self-Test values ST_OTP≠0, compare the current Self-Test response (GXST, GYST, GZST, AXST, AYST and AZST) to the factory Self-Test values (ST_OTP) and report Self-Test is passing if all the following criteria are fulfilled: Axis | Pass criteria X-gyro | (GXST / GXST_OTP) > 0.5 Y-gyro | (GYST / GYST_OTP) > 0.5 Z-gyro | (GZST / GZST_OTP) > 0.5 X-Accel | 0.5 < (AXST / AXST_OTP) < 1.5 Y-Accel | 0.5 < (AYST / AYST_OTP) < 1.5 Z-Accel | 0.5 < (AZST / AZST_OTP) < 1.5 b. If factory Self-Test values ST_OTP=0, compare the current Self-Test response (GXST, GYST, GZST, AXST, AYST and AZST) to the ST absolute limits (ST_AL) and report Self-Test is passing if all the following criteria are fulfilled. Axis | Pass criteria X-gyro | |GXST| ≥ 60dps Y-gyro | |GYST| ≥ 60dps Z-gyro | |GZST| ≥ 60dps X-Accel| 225mgee ≤ |AXST| ≤ 675mgee Y-Accel| 225mgee ≤ |AXST| ≤ 675mgee Z-Accel| 225mgee ≤ |AXST| ≤ 675mgee c. If the Self-Test passes criteria (a) and (b), it’s necessary to check gyro offset values. Report passing Self-Test if the following criteria fulfilled. Axis | Pass criteria X-gyro | |GXOFFSET| ≤ 20dps Y-gyro | |GYOFFSET| ≤ 20dps Z-gyro | |GZOFFSET| ≤ 20dps

[Command]
public GyroscopeAccelerometer RunGyroscopeAccelerometerSelfTest()

Returns

GyroscopeAccelerometer

the gyroscope and accelerometer vectors

SetWakeOnMotion(uint, AccelerometerLowPowerFrequency)

Setup the Wake On Motion. This mode generate a rising signal on pin INT You can catch it with a normal GPIO and place an interruption on it if supported Reading the sensor won't give any value until it wakes up periodically Only Accelerator data is available in this mode

[Command]
public void SetWakeOnMotion(uint accelerometerThreshold, AccelerometerLowPowerFrequency acceleratorLowPower)

Parameters

accelerometerThreshold uint

Threshold of magnetometer x/y/z axes. LSB = 4mg. Range is 0mg to 1020mg

acceleratorLowPower AccelerometerLowPowerFrequency

Frequency used to measure data for the low power consumption mode

WriteByteToSlaveDevice(I2cChannel, byte, byte, byte)

Write data on any of the I2C slave attached to the MPU9250

public void WriteByteToSlaveDevice(I2cChannel i2cChannel, byte address, byte register, byte data)

Parameters

i2cChannel I2cChannel

The slave channel to attached to the I2C device

address byte

The I2C address of the slave I2C element

register byte

The register to write to the slave I2C element

data byte

The byte data to write to the slave I2C element