I’m working with a minor variation of Example2-I2C_Digitial_compass. The problem is that every 15 readings the sensor (or library!) reports a bad reading then goes back to stable values for the next readings. The pattern is rock solid and is independent of the time between measurements. The differences between the stable readings and the anomaly is a function of the sensors rotational position.
I can easily write a filter to drop the anomalous readings, but I’d much rather find – and fix – the cause.
Are you seeing the values in the serial monitor? Would you like to share a screenshot of the noise that you’re getting?
In the following log the computed heading is consistently 35 except for measurements 1471 and 1487 (16 measurements part!) are 51 and 53, respectively:
-
Raw -0.016853/0.024124/0.061073 heading 35
-
Raw -0.016922/0.024223/0.061096 heading 35
-
Raw -0.029877/0.024147/0.060959 heading 51
-
Raw -0.016830/0.024147/0.061066 heading 35
-
Raw -0.016899/0.024162/0.061043 heading 35
-
Raw -0.016861/0.024216/0.061035 heading 35
-
Raw -0.016861/0.024109/0.061058 heading 35
-
Raw -0.016876/0.024132/0.061043 heading 35
-
Raw -0.016869/0.024178/0.061012 heading 35
-
Raw -0.016869/0.024178/0.061081 heading 35
-
Raw -0.016853/0.024178/0.060974 heading 35
-
Raw -0.016853/0.024170/0.061073 heading 35
-
Raw -0.016815/0.024132/0.061119 heading 35
-
Raw -0.016869/0.024109/0.061089 heading 35
-
Raw -0.016869/0.024124/0.061089 heading 35
-
Raw -0.016884/0.024178/0.061066 heading 35
-
Raw -0.016853/0.024147/0.061028 heading 35
-
Raw -0.016884/0.024117/0.061028 heading 35
-
Raw -0.031975/0.024155/0.060898 heading 53
The pattern is absolutely consistent – every 16th reading is wrong.