Go Down

Topic: mpu6050 problem (Read 30531 times) previous topic - next topic



Hello guys! Does any one of you, especially jjspierx, know how to modify the MPU6050_DMP6 code to work without having to input a character to start the DMP? I need this code without the character input and I am kind of new to Arduino.


Hi there, I am using MPU6050 in a self balancing robot project. But I am getting a lot of fluctuations in the reading of angle obtained by using x axis gyro and y,z axis accelerometer. When the body is suddenly tilted on either sides, the sensor gives the opposite values i.e if body is suddenly leaned forward in +ve direction of angle change it gives -ve values so  the pwm reverses its direction and vice versa. How can this problem be solved. I am using just one axis to control so only x axis gyro and y and z axis accelerometer.

  double accXangle=(atan2(AcY,AcZ)+PI)*RAD_TO_DEG;
  //  Convert gyro raw vlues to degrees!
  double gyroXrate=(double)GyX/131.0;
  // Complementary Filter!
  double compAngleX = (0.97 * (compAngleX + (gyroXrate * dt))) + (0.03 * accXangle);
  //Serial.println("AcX = ");
  float a=31.142*(compAngleX-5.35);
  float ang=a-90;
  return ang;

I am using this code to get the tilt angle.


Yeah, that code is not using the DMP and is just returning raw values from the sensor.  So the sketch is working correctly.  If you want to output values that have units and mean something, try using this code.


This is the code that uses the DMP to output values in G-force and degrees of rotation.

The code you are using is just the individual raw values from the the accelerometer and gyro.  The DMP code uses a fusion algorithm use the data from both the acclerometer AND gyro together to get much more accurate accleration and angle measurements than you get from the individual sensors.  The calculations are being done on the DMP of the sensor though, so we can't really see what is going, its a black box to us.

The code from the FreeIMU library does not use the DMP, but uses its own fusion algorithm to determine the orientation of the sensor, and from what I can tell is at least as accurate and faster than the DMP code. 

I would start with getting the DMP code working first though and see if you are happy with it or not before moving on.

Good luck.
i tried to compile the code what you advice but it always gives error. please can you help me ?

Go Up