Calibrating the SEN-19895 SparkFun 9DoF IMU Breakout - ISM330DHCX, MMC5983MA (Qwiic)

I bought the SEN-19895 in hopes of being able to accurately measure heading for a project I am doing. This heading sensor is completely off giving only values from the range of 190 - 230 degrees; not orientated correctly.

I can’t find any documentation on how to calibrate this sensor to get a range from 0 - 360 degrees and that is orientated correctly to magnetic north. Is there a code I need to run through the sensor to calibrate it and are there any additional steps to be taken or is this sensor just not designed to provide an accurate heading?

All magnetometers need to be calibrated before they can be used as compasses, if possible in the final installation, to correct for local magnetic fields and the effects of nearby iron-containing objects. Gyros must also be calibrated to remove the zero-rotation offsets, and accelerometers generally benefit as well.

Best overview of magnetometer/accelerometer calibration: https://thecavepearlproject.org/2015/05 … r-arduino/

Example of successful calibration for an extreme case: https://forum.pololu.com/t/correcting-t … eter/14315

I have tried following both of these links and I keep getting error after error.

This is the code they told me to use:

#include <Wire.h>

#include <SparkFun_MMC5983MA_Arduino_Library.h> // Include the library for MMC5983MA sensor

SFE_MMC5983MA magSensor; // Create an instance of the MMC5983MA class

void setup() {

Serial.begin(9600); // Initialize serial communication

Wire.begin(); // Initialize I2C communication

// Initialize the sensor

if (!magSensor.begin()) {

Serial.println(“Could not find a valid MMC5983MA sensor, check wiring!”);

while (1);

}

// Calibrate the sensor

magSensor.calibrate();

}

void loop() {

// Read magnetometer data

float x, y, z;

magSensor.read(&x, &y, &z);

// Print raw magnetometer data

Serial.print("Raw Magnetometer Data (uT): ");

Serial.print("X: ");

Serial.print(x);

Serial.print(" Y: ");

Serial.print(y);

Serial.print(" Z: ");

Serial.println(z);

// Perform calibration

float calibratedData[3];

calibrate(x, y, z, calibratedData);

// Print calibrated magnetometer data

Serial.print("Calibrated Magnetometer Data (uT): ");

Serial.print("X: ");

Serial.print(calibratedData[0]);

Serial.print(" Y: ");

Serial.print(calibratedData[1]);

Serial.print(" Z: ");

Serial.println(calibratedData[2]);

delay(1000); // Delay for readability

}

void calibrate(float x, float y, float z, float* calibratedData) {

// Perform calibration here (you can use the calibrate function you provided in the original Python code)

// Note: Calibration logic may need adjustments depending on sensor characteristics and calibration method used

// For simplicity, you can directly use the calibration function from your original Python code

// Placeholder calibration function

calibratedData[0] = x; // Placeholder, replace with actual calibration logic

calibratedData[1] = y; // Placeholder, replace with actual calibration logic

calibratedData[2] = z; // Placeholder, replace with actual calibration logic

}

This is the error code I keep receiving:

Compilation error: ‘class SFE_MMC5983MA’ has no member named ‘calibrate’.

If I change the code it says it has no member to read or get measurement.

The error message is self explanatory: there is no function named “calibrate” in the SFE_MMC5983MA sensor library.

There is a function called “calibrate” in the code you posted, which you could call by name (remove the “magSensor.” prefix), but it is a placeholder and does nothing useful. You would need to modify it to apply the calibration constants derived by other programs.

To get on with this project, you will need to read and have some basic understanding of the sensor calibration background material. The sensor won’t be useful until it is properly calibrated.