Go Down

Topic: Strange behavior of MPU6050 (Read 1 time) previous topic - next topic

Feb 22, 2013, 09:20 pm Last Edit: Feb 22, 2013, 09:33 pm by stefanh Reason: 1

i have a little problem with my MPU6050 sensor, when i dont move the sensor i get the following values as you can see in this picture (the timespan is 40secs)

for reading the values from the sensor i use the following code:
Code: [Select]
#include "Motion.h"

#include "MPU6050_6Axis_MotionApps20.h"

MPU6050 mpu;

int Motion::init()
   dmpReady = false;
   mpuInterrupt = false;
   devStatus = mpu.dmpInitialize();
   if(devStatus == 0)
       mpuIntStatus = mpu.getIntStatus();
       dmpReady = true;
       packetSize = mpu.dmpGetFIFOPacketSize();
   return devStatus;

int Motion::getValues(float *ax, float *ay, float *az, float *gz)
   if(!dmpReady) return 1;
   if(!mpuInterrupt) return 2;
   mpuInterrupt = false;
   mpuIntStatus = mpu.getIntStatus();
   fifoCount = mpu.getFIFOCount();
   if(fifoCount < packetSize) return 3;
   if((mpuIntStatus & 0x10) || fifoCount == 1024)
       return -1;
   if(!(mpuIntStatus & 0x02)) return 4;
   mpu.getFIFOBytes(fifoBuffer, packetSize);
   Quaternion q;           // [w, x, y, z]         quaternion container
   VectorInt16 aa;         // [x, y, z]            accel sensor measurements
   VectorInt16 aaReal;     // [x, y, z]            gravity-free accel sensor measurements
   VectorFloat gravity;    // [x, y, z]            gravity vector
   float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector
   mpu.dmpGetQuaternion(&q, fifoBuffer);
   mpu.dmpGetGravity(&gravity, &q);
   mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
   mpu.dmpGetAccel(&aa, fifoBuffer);
   mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
   *ax = (aaReal.x/16384.0) * 9.81;
   *ay = (aaReal.y/16384.0) * 9.81;
   *az = (aaReal.z/16384.0) * 9.81;
   *gz = (ypr[2]/131.0) * 180/M_PI;
   return 0;

in the setup()-method I call Motion::init() and in the loop-method I call Motion::getValues.
Can anyone explain why I get these strange values or what i am doing wrong??

I have used the libraries from https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 an my code is very similar to his examples.


greetings stefan


which value are you plotting , to get that graph ?

Its the acceleration in the x Direktion! The *ax value from the getValues-Function!

Go Up