HMC5883L - Crazy amount of jitter? I2C

I'm using the HMC5883L. Whilst it's generally giving correct data. It is also demonstrating a very extreme jitter with the values. For example, if the value is at 84 - It will continuously print between a few values e.g 83/84/85.

Anyone any idea? Thank you.

Code example snippet using library.

    mag.getHeading(&mx, &my, &mz);
    float heading = atan2(my, mx);
   
    if(heading < 0) {
    heading += 2 * M_PI; }
    value = round(heading * 180/M_PI);
    Serial.println(heading);
    delay(10);

It will continuously print between a few values e.g 83/84/85

That is hardly "extreme jitter" and looks like normal noise to me. Average a few readings to reduce noise.

If the sensor is properly calibrated, the basic compass accuracy is at best +/- 1 degree.

Whilst it didn't need your comment I'll explain further - by extreme, I mean the speed in which these values are changing. Either way, thanks for the response.

Averaging would be a great option, the only problem seems that most of the time, the value is only changing between two values and its inconsistent. So the result of the average is inconsistent too.

by extreme, I mean the speed in which these values are changing.

In general, the value will be different every time you sample it. If you sample rapidly, the value changes rapidly.

Noise in electronic circuits is an unavoidable fact of life. Averaging only reduces it.

dean_ixd:
I'm using the HMC5883L. Whilst it's generally giving correct data. It is also demonstrating a very extreme jitter with the values. For example, if the value is at 84 - It will continuously print between a few values e.g 83/84/85.

That's as good as you'll get with a MEMS magnetometer. They are not precision devices, they are small and
they are cheap, those are the strong points. If you want precision you need a different technology.

[ You might find some are rather better than others of course, but they are not SQUIDs! ]