howardhb wrote:In Port Elizabeth, South Africa, I have to run the my 5883L gain set at 0x30, otherwise, I get "saturated" values like you report.
You should always re-calibrate the Mag (after changing gain settings) by pressing CALIB_MAG in the GUI.
Also, when calibrating, make sure that you turn the copter at least 2 revolutions in each axis.
H.
interesting. in my case, the raw adc values coming from the sensor are bad, but only for one axis. calibration just uses the min and max of the sampled adc values to establish a center, so it might not help in my case. but, it brings me to the next point (which might explain yours)

i looked a little closer at the code and am trying to figure out how magCal[] is used.
magCal is based on initial sample value in order to scale subsequent readings to around magnitude 1000 for each axis individually.
during init:
<magcal> = 1000.0 / <first adc>
during calibration:
<reading> = <next adc> * <magcal>
record <min> = min({<readings>})
record <max> = max({<readings>})
at end of calibration:
compute <mid> = midpoint of <min> and <max>
subsequently:
<reading> = <next adc> * <cal> - <mid>
<adc> is a 16 bit value (range is -32768 to 32767). if the ratio of subsequent <adc> to the initial <first adc> exceeds around 32, then the computation will overflow. fortunately, it looks like the range of the sampled values is like -200 to -500 for example in my case. it might not be in your case (location dependent).
but it also does raise the question of how accurate is this normalization (to 1000) if we only relied on the initial sampled value to scale.
i had thought that magCal should really be computed after establishing the min, max and mid of the raw <adc> values during calibration, for each axis individually:
during calibration:
record <min> = min({<adc>})
record <max> = max({<adc>})
at end of calibration:
<mid> = midpoint of <min> and <max>
magCal = 1000.0 / (<max> - <min>)
subsequently:
<reading> = (<next adc> - <mid>) * magCal
in this approach, all 3 axis will be normalized to the same range (which is important for the vector computation).
sorry for the long writeup, i hope to be able to get to the bottom of this and help towards the effort.
thanks.