I have a MAG3110 unit that I’m using with an Arduino. What I would like to do is to save my calibration data and then reload it in another sketch. I’m not interested in using the magnetometer as a compass, but instead would like to simply zero each axis within a mu-metal magnetic shielding container so I can use the device for absolute magnetic field measurements (or as close as possible!).
I can run the calibration example file (SparkFun_MAG3110_Calibrated), which I’ve used as a starting point. I’ve extended it to work for the z-axis as well. From there, I have saved the offset value (x_offset) and scale (x_scale) from the calibration in the EEPROM. I can reload these values in another sketch, however, I can’t seem to actually set the offsets to the calibrated values. I’m using the setOffset function as mentioned in https://learn.sparkfun.com/tutorials/ma … guide-/all. For x_scale, I simply load the saved variable when initializing the magnetometer, but I’m not sure if this is the right thing to do.
As an example, my raw x reading (without calibration) is around 1200 mG. After running the calibration sketch, this resets to a value close to zero, which I would have expected. x_offset comes out as around 200 mG and x_scale is 0.00. When I load these values in another sketch, my x axis reads as around 1000 mG (i.e., 1200 - 200). Naively, I would expect that the offset should be more like 1200. The x scale is a mystery to me. The calculation for it is x_scale = 1.0/(x_max - x_min) from the SparkFun library, so how can it possibly come out as 0.00?
If anyone has any experience with the magnetometer, I would appreciate some assistance! I’m a total newbie to Arduino, so it’s possible that I’m missing something obvious.