Class Mpu9250
MPU9250 - gyroscope, accelerometer, temperature and magnetometer (thru an embedded AK8963).
[Interface("MPU9250 - gyroscope, accelerometer, temperature and magnetometer (thru an embedded AK8963)")]
public class Mpu9250 : Mpu6500
- Inheritance
-
Mpu9250
- Inherited Members
Constructors
Mpu9250(I2cDevice, bool, I2cDevice?)
Initialize the MPU9250
public Mpu9250(I2cDevice i2cDevice, bool shouldDispose = true, I2cDevice? i2CDeviceAk8963 = null)
Parameters
i2cDevice
I2cDeviceThe I2C device
shouldDispose
boolWill automatically dispose the I2C device if true
i2CDeviceAk8963
I2cDeviceAn I2C Device for the AK8963 when exposed and not behind the MPU9250
Properties
HasDataToRead
True if there is a data to read
public bool HasDataToRead { get; }
Property Value
MagnetometerAdjustment
Get the magnetometer hardware adjustment bias
[Property]
public Vector3 MagnetometerAdjustment { get; }
Property Value
- Vector3
MagnetometerMeasurementMode
Select the magnetometer measurement mode
public MeasurementMode MagnetometerMeasurementMode { get; set; }
Property Value
MagnetometerOutputBitMode
Select the magnetometer output bit rate
[Property]
public OutputBitMode MagnetometerOutputBitMode { get; set; }
Property Value
MagnometerBias
Get the magnetometer bias
[Property]
public Vector3 MagnometerBias { get; }
Property Value
- Vector3
Remarks
Vector axes are the following:
+Z +Y
\ | /
\ | /
|/
/|
/ |
/ |
+X
Methods
CalibrateMagnetometer(int)
Calibrate the magnetometer. Make sure your sensor is as far as possible of magnet. Move your sensor in all direction to make sure it will get enough data in all points of space Calculate as well the magnetometer bias
[Command]
public Vector3 CalibrateMagnetometer(int calibrationCounts = 1000)
Parameters
calibrationCounts
intnumber of points to read during calibration, default is 1000
Returns
- Vector3
Returns the factory calibration data
Dispose()
Cleanup everything
public void Dispose()
GetMagnetometerVersion()
Check if the magnetometer version is the correct one (0x48)
[Property("MagnetometerVersion")]
public byte GetMagnetometerVersion()
Returns
- byte
Returns the Magnetometer version number
Remarks
When the wake on motion is on, you can't read the magnetometer, so this function returns 0
ReadMagnetometer(bool)
Read the magnetometer with bias correction and can wait for new data to be present
[Telemetry("MagneticInduction")]
public Vector3 ReadMagnetometer(bool waitForData = true)
Parameters
waitForData
booltrue to wait for new data
Returns
- Vector3
The data from the magnetometer
Remarks
Vector axes are the following:
+Z +Y
\ | /
\ | /
|/
/|
/ |
/ |
+X
ReadMagnetometerWithoutCorrection(bool)
Read the magnetometer without bias correction and can wait for new data to be present
public Vector3 ReadMagnetometerWithoutCorrection(bool waitForData = true)
Parameters
waitForData
booltrue to wait for new data
Returns
- Vector3
The data from the magnetometer
Remarks
Vector axes are the following:
+Z +Y
\ | /
\ | /
|/
/|
/ |
/ |
+X
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
public void SetWakeOnMotion(uint accelerometerThreshold, AccelerometerLowPowerFrequency acceleratorLowPower)
Parameters
accelerometerThreshold
uintThreshold of magnetometer x/y/z axes. LSB = 4mg. Range is 0mg to 1020mg
acceleratorLowPower
AccelerometerLowPowerFrequencyFrequency used to measure data for the low power consumption mode