HMC5883L compass module - Y/Z movement affects each other

I'm using HMC5883L compass module with arduino. There is a strange issue with the readings from this module - for some reason, the Z and Y axis are both affected from only Z axis movement or Y axis movement.

I need to get correct readings of the Z axis (compass) without/with minimal affect from the other axis changes

Y = tilting nose up/down
Z = turning left/right (compass)

I tried several libraries, the last two from these links:

the module:
https://www.ebay.com/itm/GY-273-HMC...896943&hash=item5d37766e10:g:7PwAAOSwYvFZL5aC

impeham:
I'm using HMC5883L compass module with arduino. There is a strange issue with the readings from this module - for some reason, the Z and Y axis are both affected from only Z axis movement or Y axis movement.

All the axes are interrelated; have you run the HMC5883L_compass.ino from this library you have used: GitHub - jarzebski/Arduino-HMC5883L: HMC5883L Triple Axis Digital Compass Arduino Library ?

Note the calculation used in that example:

  // Calculate heading
  float heading = atan2(norm.YAxis, norm.XAxis);

You can do a similar calculation using, say, XAxis and Zaxis for up/down angle.

Yours,
TonyWilk

You probably need to implement a tilt-compensated compass, and for that you need an accelerometer in addition to the magnetometer.

TonyWilk:
All the axes are interrelated; have you run the HMC5883L_compass.ino from this library you have used: GitHub - jarzebski/Arduino-HMC5883L: HMC5883L Triple Axis Digital Compass Arduino Library ?

Note the calculation used in that example:

  // Calculate heading

float heading = atan2(norm.YAxis, norm.XAxis);




You can do a similar calculation using, say, XAxis and Zaxis for up/down angle.

Yours,
TonyWilk

Thanks - yes - i did try the HMC5883L_compass.ino sketch and changed the magnetic declination according to my location, but the roll and pitch are heavily affecting the heading - i need heading to be as clear as possible from the other movements.

jremington:
You probably need to implement a tilt-compensated compass, and for that you need an accelerometer in addition to the magnetometer.

this is an interesting idea, but the calculation between the sensors might be complicated - i'll check it out anyway if i won't have another choice.