Skip to main content
Visitor II
June 11, 2021
Question

MPU6050 gyroscope not working correctly

  • June 11, 2021
  • 2 replies
  • 6457 views

I am using the bluepill board and was trying to compute the angle from gyroscope raw data. However, when I tilt the sensor, the angle measured doesn't change as expected. It's changing between 1.xx and 2.xx regardless of the tilt angle. The sensor is being read every 4ms (I have configured the timer to interrupt at every 4ms). I have attached my code here, can anyone please help to to figure out what is the problem? Thanks!

Update: I try to remove the offset but the reading is still inaccurate. When the row angle is 45 degrees, it shows around 20 degrees; when the row angle is 30, it shows around 13 degrees. Both the angle calculated seems to be around 2.3 times less than the actual angle.

    This topic has been closed for replies.

    2 replies

    Super User
    June 11, 2021

    > However, when I tilt the sensor, the angle measured doesn't change as expected. It's changing between 1.xx and 2.xx regardless of the tilt angle

    A gyro doesn't measure angle, it measures the rate of change in angle.

    M7890.1Author
    Visitor II
    June 11, 2021

    Yes. So I am actually integrating the angular velocity to get the angle. Sorry for not describing it clearly. See the code snippet below:

    gyro_roll_angle += gyro_y_raw/65.5*0.004;
    gyro_pitch_angle += gyro_x_raw/65.5*0.004;
    gyro_yaw_angle += gyro_z_raw/65.5*0.004;

    Super User
    June 11, 2021
    Integrating it like this is going to amplify the noise in the signal. It’s just not a viable strategy for getting the absolute angle.
    Flight control algorithms use both the accelerometer and the gyro to find the angle with respect to gravity, but it’s not straightforward.
    M7890.1Author
    Visitor II
    June 16, 2021

    The printing problem is solved but right now the drift in the gyroscope reading is extremely severe. I have already take 100 samples of the gyroscope reading prior to actual measurement and take the average of them. This offset is then subtracted from the raw data during actual measurement. The variable used to store the accumulated offset is a int32_t variable, so it's definitely large enough to store the value. What could be the problem?