"Class MPU6050' has no member named 'begin'n" error

Hi everyone, i'm working on a project about MPU6050 and Kalman Filter. I wanna simulate it so i used the code on /dev/jarzebski: Odczyty Pitch & Roll oraz filtr Kalmana, here the code:

#include <Wire.h>
#include <MPU6050.h>
#include <KalmanFilter.h>

MPU6050 mpu;

KalmanFilter kalmanX(0.001, 0.003, 0.03);
KalmanFilter kalmanY(0.001, 0.003, 0.03);

float accPitch = 0;
float accRoll = 0;

float kalPitch = 0;
float kalRoll = 0;

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

  // Initialize MPU6050
  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    delay(500);
  }
 
  // Calibrate gyroscope. The calibration must be at rest.
  // If you don't want calibrate, comment this line.
  mpu.calibrateGyro();
}

void loop()
{
  Vector acc = mpu.readNormalizeAccel();
  Vector gyr = mpu.readNormalizeGyro();

  // Calculate Pitch & Roll from accelerometer (deg)
  accPitch = -(atan2(acc.XAxis, sqrt(acc.YAxis*acc.YAxis + acc.ZAxis*acc.ZAxis))*180.0)/M_PI;
  accRoll  = (atan2(acc.YAxis, acc.ZAxis)*180.0)/M_PI;

  // Kalman filter
  kalPitch = kalmanY.update(accPitch, gyr.YAxis);
  kalRoll = kalmanX.update(accRoll, gyr.XAxis);

  Serial.print(accPitch);
  Serial.print(":");
  Serial.print(accRoll);
  Serial.print(":");
  Serial.print(kalPitch);
  Serial.print(":");
  Serial.print(kalRoll);
  Serial.print(":");
  Serial.print(acc.XAxis);
  Serial.print(":");
  Serial.print(acc.YAxis);
  Serial.print(":");
  Serial.print(acc.ZAxis);
  Serial.print(":");
  Serial.print(gyr.XAxis);
  Serial.print(":");
  Serial.print(gyr.YAxis);
  Serial.print(":");
  Serial.print(gyr.ZAxis);

  Serial.println();
}

Then i'm facing this error:

C:\Users\Hung\Documents\Arduino\libraries\Arduino-KalmanFilter-master\KalmanFilter_MPU6050\KalmanFilter_MPU6050.ino: In function 'void setup()':

KalmanFilter_MPU6050:30: error: 'class MPU6050' has no member named 'begin'

   while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))

              ^

KalmanFilter_MPU6050:30: error: 'MPU6050_SCALE_2000DPS' was not declared in this scope

   while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))

                    ^

KalmanFilter_MPU6050:30: error: 'MPU6050_RANGE_2G' was not declared in this scope

   while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))

                                           ^

KalmanFilter_MPU6050:37: error: 'class MPU6050' has no member named 'calibrateGyro'

   mpu.calibrateGyro();

       ^

C:\Users\Hung\Documents\Arduino\libraries\Arduino-KalmanFilter-master\KalmanFilter_MPU6050\KalmanFilter_MPU6050.ino: In function 'void loop()':

KalmanFilter_MPU6050:42: error: 'Vector' was not declared in this scope

   Vector acc = mpu.readNormalizeAccel();

   ^

KalmanFilter_MPU6050:43: error: expected ';' before 'gyr'

   Vector gyr = mpu.readNormalizeGyro();

          ^

KalmanFilter_MPU6050:46: error: 'acc' was not declared in this scope

   accPitch = -(atan2(acc.XAxis, sqrt(acc.YAxis*acc.YAxis + acc.ZAxis*acc.ZAxis))*180.0)/M_PI;

                      ^

KalmanFilter_MPU6050:50: error: 'gyr' was not declared in this scope

   kalPitch = kalmanY.update(accPitch, gyr.YAxis);

                                       ^

Multiple libraries were found for "MPU6050.h"
 Used: E:\Apphotro\arduino-1.8.2\libraries\MPU6050
 Not used: C:\Users\Hung\Documents\Arduino\libraries\Arduino-MPU6050-master
exit status 1
'class MPU6050' has no member named 'begin'

I really don't know what to do, so anyone can solve this error, please help me, this very important in my project.
Thank you all, thanks very much! :smiley: :smiley: :smiley:

  // Initialize MPU6050
  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    delay(500);
  }

I assume that you copied this portion of code from somewhere. Was it from an example that worked ?

How is the MPU6050 connected to the Arduino ?

I coppied all of the code from that website and didn't change anything, then i connect MPU6050 and like this:

Where did you get the libraries from ?

I got it from here bro:

mrcrocodileee1995:
I got it from here bro:
GitHub - jarzebski/Arduino-KalmanFilter: Kalman Filter for Arduino

And the MPU6050 library ?

MPU6050 i got from here, and already added:

im sure you figured it out by now if not you have to delete all other mpu6050 libraries and download GitHub - jarzebski/Arduino-MPU6050: MPU6050 Triple Axis Gyroscope & Accelerometer Arduino Library using Google Chrome/open arduino/sketch/include library/ add zip library. it took me foooooooorrrrr ever to figure it out also but finally got it to work.

2 Likes