About the error of transfer program form UNO to mega

It didn’t work and showed that

C:\Users\User\Desktop\FYP\arduino-nightly\libraries\I2Cdev\I2Cdev.cpp:64:14: warning: #warning Using current Arduino IDE with Wire library is functionally limiting. [-Wcpp]

#warning Using current Arduino IDE with Wire library is functionally limiting.

^

C:\Users\User\Desktop\FYP\arduino-nightly\libraries\I2Cdev\I2Cdev.cpp:65:14: warning: #warning Arduino IDE v1.0.1+ with I2CDEV_BUILTIN_FASTWIRE implementation is recommended. [-Wcpp]

#warning Arduino IDE v1.0.1+ with I2CDEV_BUILTIN_FASTWIRE implementation is recommended.

^

C:\Users\User\Desktop\FYP\arduino-nightly\libraries\I2Cdev\I2Cdev.cpp:66:14: warning: #warning This I2Cdev implementation does not support: [-Wcpp]

#warning This I2Cdev implementation does not support:

^

C:\Users\User\Desktop\FYP\arduino-nightly\libraries\I2Cdev\I2Cdev.cpp:67:14: warning: #warning - Timeout detection (some Wire requests block forever) [-Wcpp]

#warning - Timeout detection (some Wire requests block forever)

^

Invalid library found in C:\Users\User\Desktop\FYP\arduino-nightly\libraries__MACOSX: C:\Users\User\Desktop\FYP\arduino-nightly\libraries__MACOSX

Sketch uses 20,430 bytes (8%) of program storage space. Maximum is 253,952 bytes.
Global variables use 1,450 bytes (17%) of dynamic memory, leaving 6,742 bytes for local variables. Maximum is 8,192 bytes.
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
Invalid library found in C:\Users\User\Desktop\FYP\arduino-nightly\libraries__MACOSX: C:\Users\User\Desktop\FYP\arduino-nightly\libraries__MACOSX
Invalid library found in C:\Users\User\Desktop\FYP\arduino-nightly\libraries__MACOSX: C:\Users\User\Desktop\FYP\arduino-nightly\libraries__MACOSX

Is the I2C problem, or the library wrong?

Thanks all!

Did you change the target board from Uno to Mega in the IDE Tools->Board?

Did you change the pin numbers as necessary? Uno PWM, Analog and port pins are not all the same as those on the Mega.

The I2C warnings are warnings, your code is compiling (also - you sound new - why are you using the nightly? They're experimental versions of the IDE, and more likely to have bugs. 1.6.5r5 is what I recommend to minimize your exposure to IDE bugs)

The error is that you're not able to upload the sketch once it compiles.

Sort that out. Is the mega known working? bootloaded? etc?

The pin is correct and I didn't change.

Also I already change the target board

I use it to collect the MPU6050 output data. It works in UNO. However, when I collect to Mega, all output number become to zero.

Uno SDA is pin 4, SCL is pin 5.

Mega SDA is pin 44, SCL is pin 43.

Ok I try try, thanks all!!

There is another question, how can I change the SDA form pin 4 to pin 44??

rubberbento: There is another question, how can I change the SDA form pin 4 to pin 44??

The SDA pin is pin 44 - you can't change it (That's pin 44 on the chip, pin 20 on the header)

