Mpu6050 direction in degrees question

Hey guys,
I hope this is a quick question. :slight_smile: using the mpu6050, is it possible to get information about which direction it is facing in degrees? So if I'm holding it horizontal, and I rotate it, can I get it to output the values in degrees between 0 and 360? Is this also possible to do without all the drift error from double integration etc? Thanks.

Anyone? I don't want to get position just direction of the mpu6050 is facing on x and y in degrees.

Can you read the compass?
if so the following will return the heading based on the raw outputs form x and y with the compass held level (no tilt compensation).

float head = atan2(y, x);
  float declinationAngle = 188.8/1000.0;    //angle in rads.  You can find the value for your area with Google
  head += declinationAngle;
  if(head < 0.00)
    head += 2*PI;
  if(head > 2*PI)
    head -= 2*PI;
  head = head * 180.00/M_PI;
  Serial.print("Heading  ");
  Serial.println(head);

I don't think the mpu6050 has a compass. I think that is the mpu9150.

The MPU6050 has an accelerometer and a rate gyro (which tells you how fast it is rotating). The accelerometer will tell you which direction is down and in a motionless situation, that is all the information you have.

Let's say it is always at a 15 degree angle or greater and you are rotating it, like it is attached to the outside of a spinning top that you are spinning very slowly, that is motion. So what equation I could I use to calculate the direction in degrees it is facing, as it changes during rotation? Does that make sense?

You integrate the rotation rate over time, to get the angle relative to wherever you started.

Sorry, I got my IMU's mixed up.
Look up complimentary filter for method of using accel and rate gyro to find orientation.
Works in pitch and roll using gravity as a reference, not so good in yaw as there is no reference.

Can I use the gyro to get the rotation rate? How would I get that?

Can I use the gyro to get the rotation rate? How would I get that?

Just read the rate gyro data registers. The data sheet will tell you how to do that.

Be aware that the thing is not exactly precise. The longer you use it, the more error you will accumulate.