Pages: [1]   Go Down
Author Topic: Strange behavior of MPU6050  (Read 801 times)
0 Members and 1 Guest are viewing this topic.
Munich
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

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:
#include "Motion.h"

#include "MPU6050_6Axis_MotionApps20.h"

MPU6050 mpu;

int Motion::init()
{
    
    Wire.begin();
    
    dmpReady = false;
    mpuInterrupt = false;
    
    mpu.initialize();
    devStatus = mpu.dmpInitialize();
    
    if(devStatus == 0)
    {
        mpu.setDMPEnabled(true);
        mpuIntStatus = mpu.getIntStatus();
        dmpReady = true;
        packetSize = mpu.dmpGetFIFOPacketSize();
        mpu.resetFIFO();
    }
    
    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)
    {
        mpu.resetFIFO();
        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.

Thanks!

greetings stefan
« Last Edit: February 22, 2013, 03:33:45 pm by stefanh » Logged

Offline Offline
Faraday Member
**
Karma: 61
Posts: 2879
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

which value are you plotting , to get that graph ?
Logged

Munich
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: