title: Connecting four MPU-6050s with Arduino Due on I2C
body: <p>I have four MPU-6050 (<a href="http://playground.arduino.cc/Main/MPU-6050" rel="nofollow">http://playground.arduino.cc/Main/MPU-6050</a>) IMU's connected to my Arduino Due via the two I2C buses. </p>
  
  <p>I only want to read accelerometer data but my code to simply read the raw data  doesn't seem to be working. Does anyone have any ideas what could be wrong?</p>
  
  <p>Here's a picture of how I connected my four MPU-6050 to the Arduino: <a href="http://i.imgur.com/UaWP2LP.jpg" rel="nofollow">http://i.imgur.com/UaWP2LP.jpg</a></p>
  
  <p>Here's my code:</p>
  
  <pre><code>// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
  // is used in I2Cdev.h
  #include "Wire.h"
  
  // I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
  // for both classes must be in the include path of your project
  #include "I2Cdev.h"
  #include "MPU6050.h"
  
  // class default I2C address is 0x68
  // specific I2C addresses may be passed as a parameter here
  // AD0 low = 0x68 (default for InvenSense evaluation board)
  // AD0 high = 0x69
  MPU6050 accel_i2c_68(MPU6050_ADDRESS_AD0_LOW);
  MPU6050 accel_i2c_69(MPU6050_ADDRESS_AD0_HIGH);
  MPU6050 accel_i2c1_68(MPU6050_ADDRESS_AD0_LOW);
  MPU6050 accel_i2c1_69(MPU6050_ADDRESS_AD0_HIGH);
  
  // Declare 12 acceleration vars, 3 for each of the four IMU's
  int16_t ax68, ay68, az68, ax69, ay69, az69, ax68_1, ay68_1, az68_1, ax69_1, ay69_1, az69_1;
  
  #define LED_PIN 13
  bool blinkState = false;
  
  void setup() {
      // join both I2C bus on Arduino Due
      Wire.begin();
      Wire1.begin();
  
      // initialize serial communication
      Serial.begin(9600);
  
      // initialize four IMU devices
      Serial.println("Initializing I2C devices...");
      accel_i2c_68.initialize();
      accel_i2c_68.setFullScaleAccelRange(MPU6050_ACCEL_FS_16);
  
      accel_i2c_69.initialize();
      accel_i2c_69.setFullScaleAccelRange(MPU6050_ACCEL_FS_16);
  
      accel_i2c1_68.initialize();
      accel_i2c1_68.setFullScaleAccelRange(MPU6050_ACCEL_FS_16);
  
      accel_i2c1_69.initialize();
      accel_i2c1_69.setFullScaleAccelRange(MPU6050_ACCEL_FS_16);
  
      // verify connection of all four IMU's
      Serial.println("Testing device connections...");
      Serial.println(accel_i2c_68.testConnection() ? "MPU6050 68 connection successful" : "MPU6050 68 connection failed");
      Serial.println(accel_i2c_69.testConnection() ? "MPU6050 69 connection successful" : "MPU6050 69 connection failed");
      Serial.println(accel_i2c1_68.testConnection() ? "MPU6050 1 68 connection successful" : "MPU6050 1 68 connection failed");
      Serial.println(accel_i2c1_69.testConnection() ? "MPU6050 1 69 connection successful" : "MPU6050 1 69 connection failed");
  
      // configure Arduino LED for
      pinMode(LED_PIN, OUTPUT);
  }
  
  void loop() {
  
      // read only acceleration raw data from all four IMU's
      accel_i2c_68.getAcceleration(&amp;ax68, &amp;ay68, &amp;az68);
      accel_i2c_69.getAcceleration(&amp;ax69, &amp;ay69, &amp;az69);
      accel_i2c1_68.getAcceleration(&amp;ax68_1, &amp;ay68_1, &amp;az68_1);
      accel_i2c1_69.getAcceleration(&amp;ax69_1, &amp;ay69_1, &amp;az69_1);
  
      // display tab-separated accel x/y/z values, divide by 2048.0 to get g-force values
      Serial.print("a:\t");
      Serial.print(ax68/2048.0); Serial.print("\t");
      Serial.print(ay68/2048.0); Serial.print("\t");
      Serial.print(az68/2048.0); Serial.print("\t");
      Serial.print(ax69/2048.0); Serial.print("\t");
      Serial.print(ay69/2048.0); Serial.print("\t");
      Serial.print(az69/2048.0); Serial.print("\t");
      Serial.print(ax68_1/2048.0); Serial.print("\t");
      Serial.print(ay68_1/2048.0); Serial.print("\t");
      Serial.print(az68_1/2048.0); Serial.print("\t");
      Serial.print(ax69_1/2048.0); Serial.print("\t");
      Serial.print(ay69_1/2048.0); Serial.print("\t");
      Serial.println(az69_1/2048.0);
  
      // blink LED to indicate activity
      blinkState = !blinkState;
      digitalWrite(LED_PIN, blinkState);
  }
  </code></pre>