MPU6050 pitch and roll problem

Hi!

I have a project where I want to measure the yaw-pitch-roll angles of a load cell. I'm using a MPU6050 to measure angles. I've read that getting the yaw correct may be hard because it drifts. However, The only angle that is responsive and correct in my setup is the yaw. The pitch and roll are lagging and very slow to respond to the change in orientation. When I rotate they first register movement in the opposite direction (due to inertia?) before they creep towards the correct orientation. I'm using the lib from Jeff Rowberg as a base for my MPU6050 stuff in my code. Circuit drawing and code is attached. Does anyone have an idea as to how my pitch and roll can be fixed?

Edit: Circuit drawing was blocked...
Edit2: The converged pitch and roll values are not close to correct.

force_angle__SD_skipole.ino (10.7 KB)

For static pitch and roll measurements, all you need is the accelerometer, and the code is very simple:

// minimal MPU-6050 tilt and roll (sjr)
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
// tested with eBay Pro Mini, **no external pullups on SDA and SCL** (works with internal pullups!)
// A4 = SDA, A5 = SCL

#include<Wire.h>
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;

void setup() {

  Wire.begin();                                      //begin the wire communication
  Wire.beginTransmission(MPU_addr1);                 //begin, send the slave adress (in this case 68)
  Wire.write(0x6B);                                  //make the reset (place a 0 into the 6B register)
  Wire.write(0);
  Wire.endTransmission(true);                        //end the transmission
  Serial.begin(9600);
}

void loop() {

  Wire.beginTransmission(MPU_addr1);
  Wire.write(0x3B);  //send starting register address, accelerometer high byte
  Wire.endTransmission(false); //restart for read
  Wire.requestFrom(MPU_addr1, 6, true); //get six bytes accelerometer data
  int t = Wire.read();
  xa = (t << 8) | Wire.read();
  t = Wire.read();
  ya = (t << 8) | Wire.read();
  t = Wire.read();
  za = (t << 8) | Wire.read();
// formula from https://wiki.dfrobot.com/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing
  roll = atan2(ya , za) * 180.0 / PI;
  pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI; //account for roll already applied

  Serial.print("roll = ");
  Serial.print(roll,1);
  Serial.print(", pitch = ");
  Serial.println(pitch,1);
  delay(400);
}

The measurements should not be static, but able to track the orientation of a skipole during skiing. For now only yaw is working, pitch and roll is off.

You could try the attached code, which uses the Mahony orientation filter. It works as least as well as the mysterious DMP code, but it is essential to properly calibrate the accelerometer and gyro.

This particular version calibrates the gyro upon startup (hold still until the offsets are printed), but you should calibrate the accelerometer independently.

With the MPU-6050 the yaw angle will always be relative to the starting orientation, and will drift.

MPU6050_Mahony_gyro.ino (9.31 KB)

Cool, thanks, I will try it :slight_smile: