QMC5883L Calibration

I have designed a unit for our RV that reads several sensors and displays driving, leveling, distance to front objects, engine and atmos conditions, etc.
I have added a QMC5883L and am only using the X axis for compass. Included a calibration routine in the sketch. Everything works perfectly on the bench. The box (with QMC588L and NANO) will be located under the front shroud. It will be mounted near metal of course (with the engine about 3 feet away.) My question(s) is: After install if I do the calibration routine while driving in a circle, will that get me close? Assuming so, how often does this routine have to be done? (I will save the corrections to Eprom to be read at each startup)
I would guess? that all vehicles with compasses have similar mounting issues near metal. Does calibration adust for this and how often do I have to do it? Thanks

Jim

As I understood, the magnetic calibrations just need to be done once and again if you install something close to it. The disturbances usually occur from metals and electrical wiring that is close to the sensor.

What puzzles me is that you only have a magnetometer. If you drive up a hill or if you do some tight turns, the heading changes with pitch and roll. Did you compensate for this?

I am not familiar with this sensor and I could be wrong.

Calibration is specifically of concern for the magnetometer, which needs recalibration whenever it is placed in a (magnetically) different environment. When the magnetic disturbance is a result of the mounting of the magnetometer onto a magnetic object, the magnetometer can be calibrated to compensate for the presence of this disturbance.

reference: https://arxiv.org/pdf/1601.05257.pdf

sracing:
I have added a QMC5883L and am only using the X axis for compass.

How is that possible? You need the y-axis because 90° and 270° both have the same magnetic intensity on the x-axis.

You need both X and Y axes to make a compass, and it will work well only if calibrated in place, and kept level.

Comprehensive calibration tutorial

Simpler procedure, will need some modifications for the QMC5883.

Sorry misspoke. I am using getAzimuth from the library and just putting that into what I defined as an X integer. So yes, I assume the library is providing the required X/y calculation in the return. At least it works.. :slight_smile: Thanks for the other replies. I now feel pretty good about installing in the RV and calibrating.

Dyso, Generally on the road one is close to level enough for the QMC5883L to work fine. it works fine on the bench with angles of 5+ degrees of level changes. Long grades of 5+ degrees are unusual and not worrisome for a short error. I just want to know whether I am heading N, S, E, or West when the sun isn't out. :slight_smile:

Possibly the getAzimouth library command does some adjusting?

The compensation will work if you have an accelerometer. With an accelerometer, you will be able to get the pitch and roll. The compensation uses all the axis of the magnetometer. I don't think the library compensates for that.

Also, I would read the Comprehensive calibration tutorial that @jremington posted. It is really good, I read that when I started playing around with IMU's. If I were you, I would try a manual calibration using exactly this type of strategy. It will help you learn a lot.

Then also take a look at this:

My point is, with very simple coding, you can make an accurate compass. You just need to print the raw values. If you need any more help, just write in the forum.

Another thing you need to consider is if you have a magnetic Declination at your location. Check on this link:
http://www.geomag.bgs.ac.uk/data_service/models_compass/wmm_calc.html
If you have, then you would need to correct that aswell.

#include <QMC5883LCompass.h>

QMC5883LCompass compass;

void setup() {
  Serial.begin(9600);
  compass.init();
  
}

void loop() {
  int x, y, z;
  
  // Read compass values
  compass.read();

  // Return XYZ readings
  x = compass.getX();
  y = compass.getY();
  z = compass.getZ();
  
  Serial.print(" ");
  Serial.print(x);
  Serial.print(" ");
  Serial.print(y);
  Serial.print(" ");
  Serial.print(z);
  Serial.println();
  
  delay(100);
}

This is something you should look at. I think this gives the xyz raw values.

reference: QMC5883LCompass/xyz.ino at master · mprograms/QMC5883LCompass · GitHub