user37011: I am working on creating a motion sensor based on an Arduino and MPU6050 interface. I'd like to retorfit my code to be able to read 2 mpu6050 devices. Besides defining a 0x69 address and setting AD0 to high on one and AD0 to low on the other, what additional changes to I need to make to my code? I posted my original code below. Thanks in advance!
//Basic code to setup and read raw values from mpu6050
//matt_m 7-9-2017


#include <Wire.h>

//Registers: Accelerometer, Temp, Gyroscope
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48

#define PWR_MGMT_1 0x6B
#define PWR_MGMT_2 0x6C

#define MPU6050 0x68 //Device address
#define ACCEL_CONFIG 0x1C //Accelerometer configuration address
#define GYRO_CONFIG 0x1B //Gyro configuration address




//Sensor output scaling
#define accSens 0 // 0 = 2g, 1 = 4g, 2 = 8g, 3 = 16g
#define gyroSens 1 // 0 = 250rad/s, 1 = 500rad/s, 2 1000rad/s, 3 = 2000rad/s


int16_t  AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;

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

void loop() {
  read_mpu6050();
  Serial.println(AcX);  //value to display
}

//setup MPU6050
void angle_setup()
{
  Wire.begin();
  delay (100);
  writeTo(MPU6050, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU6050, ACCEL_CONFIG, accSens << 3); // Specifying output scaling 
  of accelerometer
  writeTo(MPU6050, GYRO_CONFIG, gyroSens << 3); // Specifying output scaling 
  of gyroscope
  delay (100);
}

void read_mpu6050()
{
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU6050);
  Wire.write(0x3B);                  // starting with register 0x3B 
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050, 14, true);  // request a total of 14 registers
  AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C 
(ACCEL_XOUT_L)
  AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E 
(ACCEL_YOUT_L)
  AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 
(ACCEL_ZOUT_L)
  Tmp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 
(TEMP_OUT_L)
  GyX = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 
(GYRO_XOUT_L)
  GyY = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 
(GYRO_YOUT_L)
  GyZ = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 
(GYRO_ZOUT_L)
}

void writeTo(byte device, byte toAddress, byte val) {
  Wire.beginTransmission(device);  
  Wire.write(toAddress);        
  Wire.write(val);        
  Wire.endTransmission();
 }

*edit: This below is the code with my best guess of how to implement 2 sensors, alas, my the output on my serial monitor keeps spitting out erraneous -1s and 0s
#include <Wire.h>

//Registers: Accelerometer, Temp, Gyroscope
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48

#define PWR_MGMT_1 0x6B
#define PWR_MGMT_2 0x6C


#define MPU60501 0x68 //Device address #1
#define MPU60502 0x69 //Device address #2
#define ACCEL_CONFIG 0x1C //Accelerometer configuration address
#define GYRO_CONFIG 0x1B //Gyro configuration address




//Sensor output scaling
#define accSens 0 // 0 = 2g, 1 = 4g, 2 = 8g, 3 = 16g
#define gyroSens 1 // 0 = 250rad/s, 1 = 500rad/s, 2 1000rad/s, 3 = 2000rad/s


int16_t  AcX1, AcY1, AcZ1, Tmp1, GyX1, GyY1, GyZ1;
int16_t  AcX2, AcY2, AcZ2, Tmp2, GyX2, GyY2, GyZ2;
void setup() {
 pinMode(0, OUTPUT);
 digitalWrite(0, HIGH);
 pinMode(1, OUTPUT);
 digitalWrite(1,LOW);
 Serial.begin(115200);
 angle_setup1();
 angle_setup2();
}

void loop() {
  read_mpu60501();
  Serial.println(AcX1);  //value to display
  read_mpu60502();
  Serial.println(AcX2);  //value to display


}

//setup MPU60501
void angle_setup1()
{
  Wire.begin();
  delay (100);
  writeTo(MPU60501, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU60501, ACCEL_CONFIG, accSens << 3); // Specifying output 
scaling of accelerometer
  writeTo(MPU60501, GYRO_CONFIG, gyroSens << 3); // Specifying output 
scaling of gyroscope
  delay (100);
}

void read_mpu60501()
{
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU60501);
  Wire.write(0x3B);                  // starting with register 0x3B 
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU60501, 14, true);  // request a total of 14 registers
  AcX1 = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C 
