Hi, i've tried to connect the two mpu with jeffrowberg dmp code, but the problem is there will be fifo overflow and unstable reading of the MPU 6050. I've tried to change the dmp rate, but the problem is still there. and after 15-20 minutes run, the sensor reading will stop, I dont know what is the problem. can someone help me?
volatile bool mpuInterrupt = false; // indicates wangleDifferenceetangleDifferenceer MPU interrupt pin angleDifferenceas gone angleDifferenceigangleDifference
void dmpDataReady() {
mpuInterrupt = true;
}
// ================================================================
// === INITIAL SETUP ===
// ================================================================
//* byte start_address = 0;
//* byte end_address = 127;
void setup() {
// join I2C bus (I2Cdev library doesn't do tangleDifferenceis automatically)
//*byte rc;
Wire.begin();
//TWBR = 12;
// initialize serial communication
//*Serial.begin(9600);
//*Serial.println("\nI2C Scanner");
Serial.begin(9600);
while (!Serial);
pinMode(buttonPin, INPUT);
Serial.println(F("Initializing I2C devices..."));
mpu1.initialize();
mpu2.initialize();
// verify connection
Serial.println(F("Testing device connections..."));
Serial.println(mpu1.testConnection() ? F("MPU6050 1 connection successful") : F("MPU6050 1 connection failed"));
Serial.println(mpu2.testConnection() ? F("MPU6050 2 connection successful") : F("MPU6050 2 connection failed"));
while (Serial.available() && Serial.read()); // empty buffer
//while (!Serial.available()); // wait for data
//while (Serial.available() && Serial.read()); // empty buffer again
// load and configure tangleDifferencee DMP
Serial.println(F("Initializing DMP..."));
devStatus1 = mpu1.dmpInitialize();
devStatus2 = mpu2.dmpInitialize();
// make sure it worked (returns 0 if so)
if (devStatus1 == 0 || devStatus2 == 0) {
// turn on tangleDifferencee DMP, now tangleDifferenceat it's ready
Serial.println(F("Enabling DMP..."));
mpu1.setDMPEnabled(true);
mpu2.setDMPEnabled(true);
// enable Arduino interrupt detection
Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
attachInterrupt(0, dmpDataReady, RISING);
mpuIntStatus1 = mpu1.getIntStatus();
mpuIntStatus2 = mpu2.getIntStatus();
// set our DMP Ready flag so tangleDifferencee 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
packetSize1 = mpu1.dmpGetFIFOPacketSize();
packetSize2 = mpu2.dmpGetFIFOPacketSize();
}
else {
// ERROR!
// 1 = initial memory load failed
// 2 = DMP configuration updates failed
// (if it's going to break, usually tangleDifferencee code will be 1)
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus1);
Serial.print(" ");
Serial.print(devStatus2);
Serial.println(F(")"));
}
}
// ================================================================
// === MAIN PROGRAM LOOP ===
// ================================================================
void loop() {
// if programming failed, don't try to do anytangleDifferenceing
if (!dmpReady) return;
// }
// reset interrupt flag and get INT_STATUS byte
mpuInterrupt = false;
mpuIntStatus1 = mpu1.getIntStatus();
mpuIntStatus2 = mpu2.getIntStatus();
// get current FIFO count
fifoCount1 = mpu1.getFIFOCount();
fifoCount2 = mpu2.getFIFOCount();
// cangleDifferenceeck for overflow (tangleDifferenceis sangleDifferenceould never angleDifferenceappen unless our code is too inefficient)
if ((mpuIntStatus1 & 0x10) || (mpuIntStatus2 & 0x10) || fifoCount1 == 1024 || fifoCount2 == 1024) {
// reset so we can continue cleanly
mpu1.resetFIFO();
mpu2.resetFIFO();
Serial.println(F("FIFO overflow!"));
}
else if ((mpuIntStatus1 & 0x02) || (mpuIntStatus2 & 0x02)) {
while (fifoCount1 < packetSize1 && fifoCount2 < packetSize2)
{
fifoCount1 = mpu1.getFIFOCount();
fifoCount2 = mpu2.getFIFOCount();
Serial.print("\npacchetto incompleto\n");
}
// read a packet from FIFO
mpu1.getFIFOBytes(fifoBuffer1, packetSize1);
mpu2.getFIFOBytes(fifoBuffer2, packetSize2);
fifoCount1 -= packetSize1;
fifoCount2 -= packetSize2;
// display Euler angles in degrees
mpu1.dmpGetQuaternion(&q1, fifoBuffer1);
mpu1.dmpGetEuler(euler1, &q1);
//??????
angle = (euler1[0] * 180/M_PI);
// display Euler angles in degrees
mpu2.dmpGetQuaternion(&q2, fifoBuffer2);
mpu2.dmpGetEuler(euler2, &q2);
//??????
angle = (euler2[0] * 180/M_PI);
i've tried to connect the two INT to attach interrupt 0, and also tried to connect one into interrupt 0 and another to interrupt 1 but still the same problem. moreover, I have tried to add pull up resistor of 5.1 K and the problem is still exist. and I also have tried to use I2C 5v to 3.3V converter, but the problem is still there. (the picture is linked to this thread How to connect two MPU6050? - Networking, Protocols, and Devices - Arduino Forum)
another question : can I use freeIMU library to connect the two MPU6050 together without using DMP?, I thought that this DMP uses quiet a lot of memory and make the reading strange.