But I just change the pin from pin 4 to pin 44? Don't need to change the program? :-[ :'(

Thanks!!!!!!

If you’re using I2C, you have to use pin 44 (aka digital pin 20) - you have no choice, and no change to make.

It still can’t work, here is my program which is work at UNO and can’t output data (all 0.00) in MEGA2560.

#include <SD.h>
#include <math.h>
#include "I2Cdev.h"
#include "MPU6050.h"

File robotleg;


// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include "Wire.h"
#endif

// 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 accelgyro;
//MPU6050 accelgyro(0x69); // <-- use for AD0 high



int16_t ax, ay, az;
int16_t gx, gy, gz;

//variaveis genericas
int loop_cnt=0;
int ledPin = 13;
char c;
int i=0,inicio=0;
boolean first_exec=true,debug_msg=true,debug_k=false;
double T=0;
int Boolean_state=0;

//variaveis do nunchuck
int zbut,cbut;

//variaveis do aceleroemtro
int offsetX=132,offsetY=134,offsetZ=190,offsetW=319;  //offset values are obtained holding the chuck on a fix zero position
static double scaleX=-50,scaleY=50,scaleZ=50,scaleW=0.512;  //point axxis upward then downward, subtracting the values, and divide by 2
double accx,accy,accz;
double accdegx,accdegy,accdegz;
double countx,county,countz;
double pitch=0;
double con=32768;
double accfactor=(9.81*(2/con));

//variaveis do gyroscopio
double gyro=0,w=0,teta=0,filter_teta=0;

//variaveis do PID
double dt=1;
double error=0, last_error=0;
double last_time=0,time=0;
double setpoint=0;
double integral=0,derivative=0,output=0;

//constantes
#define MAXTRESHOLD 230
#define MINTRESHOLD 35
#define HPF 0.98
#define LPF (1-HPF)
#define SAMPLE 10
#define OUTPUT_READABLE_ACCELGYRO

// uncomment "OUTPUT_BINARY_ACCELGYRO" to send all 6 axes of data as 16-bit
// binary, one right after the other. This is very fast (as fast as possible
// without compression or data loss), and easy to parse, but impossible to read
// for a human.
//#define OUTPUT_BINARY_ACCELGYRO


#define LED_PIN 13
bool blinkState = false;

void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

    // initialize serial communication
    // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
    // it's really up to you depending on your project)
    Serial.begin(115200);

    // initialize device
    Serial.println("Initializing I2C devices...");
    accelgyro.initialize();

    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");

    // use the code below to change accel/gyro offset values
    /*
    Serial.println("Updating internal sensor offsets...");
    // -76  -2359 1688  0 0 0
    Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t"); // -76
    Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t"); // -2359
    Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t"); // 1688
    Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t"); // 0
    Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t"); // 0
    Serial.print(accelgyro.getZGyroOffset()); Serial.print("\t"); // 0
    Serial.print("\n");
    accelgyro.setXGyroOffset(220);
    accelgyro.setYGyroOffset(76);
    accelgyro.setZGyroOffset(-85);
    Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t"); // -76
    Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t"); // -2359
    Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t"); // 1688
    Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t"); // 0
    Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t"); // 0
    Serial.print(accelgyro.getZGyroOffset()); Serial.print("\t"); // 0
    Serial.print("\n");
    */
    
    // configure Arduino LED for
    pinMode(LED_PIN, OUTPUT);
    
    pinMode(7, OUTPUT);

/*

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
*/

  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  robotleg = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (robotleg) {
    Serial.print("Writing to test.txt...");
    robotleg.println(accdegx);
    
    // close the file:
    robotleg.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  robotleg = SD.open("test.txt");
  if (robotleg) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (robotleg.available()) {
      Serial.write(robotleg.read());
    }
    // close the file:
    robotleg.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
}

void loop() {

    
      if(Boolean_state){
        digitalWrite(7,HIGH);
        Boolean_state = false;
      }
      else{
        digitalWrite(7,LOW);
        Boolean_state = true; //-2us
      }
    
    
    // read raw accel/gyro measurements from device
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    
    countx  = ax*accfactor;
    county  = ay*accfactor;
    countz  = az*accfactor;
    //zbut = nunchuck_zbutton();
    //cbut = nunchuck_cbutton();
    //gyro = analogRead(0);

    accx = ((atan2((countx),sqrt(sq(county)+sq(countz)))));
    accy = ((atan2((county),sqrt(sq(countx)+sq(countz)))));
    accz = ((atan2(sqrt(sq(county)+sq(countx)),(countz))));

    accdegx = (accx * 4068) / 71;
    accdegy = (accy * 4068) / 71;
    accdegz = (accz * 4068) / 71;
    
    //pitch = (double)(atan2(accy,sqrt(sq(accz)+sq(accx)))*180/3.14);

    w    = ((double)(gyro-offsetW)/scaleW);

    teta = teta + w*dt/1000;


    filter_teta = HPF*(filter_teta + w*dt/1000 ) + LPF*(pitch);

    if(cbut==1){
    set_offset();
  }

 

    // these methods (and a few others) are also available
    //accelgyro.getAcceleration(&ax, &ay, &az);
    //accelgyro.getRotation(&gx, &gy, &gz);

    #ifdef OUTPUT_READABLE_ACCELGYRO
        // display tab-separated accel/gyro x/y/z values
        Serial.print("a/g:\t");
        Serial.print(con); Serial.print("\t");
        Serial.print(accfactor,10); Serial.print("\t");
        Serial.print(accdegx); Serial.print("\t");
        Serial.print(accdegy); Serial.print("\t");
        Serial.print(accdegz); Serial.print("\t");
        Serial.print(accx); Serial.print("\t");
        Serial.print(accy); Serial.print("\t");
        Serial.println(accz);
        /*
        robotleg.println("a/g:\t");
        robotleg.println(accx); robotleg.println("\t");
        robotleg.println(accy); robotleg.println("\t");
        robotleg.println(accz); robotleg.println("\t");
        robotleg.println(gx); robotleg.println("\t");
        robotleg.println(gy); robotleg.println("\t");
        robotleg.println(gz);
        */
    #endif

    #ifdef OUTPUT_BINARY_ACCELGYRO
        Serial.write((uint8_t)(ax >> 8)); Serial.write((uint8_t)(ax & 0xFF));
        Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF));
        Serial.write((uint8_t)(az >> 8)); Serial.write((uint8_t)(az & 0xFF));
        Serial.write((uint8_t)(gx >> 8)); Serial.write((uint8_t)(gx & 0xFF));
        Serial.write((uint8_t)(gy >> 8)); Serial.write((uint8_t)(gy & 0xFF));
        Serial.write((uint8_t)(gz >> 8)); Serial.write((uint8_t)(gz & 0xFF));
    #endif

    // blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);

  // nothing happens after setup
}

void set_offset(){
  delay(500);
  //nunchuck_get_data();
  offsetX=countx;
  offsetY=county;
  offsetZ=countz;
  offsetW=analogRead(0);
  Serial.println("Novos offsets setados");
}

Moderator edit: CODE TAGS.

Post a schematic AND a picture to prove that you followed the schematic.

When posting code, do NOT post boatloads of commented out code. Exercise your delete key BEFORE posting code IN CODE TAGS.