Done!

First I had to calibrate the Magnetical Z axis. This I had forgott.

Then I could use this code:

```
// ---------- 3D Compensated Compass Heading -----------------------
accRaw[0] = FXO.accelData.x;
accRaw[1] = FXO.accelData.y;
accRaw[2] = FXO.accelData.z;
magRaw[0] = -FXO.magData.x;
magRaw[1] = FXO.magData.y;
magRaw[2] = FXO.magData.z;
headingraw = atan2(magRaw[1], magRaw[0]) * RadToDeg;
xM = magRaw[0];
yM = magRaw[1];
zM = magRaw[2];
xG = accRaw[0];
yG = accRaw[1];
zG = accRaw[2];
pitch = atan2(xG, sqrt(yG * yG + zG * zG));
roll = atan2(yG, zG);
roll_print = roll * RadToDeg;
pitch_print = pitch * RadToDeg;
xM2 = xM * cos(pitch) + zM * sin(pitch);
yM2 = xM * sin(roll) * sin(pitch) + yM * cos(roll) - zM * sin(roll) * cos(pitch);
compHeading = atan2(yM2, xM2) * RadToDeg;
compHeading = compHeading + 90 ; //Korrektur weil Sensor 90° auf der Platine eigebaut ist.
if (compHeading <= 0) {//If the heading is negative (ranges from -1 to -180)
compHeading = compHeading * -1; //Negate the heading
}
else if (compHeading > 0) {
compHeading = 360 - compHeading;
}
```