MPU6050: Lot of Compilation warnings.

Hi all,

Am building a balancing platform. When i installed i2cdev lib and include the following headers and compile the code i get a lot of compilation errors. Is everybody getting the same

headers
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"

In file included from /Users/ramakrishnanmanoharan/Documents/Arduino/balacingbot/balacingbot.ino:4:0:
/Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050_6Axis_MotionApps20.h: In member function 'uint8_t MPU6050::dmpGetGravity(int16_t*, const uint8_t*)':
/Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050_6Axis_MotionApps20.h:522:65: warning: integer overflow in expression [-Woverflow]

  • (int32_t)qI[2] * qI[2] + (int32_t)qI[3] * qI[3]) / (2 * 16384);
    ^~~~~
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050_6Axis_MotionApps20.h: In member function 'uint8_t MPU6050::dmpProcessFIFOPacket(const unsigned char*)':
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050_6Axis_MotionApps20.h:576:60: warning: unused parameter 'dmpData' [-Wunused-parameter]
    uint8_t MPU6050::dmpProcessFIFOPacket(const unsigned char dmpData) {
    ^~~~~~~
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.cpp: In member function 'void MPU6050::getMotion9(int16_t
    , int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*)':
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.cpp:1769:113: warning: unused parameter 'mx' [-Wunused-parameter]
    void MPU6050::getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz) {
    ^~
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.cpp:1769:126: warning: unused parameter 'my' [-Wunused-parameter]
    void MPU6050::getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz) {
    ^~
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.cpp:1769:139: warning: unused parameter 'mz' [-Wunused-parameter]
    void MPU6050::getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz) {
    ^~
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.h:436:7: warning: type 'struct MPU6050' violates the C++ One Definition Rule [-Wodr]
    class MPU6050 {
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.h:436:7: note: a different type is defined in another translation unit
    class MPU6050 {
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.h:1036:18: note: the first difference of corresponding definitions is field 'dmpPacketBuffer'
    uint8_t *dmpPacketBuffer;
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.h:436:7: note: a type with different number of fields is defined in another translation unit
    class MPU6050 {
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.h:440:14: warning: 'initialize' violates the C++ One Definition Rule [-Wodr]
    void initialize();
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.cpp:56:6: note: implicit this pointer type mismatch
    void MPU6050::initialize() {
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.h:436:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
    class MPU6050 {
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.cpp:56:6: note: 'initialize' was previously declared here
    void MPU6050::initialize() {
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.cpp:56:6: note: code may be misoptimized unless -fno-strict-aliasing is used
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.h:441:14: warning: 'testConnection' violates the C++ One Definition Rule [-Wodr]
    bool testConnection();
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.cpp:67:6: note: implicit this pointer type mismatch
    bool MPU6050::testConnection() {
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.h:436:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
    class MPU6050 {
    ^
    /Users/ramakrishnanmanoharan/Documents/Arduino/libraries/MPU6050/MPU6050.cpp:67:6: note: 'testConnection' was previously declared here
    bool MPU6050::testConnection() {

Do you think that it would be helpful to see the code that you are compiling and a link to the libraries that you are #including ?

Hi ,

The code is here. I have done the exact steps in fact.

he code is here

It would be better if it were here

See Read this before posting a programming question and follow the instructions regarding posting code and error messages

I have pasted the code here. Am a newbie in Arduino coding. just doing few small scale projects.

#include "I2Cdev.h"
#include <PID_v1.h> //From https://github.com/br3ttb/Arduino-PID-Library/blob/master/PID_v1.h
#include "MPU6050_6Axis_MotionApps20.h" //https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050

MPU6050 mpu;

// MPU control/status vars
bool dmpReady = false;  // set true if DMP init was successful
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

// orientation/motion vars
Quaternion q;           // [w, x, y, z]         quaternion container
VectorFloat gravity;    // [x, y, z]            gravity vector
float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

/*********Tune these 4 values for your BOT*********/
double setpoint= 176; //set the value when the bot is perpendicular to ground using serial monitor. 
//Read the project documentation on circuitdigest.com to learn how to set these values
double Kp = 21; //Set this first
double Kd = 0.8; //Set this secound
double Ki = 140; //Finally set this 
/******End of values setting*********/

double input, output;
PID pid(&input, &output, &setpoint, Kp, Ki, Kd, DIRECT);

volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
void dmpDataReady()
{
    mpuInterrupt = true;
}

void setup() {
  Serial.begin(115200);

  // initialize device
    Serial.println(F("Initializing I2C devices..."));
    mpu.initialize();

     // verify connection
    Serial.println(F("Testing device connections..."));
    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

    // load and configure the DMP
    devStatus = mpu.dmpInitialize();

    
    // supply your own gyro offsets here, scaled for min sensitivity
    mpu.setXGyroOffset(220);
    mpu.setYGyroOffset(76);
    mpu.setZGyroOffset(-85);
    mpu.setZAccelOffset(1688); 

      // make sure it worked (returns 0 if so)
    if (devStatus == 0)
    {
        // turn on the DMP, now that it's ready
        Serial.println(F("Enabling DMP..."));
        mpu.setDMPEnabled(true);

        // enable Arduino interrupt detection
        Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
        attachInterrupt(0, dmpDataReady, RISING);
        mpuIntStatus = mpu.getIntStatus();

        // set our DMP Ready flag so the main loop() function knows it's okay to use it
        Serial.println(F("DMP ready! Waiting for first interrupt..."));
        dmpReady = true;

        // get expected DMP packet size for later comparison
        packetSize = mpu.dmpGetFIFOPacketSize();
        
        //setup PID
        pid.SetMode(AUTOMATIC);
        pid.SetSampleTime(10);
        pid.SetOutputLimits(-255, 255);  
    }
    else
    {
        // ERROR!
        // 1 = initial memory load failed
        // 2 = DMP configuration updates failed
        // (if it's going to break, usually the code will be 1)
        Serial.print(F("DMP Initialization failed (code "));
        Serial.print(devStatus);
        Serial.println(F(")"));
    }

//Initialise the Motor outpu pins
    pinMode (6, OUTPUT);
    pinMode (9, OUTPUT);
    pinMode (10, OUTPUT);
    pinMode (11, OUTPUT);

//By default turn off both the motors
    analogWrite(6,LOW);
    analogWrite(9,LOW);
    analogWrite(10,LOW);
    analogWrite(11,LOW);
}

void loop() {
 
    // if programming failed, don't try to do anything
    if (!dmpReady) return;

    // wait for MPU interrupt or extra packet(s) available
    while (!mpuInterrupt && fifoCount < packetSize)
    {
        //no mpu data - performing PID calculations and output to motors     
        pid.Compute();   
        
        //Print the value of Input and Output on serial monitor to check how it is working.
        Serial.print(input); Serial.print(" =>"); Serial.println(output);
               
        if (input>150 && input<200){//If the Bot is falling 
          
        if (output>0) //Falling towards front 
        Forward(); //Rotate the wheels forward 
        else if (output<0) //Falling towards back
        Reverse(); //Rotate the wheels backward 
        }
        else //If Bot not falling
        Stop(); //Hold the wheels still
        
    }

    // reset interrupt flag and get INT_STATUS byte
    mpuInterrupt = false;
    mpuIntStatus = mpu.getIntStatus();

    // get current FIFO count
    fifoCount = mpu.getFIFOCount();

    // check for overflow (this should never happen unless our code is too inefficient)
    if ((mpuIntStatus & 0x10) || fifoCount == 1024)
    {
        // reset so we can continue cleanly
        mpu.resetFIFO();
        Serial.println(F("FIFO overflow!"));

    // otherwise, check for DMP data ready interrupt (this should happen frequently)
    }
    else if (mpuIntStatus & 0x02)
    {
        // wait for correct available data length, should be a VERY short wait
        while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

        // read a packet from FIFO
        mpu.getFIFOBytes(fifoBuffer, packetSize);
        
        // track FIFO count here in case there is > 1 packet available
        // (this lets us immediately read more without waiting for an interrupt)
        fifoCount -= packetSize;

        mpu.dmpGetQuaternion(&q, fifoBuffer); //get value for q
        mpu.dmpGetGravity(&gravity, &q); //get value for gravity
        mpu.dmpGetYawPitchRoll(ypr, &q, &gravity); //get value for ypr

        input = ypr[1] * 180/M_PI + 180;

   }
}

void Forward() //Code to rotate the wheel forward 
{
    analogWrite(6,output);
    analogWrite(9,0);
    analogWrite(10,output);
    analogWrite(11,0);
    Serial.print("F"); //Debugging information 
}

void Reverse() //Code to rotate the wheel Backward  
{
    analogWrite(6,0);
    analogWrite(9,output*-1);
    analogWrite(10,0);
    analogWrite(11,output*-1); 
    Serial.print("R");
}

void Stop() //Code to stop both the wheels
{
    analogWrite(6,0);
    analogWrite(9,0);
    analogWrite(10,0);
    analogWrite(11,0); 
    Serial.print("S");
}

If you read the thread that I linked to them you should know how to post code properly

Please edit your post and at least add code tags to make it easier to copy for examination in an editor

done... I did search for a "code" decorator. didn't realize i had to manually do that. sorry