Accelero Flips at Vertical Position

Hi all,

Im very new to arduino and sensors and I want to learn to get a 9DOF to work.
I'm using the 9DOF sensor stick from sparkfun

I've got the Gyro working correctly but I'm having problems with the Accelerometer.

As I turn the Accelerometers X axis to a vertical position the Y axis begins to flip.
If I turn the Accelerometers Y axis to a vertical position the X axis begins to flip.
It is hard to explain so I made a video.

This video shows the problem using an 3d object. (I set the yaw to zero as it cannot be measured with the accelerometer)
At first you see the angle's are correct until I reach the turning point. It happens in both axis.

Then I made this second video where you can see the RAW G values and the calculated X and Y angle.

I use this code to get from G to angle in degrees:

Y = ((atan2(rawY,rawZ)+PI)*RAD_TO_DEG);
X = ((atan2(rawX,rawZ)+PI)*RAD_TO_DEG);

How can I fix this problem? I cant find a sollution :frowning:
Thanks in advantage!

You have one axis being held at zero yet use raw values from all three to get X and Y.
I would start looking there. Perhaps X and Y need to be calculated differently depending on condition.

That's how they work.

If you don't want it to work that way, you need to use quaternions.

Thanks for your reply and help to point me in the right direction!
Im going to find out how quaternions work.

Is this weird behavior a gimbal lock?
And are the angle's I've calculated with the formula euler angles?