Hi guys,
I have played with the BMX055 sensor from Bosch. I want to find the heading of the system using the integrated magnetometer but I can not find the heading of the system.
I have tried using below equation but it did not work.
Heading = atan2(Y_magnetometer, X_magnetometer) * 180 / PI;
the code for reading the magnetometer data:
// Addr_Mag 0x13
void BMX055_Mag()
{
int data[8];
for (int i = 0; i < 8; i++)
{
Wire.beginTransmission(Addr_Mag);
Wire.write((0x42 + i)); // Select data register
Wire.endTransmission();
Wire.requestFrom(Addr_Mag, 1); // Request 1 byte of data
// Read 6 bytes of data
// xMag lsb, xMag msb, yMag lsb, yMag msb, zMag lsb, zMag msb
if (Wire.available() == 1)
data[i] = Wire.read();
}
// Convert the data
xMag = ((data[1] <<8) | data[0])>>3;
if (xMag > 4095) xMag -= 8192;
yMag = ((data[3] <<8) | data[2])>>3;
if (yMag > 4095) yMag -= 8192;
zMag = ((data[5] <<8) | data[4])>>1;
if (zMag > 16383) zMag -= 32768;
}
My question is:
- Is there any problem with my provided code?
- How to calculate the heading using a magnetometer?
Thank you for your help,