(ACCEL_XOUT_L)
  AcY1 = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E 
(ACCEL_YOUT_L)
  AcZ1 = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 
(ACCEL_ZOUT_L)
  Tmp1 = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 
(TEMP_OUT_L)
  GyX1 = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 
(GYRO_XOUT_L)
  GyY1 = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 
(GYRO_YOUT_L)
  GyZ1 = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 
(GYRO_ZOUT_L)
}

//setup MPU60502
void angle_setup2()
{
  Wire.begin();
  delay (100);
  writeTo(MPU60502, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU60502, ACCEL_CONFIG, accSens << 3); // Specifying output 
scaling of accelerometer
  writeTo(MPU60502, GYRO_CONFIG, gyroSens << 3); // Specifying output 
scaling of gyroscope
  delay (100);
 }
void read_mpu60502()
 {
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU60502);
  Wire.write(0x3B);                  // starting with register 0x3B 
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU60502, 14, true);  // request a total of 14 registers
  AcX2 = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C 
(ACCEL_XOUT_L)
  AcY2 = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E 
(ACCEL_YOUT_L)
  AcZ2 = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 
(ACCEL_ZOUT_L)
  Tmp2 = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 
(TEMP_OUT_L)
  GyX2 = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 
(GYRO_XOUT_L)
  GyY2 = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 
(GYRO_YOUT_L)
  GyZ2 = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 
(GYRO_ZOUT_L)
}

void writeTo(byte device, byte toAddress, byte val) {
  Wire.beginTransmission(device);  
  Wire.write(toAddress);        
  Wire.write(val);        
  Wire.endTransmission();
}

