Need to add multiple MPU6050 on this code

#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);
bool bPeriodic = false;
int period = 100;
long timer = 0;
long timezero = millis();

void setup() {
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);

Serial.setTimeout(50); //improve responsiveness
Serial.begin(57600);
// note: we delayed the Serial.begin() until now
// to avoid having the mpu6050 setup functions
// sending debug info in a format that
// mcjMPU6050.dsa cant process
// the alternative would be to modify MPU6050_tockn.cpp
// but we prefer not doing that
sendHeaders();
}

void sendHeaders()
{
timezero = millis();
Serial.print( "HEADERS\t" );
Serial.print(millis()-timezero); Serial.print("\t");
Serial.print( "tmpr\t" );
Serial.print( "aclX\t" );
Serial.print( "aclY\t" );
Serial.print( "aclZ\t" );
Serial.print( "gyrX\t" );
Serial.print( "gyrY\t" );
Serial.print( "gyrZ\t" );
Serial.print( "acAX\t" );
Serial.print( "acAY\t" );
Serial.print( "gyAX\t" );
Serial.print( "gyAY\t" );
Serial.print( "gyAZ\t" );
Serial.print( "angX\t" );
Serial.print( "angY\t" );
Serial.print( "angZ\t" );
Serial.print( "eol\n" );
}

void sendSample()
{
Serial.print("DATA"); Serial.print("\t");
Serial.print(millis()-timezero); Serial.print("\t");
Serial.print(mpu6050.getTemp()); Serial.print("\t");
Serial.print(mpu6050.getAccX()); Serial.print("\t");
Serial.print(mpu6050.getAccY()); Serial.print("\t");
Serial.print(mpu6050.getAccZ()); Serial.print("\t");
Serial.print(mpu6050.getGyroX()); Serial.print("\t");
Serial.print(mpu6050.getGyroY()); Serial.print("\t");
Serial.print(mpu6050.getGyroZ()); Serial.print("\t");
Serial.print(mpu6050.getAccAngleX()); Serial.print("\t");
Serial.print(mpu6050.getAccAngleY()); Serial.print("\t");
Serial.print(mpu6050.getGyroAngleX());Serial.print("\t");
Serial.print(mpu6050.getGyroAngleY());Serial.print("\t");
Serial.print(mpu6050.getGyroAngleZ());Serial.print("\t");
Serial.print(mpu6050.getAngleX()); Serial.print("\t");
Serial.print(mpu6050.getAngleY()); Serial.print("\t");
Serial.print(mpu6050.getAngleZ()); Serial.print("\teol\n");
}

void loop() {
mpu6050.update();
if( (millis() - timer > period ) && bPeriodic )
{
sendSample();
timer = millis();
}
else
{
if (Serial.available())
{
//example: "period 33" for 30fps
String str = Serial.readString();
str.replace("\n","");
int pos = str.indexOf( "period" );
if( pos >= 0 )
{
period = str.substring( pos + 6 ).toInt();
Serial.print("ACK"); Serial.print("\t");
Serial.print(millis()-timezero); Serial.print("\t");
Serial.print(str); Serial.print("\teol\n");
}
else if( str.indexOf( "getHeaders" ) >= 0 )
{
sendHeaders();
}
else if( str.indexOf( "getSample" ) >= 0 )
{
sendSample();
}
else if( str.indexOf( "setPeriodic on" ) >= 0 )
{
bPeriodic = true;
Serial.print("ACK"); Serial.print("\t");
Serial.print(millis()-timezero); Serial.print("\t");
Serial.print(str); Serial.print("\teol\n");
}
else if( str.indexOf( "setPeriodic off" ) >= 0 )
{
bPeriodic = false;
Serial.print("ACK"); Serial.print("\t");
Serial.print(millis()-timezero); Serial.print("\t");
Serial.print(str); Serial.print("\teol\n");
}
else
{
Serial.print("NACK"); Serial.print("\t");
Serial.print(millis()-timezero); Serial.print("\t");
Serial.print(str); Serial.print("\teol\n");
}
}
}
}

Do you have a question?

Please remember to use code tags when posting code.

oh my bad!
yes i want to add multiple MPU6050 on this code

#include <MPU6050_tockn.h>
#include <Wire.h>

//mCasualJacques 08/26/2018 5:18PM

MPU6050 mpu6050(Wire);
bool bPeriodic = false;
int period = 100;
long timer = 0;
long timezero = millis();

void setup() {
  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);

  Serial.setTimeout(50); //improve responsiveness
  Serial.begin(57600);
  // note: we delayed the Serial.begin() until now
  // to avoid having the mpu6050 setup functions
  // sending debug info in a format that
  // mcjMPU6050.dsa cant process
  // the alternative would be to modify MPU6050_tockn.cpp
  // but we prefer not doing that
  sendHeaders();
}  

