Digital compass help

Hi guys,

I'm messing around with the Honeywell HMC5883L magnetometer trying to build a digital compass as my first ever arduino project.

I've found an amazing bit of code that does a great job of calibrating the magnometer to provide usable results. Here is the link to the code: GitHub - helscream/HMC5883L_Header_Arduino_Auto_calibration: HMC5883L on Arduino with auto calibration capability
There are two libraries that come with it so I can't really copy and paste all of the code on here.

Anyways what I'd like to be able to do is take the X Y Z and gain compensation results that this program comes up with and use those results in another sketch I'm writing to act like a compass. I'd rather not have to calibrate the compass every time I turn it on which is what this program does. But I'm quite new to this and am having trouble figuring out which direction to take. A kind suggestion? Thank you!

The calibration program will provide gain and offset for each axis. Your compass program must apply those corrections, before using the data to estimate the direction of North, so they can be coded directly into that program.

Magnetometers need to be calibrated from time to time, especially if the environment changes (e.g. the presence of magnets, iron objects, current carrying conductors, etc.).

Here are a couple of other links on calibration, in increasing order of sophistication and accuracy:

Once you have a set of calibration values you can put then into EEPROM and load them from there after reset.

Modify your calibration program to write the results to the EEPROM. You may need to add an extra button to trigger the write, or add a serial command interpreter. Write down which locations you used in the EEPROM - location 0 can store the X value, location 2 can store the Y value etc. Remember that integers have 16 bits so they will fill 2 EEPROM locations. (longs and floats are bigger.)

Now you will have that Arduino 'paired' to that magnetometer. It will remember those calibration values 'forever'. Load up your actual program, which reads those calibrations from the EEPROM in the setup() function.