`

user10394: When ever you start looking at multiples of an object you should think of classes and structures to do things.
If you wrote a class:
class MPU6050
{
public:
    // Class constructor
    MPU6050 (const byte& address = 0x68)
      :m_Address(address)
    {
    }

    // Class destructor
    ~MPU6050()
    {}

    //setup MPU60501
    void angle_setup (void)
    {
      // Wire.begin();              // This should be called in main setup.
      delay (100);
      writeTo(MPU60501, PWR_MGMT_1, 0); //wakeup from sleep
      writeTo(MPU60501, ACCEL_CONFIG, accSens << 3); // Specifying output scaling of accelerometer
      writeTo(MPU60501, GYRO_CONFIG, gyroSens << 3); // Specifying output scaling of gyroscope
      delay (100);
    }

    void read_mpu6050(void)
    {
      // read raw accel/gyro measurements from device
      Wire.beginTransmission(MPU60501);
      Wire.write(0x3B);                  // starting with register 0x3B (ACCEL_XOUT_H)
      Wire.endTransmission(false);
      Wire.requestFrom(MPU60501, 14, true);  // request a total of 14 registers
      AcX1 = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
      AcY1 = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
      AcZ1 = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
      Tmp1 = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
      GyX1 = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44(GYRO_XOUT_L)
      GyY1 = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46   (GYRO_YOUT_L)
      GyZ1 = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48   (GYRO_ZOUT_L)
    }

    // Data member that could be private and have access functions, but...
    int16_t     AcX1;
    int16_t     AcY1;
    int16_t     AcZ1;
    int16_t     Tmp1;
    int16_t     GyX1;
    int16_t     GyY1;
    int16_t     GyZ1;

private:
    byte m_Address;
};

You could then have any number of sensors by going:
MPU6050  SensorOne;  // Address is optional and defaults to 68.
MPU6050  SensorTwo (0x69);

To access the data or functions in them:
SensorOne.angle_setup();
Serial.println(SensorOne.AcX1);

You could put the sensor in an array and then use loops everywhere, but there isn't much of a saving for two instances.

37011: <p>I am working on creating a motion sensor based on an Arduino and MPU6050 interface. I'd like to retorfit my code to be able to read 2 mpu6050 devices. Besides defining a 0x69 address and setting AD0 to high on one and AD0 to low on the other, what additional changes to I need to make to my code? I posted my original code below. Thanks in advance!</p>

<pre><code>//Basic code to setup and read raw values from mpu6050
//matt_m 7-9-2017


#include &lt;Wire.h&gt;

//Registers: Accelerometer, Temp, Gyroscope
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48

#define PWR_MGMT_1 0x6B
#define PWR_MGMT_2 0x6C

#define MPU6050 0x68 //Device address
#define ACCEL_CONFIG 0x1C //Accelerometer configuration address
#define GYRO_CONFIG 0x1B //Gyro configuration address




//Sensor output scaling
#define accSens 0 // 0 = 2g, 1 = 4g, 2 = 8g, 3 = 16g
#define gyroSens 1 // 0 = 250rad/s, 1 = 500rad/s, 2 1000rad/s, 3 = 2000rad/s


int16_t  AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;

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

void loop() {
  read_mpu6050();
  Serial.println(AcX);  //value to display
}

//setup MPU6050
void angle_setup()
{
  Wire.begin();
  delay (100);
  writeTo(MPU6050, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU6050, ACCEL_CONFIG, accSens &lt;&lt; 3); // Specifying output scaling 
  of accelerometer
  writeTo(MPU6050, GYRO_CONFIG, gyroSens &lt;&lt; 3); // Specifying output scaling 
  of gyroscope
  delay (100);
}

void read_mpu6050()
{
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU6050);
  Wire.write(0x3B);                  // starting with register 0x3B 
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050, 14, true);  // request a total of 14 registers
  AcX = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) &amp; 0x3C 
(ACCEL_XOUT_L)
  AcY = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) &amp; 0x3E 
(ACCEL_YOUT_L)
  AcZ = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) &amp; 0x40 
(ACCEL_ZOUT_L)
  Tmp = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x41 (TEMP_OUT_H) &amp; 0x42 
(TEMP_OUT_L)
  GyX = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) &amp; 0x44 
(GYRO_XOUT_L)
  GyY = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) &amp; 0x46 
(GYRO_YOUT_L)
  GyZ = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) &amp; 0x48 
(GYRO_ZOUT_L)
}

void writeTo(byte device, byte toAddress, byte val) {
  Wire.beginTransmission(device);  
  Wire.write(toAddress);        
  Wire.write(val);        
  Wire.endTransmission();
 }
</code></pre>

<p>*edit: This below is the code with my best guess of how to implement 2 sensors, alas, my the output on my serial monitor keeps spitting out erraneous -1s and 0s</p>

<pre><code>#include &lt;Wire.h&gt;

//Registers: Accelerometer, Temp, Gyroscope
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48

#define PWR_MGMT_1 0x6B
#define PWR_MGMT_2 0x6C


#define MPU60501 0x68 //Device address #1
#define MPU60502 0x69 //Device address #2
#define ACCEL_CONFIG 0x1C //Accelerometer configuration address
#define GYRO_CONFIG 0x1B //Gyro configuration address




//Sensor output scaling
#define accSens 0 // 0 = 2g, 1 = 4g, 2 = 8g, 3 = 16g
#define gyroSens 1 // 0 = 250rad/s, 1 = 500rad/s, 2 1000rad/s, 3 = 2000rad/s


int16_t  AcX1, AcY1, AcZ1, Tmp1, GyX1, GyY1, GyZ1;
int16_t  AcX2, AcY2, AcZ2, Tmp2, GyX2, GyY2, GyZ2;
void setup() {
 pinMode(0, OUTPUT);
 digitalWrite(0, HIGH);
 pinMode(1, OUTPUT);
 digitalWrite(1,LOW);
 Serial.begin(115200);
 angle_setup1();
 angle_setup2();
}

void loop() {
  read_mpu60501();
  Serial.println(AcX1);  //value to display
  read_mpu60502();
  Serial.println(AcX2);  //value to display


}

//setup MPU60501
void angle_setup1()
{
  Wire.begin();
  delay (100);
  writeTo(MPU60501, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU60501, ACCEL_CONFIG, accSens &lt;&lt; 3); // Specifying output 
scaling of accelerometer
  writeTo(MPU60501, GYRO_CONFIG, gyroSens &lt;&lt; 3); // Specifying output 
scaling of gyroscope
  delay (100);
}

void read_mpu60501()
{
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU60501);
  Wire.write(0x3B);                  // starting with register 0x3B 
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU60501, 14, true);  // request a total of 14 registers
  AcX1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) &amp; 0x3C 
(ACCEL_XOUT_L)
  AcY1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) &amp; 0x3E 
(ACCEL_YOUT_L)
  AcZ1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) &amp; 0x40 
(ACCEL_ZOUT_L)
  Tmp1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x41 (TEMP_OUT_H) &amp; 0x42 
(TEMP_OUT_L)
  GyX1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) &amp; 0x44 
(GYRO_XOUT_L)
  GyY1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) &amp; 0x46 
(GYRO_YOUT_L)
  GyZ1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) &amp; 0x48 
(GYRO_ZOUT_L)
}

//setup MPU60502
void angle_setup2()
{
  Wire.begin();
  delay (100);
  writeTo(MPU60502, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU60502, ACCEL_CONFIG, accSens &lt;&lt; 3); // Specifying output 
scaling of accelerometer
  writeTo(MPU60502, GYRO_CONFIG, gyroSens &lt;&lt; 3); // Specifying output 
scaling of gyroscope
  delay (100);
 }
void read_mpu60502()
 {
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU60502);
  Wire.write(0x3B);                  // starting with register 0x3B 
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU60502, 14, true);  // request a total of 14 registers
  AcX2 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) &amp; 0x3C 
(ACCEL_XOUT_L)
  AcY2 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) &amp; 0x3E 
(ACCEL_YOUT_L)
  AcZ2 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) &amp; 0x40 
(ACCEL_ZOUT_L)
  Tmp2 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x41 (TEMP_OUT_H) &amp; 0x42 
(TEMP_OUT_L)
  GyX2 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) &amp; 0x44 
(GYRO_XOUT_L)
  GyY2 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) &amp; 0x46 
(GYRO_YOUT_L)
  GyZ2 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) &amp; 0x48 
(GYRO_ZOUT_L)
}

void writeTo(byte device, byte toAddress, byte val) {
  Wire.beginTransmission(device);  
  Wire.write(toAddress);        
  Wire.write(val);        
  Wire.endTransmission();
}
</code></pre>

<p>`</p>
 10394: <p>When ever you start looking at multiples of an object you should think of classes and structures to do things.</p>

