Mpu6050 quaternion

Hello,
I have an mpu6050 and i want to measure XYZ angle but you know there is a gimball lock when i rotate pith angle to 90 degree then i rotate roll angle to 90 degree it exposes gives some meaningless angle. So i know that quaternion angles work very well with gimball lock but i want to show the XYZ angle without gimball lock so i try to convert to quaternion angles to euler angles but ı didnt make it. So if anyone can help i am really going to very thankful.
I am using jeff rowberg mpu6050's library

For help, please read and follow the instructions in the "How to get the best out of this forum" post.

Here is the link: How to get the best out of this forum

May i ask what information you need ?

Read the "How to get the best out of this forum" post to find out!

I read it my question is obvious actually i read many forum question and i saw your many response i also try your library. to sum up, i think you already understand my question. that is why i ask you what information you need it. Because it's not programming question so i dont share any code i already explain question quite detalied. I want to measure angle without gimball lock 0-180 degree for all axis is there a way to do this. One way it comes my mind converting quaternion angles to eular angle does it work ? if it is what is the formulas i try some formulas and didnt work

    yaw   = atan2(2.0f * (q[1] * q[2] + q[0] * q[3]), q[0] * q[0] + q[1] * q[1] - q[2] * q[2] - q[3] * q[3]);   
    pitch = -asin(2.0f * (q[1] * q[3] - q[0] * q[2]));
    roll  = atan2(2.0f * (q[0] * q[1] + q[2] * q[3]), q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3]);
    pitch *= 180.0f / PI;
    yaw   *= 180.0f / PI; 
    yaw   -= 13.8f; // Declination at your location
    roll  *= 180.0f / PI;

Correct.

What you forgot to do was supply any of the information needed to answer the question.

Good luck with your project!

I also ask you to what information you need it so it's up to you

class Quaternion {
    public:
        float w;
        float x;
        float y;
        float z;

quaternion comes like this in jeff rowberg library.
in your equation there is q[0] q[1] q[2] q[3]
how can i match it q[0] = w, q[1] = x, q[2] = y, q[3] = z maybe like this ?

Yes, it is this mapping.

You can have more informations here:
(Conversion between quaternions and Euler angles - Wikipedia)

my breadboard position like this.
in the picture i show the direction with arrıows with this should be roll angle but in serial monitor when i rotate it changes the pitch angle. this is firt problem.
Second problem is when i rotate this angle to 90 degree even it become 80-90 degree suddenly roll angle become -140 degree.

void loop() {
    // if programming failed, don't try to do anything
    if (!dmpReady) return;
    // read a packet from FIFO
    if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet 
        #ifdef OUTPUT_READABLE_QUATERNION
            // display quaternion values in easy matrix form: w x y z
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            /*
            Serial.print("quat\t");
            Serial.print(q.w);
            Serial.print("\t");
            Serial.print(q.x);
            Serial.print("\t");
            Serial.print(q.y);
            Serial.print("\t");
            Serial.println(q.z);
            */
            
            yaw = atan2(2.0f * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z);
            pitch = -asin(2.0f * (q.z * q.z - q.w * q.y));
            roll = atan2(2.0f * (q.w * q.x + q.y * q.z), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z);
    
            // Açıları derece cinsine çevirme
            pitch *= 180.0f / PI;
            yaw *= 180.0f / PI; 
            yaw -= 13.8f; // Bulunduğunuz konum için doğrulama (declination) açısı
            roll *= 180.0f / PI;
            Serial.print("pitch: "); Serial.print(pitch);
            Serial.print(" roll: "); Serial.print(roll);
            Serial.print(" yaw: "); Serial.println(yaw);
            
        #endif

@jremington @nferry

Does you use this librairy ?
https://forum.arduino.cc/t/finally-mpu6050-fifo-dmp-quaternion-code-for-arduino-made-easy/598424

There is an example with a Yaw,Pitch,Roll conversion made in the librairy.

I try it now ı run Simple_MPU6050_Example skecth but same problem exist
when mpu6050 initial position with(0,0,0) then i roll angle to around the 80 and 90 degree then pitch and yaw become -140_-170 degree sudddenly there is something wrong with me or am i missing something i only rotate roll angle to 90 degree so pitch angle should stay 0 degree am i right ? . I just want to measure 0-180 degree with all axis that is what i want
@nferry

So, it is not a software problem, but an hardware or environment issue.

Somes ideas:

  • Is your sensor correctly oriented ?
  • Is your sensor not near a metallic environment (Magnetometer) ?
  • Is your sensor perturbated by external behaviors ?
  • Is your sensor working..... ?
    ...

Not easy, good luck.
Best regards

I dont think my sensor is broken because i execute jeff rowberg teapot example and i move my mpu6050 around i saw it working really good with quaternion but when i try to get angle ı have an issue which i mention it. Thank you for your help. I hope i can make it. It is important for me
@nferry