Two Arduino Mega 1280 boards communicate using I2C

Hi,
I encountered a problme using two arduino mega1280 boards to communicate to each other. It didnt work.ardall.
I just follow this link to link the two boards. the pullup resistors I used is 10K

http://www.instructables.com/id/I2C-between-Arduinos/step2/Hardware/

Here is my code for Master:

#include <Wire.h>

#define LED_OUT 13

void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}

int x = 0;

void loop()
{
Wire.beginTransmission(5); // transmit to device #5
Wire.send(x); // sends one byte
Wire.endTransmission(); // stop transmitting

x++;
if (x == 10)
x = 0;
delay(100);
}

and for the Slave:

#include <Wire.h>

#define LED_OUT 13

int x;

void setup()
{
Serial.begin(9600);
Wire.begin(5); // join i2c bus with address #5
x = 0;
}

void loop()
{
if(Wire.available())
{
x = Wire.receive();
Serial.println(x);
delay(100);
}
else
{
Serial.println(“XXXXXXX”);
}
}

Any help will be greatly appreciated.
Thank you

IF you used the wiring diagram in that link then you have the two I2C pins wired to the wrong pins. The AVR1280 mega boards use different pins for I2C, pins 20 & 21 for data & clock.

Lefty

you are correct, it works now.
Thank you very much :smiley: