I'm having issues getting the Master Writer/Slave Receiver example to work using an Arduino Mega 2560 and an Arduino UNO.
Here's a pic of my wiring:
Here's my Master Sketch:
#include <Wire.h>
void setup()
{
//Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
//Serial.println("master setup");
}
byte x = 0;
void loop()
{
Wire.beginTransmission(21); // transmit to device #4
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
//Serial.println(x);
x++;
delay(500);
}
Here's my Slave Sketch:
#include <Wire.h>
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
Serial.println("slave setup");
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
My UNO is connected to my computer via USB. My Mega is powered via a 12V 2.5 DC adapter. I'm using the pins 20 and 21 on the MEGA for data and clock signals respectfully.
I test in this sequence...Upload master sketch to MEGA, then upload slave sketch to UNO. I've also tried resetting both boards.
Any ideas why I wouldn't be getting any traces from my UNO? Is there something I'm missing?