void sendHeaders()
{  
  timezero = millis();
  Serial.print( "HEADERS\t" );
  Serial.print(millis()-timezero);  Serial.print("\t");
  Serial.print( "tmpr\t" );
  Serial.print( "aclX\t" );
  Serial.print( "aclY\t" );
  Serial.print( "aclZ\t" );
  Serial.print( "gyrX\t" );
  Serial.print( "gyrY\t" );
  Serial.print( "gyrZ\t" );
  Serial.print( "acAX\t" );
  Serial.print( "acAY\t" );
  Serial.print( "gyAX\t" );
  Serial.print( "gyAY\t" );
  Serial.print( "gyAZ\t" );
  Serial.print( "angX\t" );
  Serial.print( "angY\t" );
  Serial.print( "angZ\t" );
  Serial.print( "eol\n" );
}

void sendSample()
{
  Serial.print("DATA");                 Serial.print("\t");
  Serial.print(millis()-timezero);      Serial.print("\t");
  Serial.print(mpu6050.getTemp());      Serial.print("\t");
  Serial.print(mpu6050.getAccX());      Serial.print("\t");
  Serial.print(mpu6050.getAccY());      Serial.print("\t");
  Serial.print(mpu6050.getAccZ());      Serial.print("\t");
  Serial.print(mpu6050.getGyroX());     Serial.print("\t");
  Serial.print(mpu6050.getGyroY());     Serial.print("\t");
  Serial.print(mpu6050.getGyroZ());     Serial.print("\t");
  Serial.print(mpu6050.getAccAngleX()); Serial.print("\t");
  Serial.print(mpu6050.getAccAngleY()); Serial.print("\t");
  Serial.print(mpu6050.getGyroAngleX());Serial.print("\t");
  Serial.print(mpu6050.getGyroAngleY());Serial.print("\t");
  Serial.print(mpu6050.getGyroAngleZ());Serial.print("\t");
  Serial.print(mpu6050.getAngleX());    Serial.print("\t");
  Serial.print(mpu6050.getAngleY());    Serial.print("\t");
  Serial.print(mpu6050.getAngleZ());    Serial.print("\teol\n");
}

void loop() {
  mpu6050.update();
  if( (millis() - timer > period ) && bPeriodic ) 
  {
    sendSample();
    timer = millis();
  }
  else
  {
    if (Serial.available()) 
    {
      //example: "period 33" for 30fps
      String str = Serial.readString();
      str.replace("\n","");
      int pos = str.indexOf( "period" ); 
      if( pos >= 0 )
      {
        period = str.substring( pos + 6 ).toInt(); 
        Serial.print("ACK"); Serial.print("\t");
        Serial.print(millis()-timezero); Serial.print("\t");
        Serial.print(str); Serial.print("\teol\n");
      }
      else if( str.indexOf( "getHeaders" ) >= 0 )
      {
        sendHeaders();
      }
      else if( str.indexOf( "getSample" ) >= 0 )
      {
        sendSample();
      }
      else if( str.indexOf( "setPeriodic on" ) >= 0 )
      {
        bPeriodic = true;
        Serial.print("ACK"); Serial.print("\t");
        Serial.print(millis()-timezero); Serial.print("\t");
        Serial.print(str); Serial.print("\teol\n");
      }
      else if( str.indexOf( "setPeriodic off" ) >= 0 )
      {
        bPeriodic = false;
        Serial.print("ACK"); Serial.print("\t");
        Serial.print(millis()-timezero); Serial.print("\t");
        Serial.print(str); Serial.print("\teol\n");
      }
      else
      {
        Serial.print("NACK"); Serial.print("\t");
        Serial.print(millis()-timezero); Serial.print("\t");
        Serial.print(str); Serial.print("\teol\n");
      }
    }
  }
}


Do you have access to the AD0 pin on the 6050?

You're using a silly library that hardcodes a single I2C address (0x68) into its header file. I'd modify the library so that the I2C address is passed as an argument to its constructor or alternatively to the begin() function. Again, it's very silly that the author didn't do it like this in the first place.

Yes i do!

I guess he used headers to communicate with a 3rd party software!
That is what i need it to do though!

Well, with the library you have, only the device having the address 0x68 is active during I2C operations, so you simply arrange for the other devices to have the alternate address by tying their AD0 pins to an output pin.

I did that after following some tutorials and i've managed to get the 0x69
but my problem here is that i don't know how to connect the new headers I added to the 2nd MPU

Each MPU (including the first) has to have an output pin from the MCU connected to the AD0 pin.
SDA and SCL are simply bussed.