Arduino_LSM9DS1 - readMagneticField()

Query the IMU’s magnetometer and return the magnetic field in uT (micro Tesla).

Syntax

IMU.readMagneticField(x,y,z)

Parameters

  • x: float variable where the magnetometer value in the IMU’s x-axis will be stored.
  • y: float variable where the magnetometer value in the IMU’s y-axis will be stored.
  • z: float variable where the magnetometer value in the IMU’s z-axis will be stored.

Returns

1 on success, 0 on failure.

Example

float x, y, z;

if (IMU.magneticFieldAvailable()) {
    IMU.readMagneticField(x, y, z);

    Serial.print(x);
    Serial.print('\t');
    Serial.print(y);
    Serial.print('\t');
    Serial.println(z);
}

See also