<p>If you wrote a class:</p>

<pre><code>class MPU6050
{
public:
    // Class constructor
    MPU6050 (const byte&amp; address = 0x68)
      :m_Address(address)
    {
    }

    // Class destructor
    ~MPU6050()
    {}

    //setup MPU60501
    void angle_setup (void)
    {
      // Wire.begin();              // This should be called in main setup.
      delay (100);
      writeTo(MPU60501, PWR_MGMT_1, 0); //wakeup from sleep
      writeTo(MPU60501, ACCEL_CONFIG, accSens &lt;&lt; 3); // Specifying output scaling of accelerometer
      writeTo(MPU60501, GYRO_CONFIG, gyroSens &lt;&lt; 3); // Specifying output scaling of gyroscope
      delay (100);
    }

    void read_mpu6050(void)
    {
      // read raw accel/gyro measurements from device
      Wire.beginTransmission(MPU60501);
      Wire.write(0x3B);                  // starting with register 0x3B (ACCEL_XOUT_H)
      Wire.endTransmission(false);
      Wire.requestFrom(MPU60501, 14, true);  // request a total of 14 registers
      AcX1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) &amp; 0x3C (ACCEL_XOUT_L)
      AcY1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) &amp; 0x3E (ACCEL_YOUT_L)
      AcZ1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) &amp; 0x40 (ACCEL_ZOUT_L)
      Tmp1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x41 (TEMP_OUT_H) &amp; 0x42 (TEMP_OUT_L)
      GyX1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) &amp; 0x44(GYRO_XOUT_L)
      GyY1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) &amp; 0x46   (GYRO_YOUT_L)
      GyZ1 = Wire.read() &lt;&lt; 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) &amp; 0x48   (GYRO_ZOUT_L)
    }

    // Data member that could be private and have access functions, but...
    int16_t     AcX1;
    int16_t     AcY1;
    int16_t     AcZ1;
    int16_t     Tmp1;
    int16_t     GyX1;
    int16_t     GyY1;
    int16_t     GyZ1;

private:
    byte m_Address;
};
</code></pre>

<p>You could then have any number of sensors by going:</p>

<pre><code>MPU6050  SensorOne;  // Address is optional and defaults to 68.
MPU6050  SensorTwo (0x69);
</code></pre>

<p>To access the data or functions in them:</p>

<pre><code>SensorOne.angle_setup();
Serial.println(SensorOne.AcX1);
</code></pre>

<p>You could put the sensor in an array and then use loops everywhere, but there isn't much of a saving for two instances.</p>
