Class Ak8963
- Namespace
- Iot.Device.Magnetometer
- Assembly
- Iot.Device.Ak8963.dll
AK8963 class implementing a magnetometer.
[Interface("AK8963 class implementing a magnetometer")]
public sealed class Ak8963
- Inheritance
-
Ak8963
Constructors
Ak8963(I2cDevice)
Initializes a new instance of the Ak8963 class.
public Ak8963(I2cDevice i2CDevice)
Parameters
i2CDevice
I2cDeviceThe I2C device.
Ak8963(I2cDevice, Ak8963I2cBase, bool)
Initializes a new instance of the Ak8963 class to use if AK8963 is behind another element and need a special I2C protocol like when used with the MPU9250.
public Ak8963(I2cDevice i2cDevice, Ak8963I2cBase ak8963Interface, bool shouldDispose = true)
Parameters
i2cDevice
I2cDeviceThe I2C device.
ak8963Interface
Ak8963I2cBaseThe specific interface to communicate with the AK8963.
shouldDispose
boolTrue to dispose the I2C device when class is disposed.
Fields
DefaultI2cAddress
Default I2C address for the AK8963.
public const byte DefaultI2cAddress = 12
Field Value
Properties
DefaultTimeout
Gets or sets default timeout to use when timeout is not provided in the reading methods.
[Property]
public TimeSpan DefaultTimeout { get; set; }
Property Value
HasDataToRead
True if there is a data to read.
public bool HasDataToRead { get; }
Property Value
MageneticFieldGeneratorEnabled
Gets or sets a value indicating whether the device is in self test mode. If set to true, this creates a magnetic field Once you read it, you will have the results of the self test 14-bit output(BIT=“0”) | HX[15:0] | HY[15:0] | HZ[15:0] Criteria | -50 =< HX =< 50 | -50 =< HY =< 50 | -800 =< HZ =< -200 16-bit output(BIT=“1”) | HX[15:0] | HY[15:0] | HZ[15:0] Criteria | -200 =< HX =< 200 | -200 =< HY =< 200 | -3200 =< HZ =< -800
[Property]
public bool MageneticFieldGeneratorEnabled { get; set; }
Property Value
MagnetometerAdjustment
Gets or sets the magnetometer hardware adjustment bias.
[Property]
public Vector3 MagnetometerAdjustment { get; set; }
Property Value
- Vector3
MagnetometerBias
Gets or sets the magnetometer bias.
[Property]
public Vector3 MagnetometerBias { get; set; }
Property Value
- Vector3
MeasurementMode
Gets or sets the measurement mode.
[Property]
public MeasurementMode MeasurementMode { get; set; }
Property Value
OutputBitMode
Gets or sets the output bit rate.
[Property]
public OutputBitMode OutputBitMode { get; set; }
Property Value
Methods
CalibrateMagnetometer(int)
Calibrate the magnetometer. Make sure your sensor is as far as possible of magnet Calculate as well the magnetometer bias. Please make sure you are moving the magnetometer all over space, rotating it. Please make sure you are not close to any magnetic field like magnet or phone.
public Vector3 CalibrateMagnetometer(int numberOfMeasurements = 1000)
Parameters
numberOfMeasurements
intNumber of measurement for the calibration, default is 1000.
Returns
- Vector3
Returns the factory calibration data.
Dispose()
Cleanup everything.
public void Dispose()
GetDeviceInfo()
Get the device information.
public byte GetDeviceInfo()
Returns
- byte
The device information.
IsVersionCorrect()
Check if the version is the correct one (0x48). This is fixed for this device Page 28 from the documentation : Device ID of AKM. It is described in one byte and fixed value. 48H: fixed.
public bool IsVersionCorrect()
Returns
- bool
Returns true if the version match.
ReadMagnetometer(bool)
Read the magnetometer with bias correction and can wait for new data to be present.
[Telemetry("Magnetometer")]
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:
+X
\ | /
\ | /
|/
/|
/ |
/ |
+Z +Y.
ReadMagnetometer(bool, TimeSpan)
Read the magnetometer with bias correction and can wait for new data to be present.
public Vector3 ReadMagnetometer(bool waitForData, TimeSpan timeout)
Parameters
waitForData
boolTrue to wait for new data.
timeout
TimeSpanTimeout for waiting the data, ignored if waitForData is false.
Returns
- Vector3
The data from the magnetometer.
Remarks
Vector axes are the following:
+X
\ | /
\ | /
|/
/|
/ |
/ |
+Z +Y.
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:
+X
\ | /
\ | /
|/
/|
/ |
/ |
+Z +Y.
ReadMagnetometerWithoutCorrection(bool, TimeSpan)
Read the magnetometer without Bias correction and can wait for new data to be present.
public Vector3 ReadMagnetometerWithoutCorrection(bool waitForData, TimeSpan timeout)
Parameters
waitForData
boolTrue to wait for new data.
timeout
TimeSpanTimeout for waiting the data, ignored if waitForData is false.
Returns
- Vector3
The data from the magnetometer.
Remarks
Vector axes are the following:
+X
\ | /
\ | /
|/
/|
/ |
/ |
+Z +Y.
Reset()
Reset the device.
[Command]
public void Reset()