So I have been trying to get my 2 mega 2560's to talk for days now and I'm ready to get the shot gun out and teach them what for......
I have tried using many sketches but to no avail. I have even tried the examples that came with sketch_sep10a and just running them as is one in each mega and no work. Then I tried the sketches below and found the mega's lock up just after the: Wire.beginTransmission(5); line. I tried the same code in both my mega 2560 and same poo. Tried it in my Arduino uno and the LEDs turn on and off on the master, but the mega dose not seem to receive anything. I only have one Uno. I'm a a loss here.
There are 3 wires from each mega. Pin # 21 runs to the SCL bus, and 20 runs to the SDA bus. Then a 5 volt feed runs into 2 resistors. 1 resistor connected to each bus. Then after you asked a bought connecting the grounds I added a ground from one of the ground pins on each mega to the other mega. Did not seem to help.
I was playing with the sketch and I got the first one to appear to work. I commented out the lines that said end transmition, and now I can turn on or off the LED'S on the master board. But not on the slave. So there is no way to tell if the signal is even leaving the master board.
O dear a photo, ok sure, first let me explain that this is a vary advanced mess. I'm trying to upgrade my life size R2D2. The mega in the bottom has only 4 empty pins left. The slip wring that takes wires to the head has only 4 wires un used. The bottom mega is well buried sort of and the top one in the head is out in plain view but the buss with the resistors where the buss is feed or starts is on the other side of the head. Ill post some pictures. Sorry I know these R not what you where looking for, But I did not what to be rude and not post anything.
Ok This is the droid before I started with the new projects.
Here is the inside of the body, main panel. The mega is circled in red.
OK, so you don't have two Megas on the bench connected by 3 wires and are having trouble with that sketch, exactly. You have much, much more.
First, it looks really cool.
Second this is what Wire.beginTransmission does:
void TwoWire::beginTransmission(uint8_t address)
{
// indicate that we are transmitting
transmitting = 1;
// set address of targeted slave
txAddress = address;
// reset tx buffer iterator vars
txBufferIndex = 0;
txBufferLength = 0;
}
It sets 4 variables.
Slee_The_Sloth:
Then I tried the sketches below and found the mega's lock up just after the: Wire.beginTransmission(5); line.
Now the code above is hardly going to fail. So your deduction that it locks up on the Wire.beginTransmission(5) just can't be right. On the endTransmission, that I could believe.
To say that there might conceivably be a bit of noise in your system there would be an understatement, I think.
You could try dropping the I2C clock speed. My page gives example settings for that:
Is there any good reason you can't use one of the Mega's serial ports to talk from one to the other, since I2C seems to be causing problems?
The way I determined where the mega was locking up is I moved the digital write statement around. It worked up to one point and then one line passed that the led quite coming on.
I will look into your page. That's worth a try. As for the serial, I think that would work just as well for what I need. I just don't know much about it..YET.... Any good places to point me to?