uint8_t MPU6050_Init(uint8_t slave_addr)
{
uint8_t result;
Wire.setClock(400000);
Wire.begin();
// initialize device
Serial.println("Initializing MPU6050...");
mpu.initialize();
// verify connection
result = mpu.testConnection();
if (result)
Serial.println("Connection successful");
else
{
Serial.println("Connection failed");
return result;
}
// load and configure the DMP
Serial.println("Initializing DMP...");
result = mpu.dmpInitialize();
//At this point I get
// X Accel Y Accel Z Accel X Gyro Y Gyro Z Gyro
//OFFSETS -3484, -5361, 768, 33, -36, 31
// supply your own gyro offsets here, scaled for min sensitivity
mpu.setXGyroOffset(33);
mpu.setYGyroOffset(-36);
mpu.setZGyroOffset(-31);
mpu.setXAccelOffset(-3484);
mpu.setYAccelOffset(-5361);
mpu.setZAccelOffset(768); // 1688 factory default for my test chip
// make sure it worked (returns 0 if so)
if (result == 0)
{
// Calibration Time: generate offsets and calibrate our MPU6050
mpu.CalibrateAccel(6);
mpu.CalibrateGyro(6);
mpu.PrintActiveOffsets();
// turn on the DMP, now that it's ready
Serial.println("Enabling DMP...");
mpu.setDMPEnabled(true);
result = mpu.getIntStatus();
// set our DMP Ready flag so the main loop() function knows it's okay to use it
Serial.println("DMP ready! Waiting for first interrupt...");
dmpReady = true;
// get expected DMP packet size for later comparison
packetSize = mpu.dmpGetFIFOPacketSize();
}
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("DMP Initialization failed (code ");
Serial.print(result);
Serial.println(")");
}
return result;
}
I get
Initializing MPU6050...
Connection successful
Initializing DMP...
>*......>......
// X Accel Y Accel Z Accel X Gyro Y Gyro Z Gyro
//OFFSETS -3716, -4157, 3056, 35, -40, 32
Enabling DMP...
DMP ready! Waiting for first interrupt...
So I suppose it's OK.
Then I try to read
float MPU6050_Read(uint8_t val_type)
{
float value;
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
Serial.print("X: ");
Serial.print(aaReal.x);
Serial.print(" Y: ");
Serial.print(aaReal.y);
Serial.print(" Z: ");
Serial.println(aaReal.z);
return value;
}
Get all zeroes
X: 0 Y: 0 Z: 0
What can be a problem?