Serial communication

Hi Everyone,

I have two Arduino Mega 2560 that i am trying to connect togeather via the communication ports. All of my research says this should be working, but for the life of me i cant get it figured out. they just never seem to connect.

this is my current code

//Transmitter code

void setup()

this is my current code

//Transmitter code

void setup()

There isn't even a loop() function, or a body to the setup() function.

What have you connected on one Arduino to what on the other Arduino?

thanks for getting back so quickly!

i had a slight keyboard issue and i submitted the post withough typing almost anything out.

The setup is very simple

Arduino 1 Arduino 2
TX1<--------------->RX0
RX0<--------------->TX1

here is my real code:

//Transmitter code

counter = 1;

void setup(){
Serial.begin(9600);
}

Void loop(){
Serial.print(counter);
delay(10);
}

//Receiver code

Void setup(){
Serial.begin(9600);
}

Void loop(){
if (Serial.available()>0){
incomingByte = Serial.read();
Serial.print(incomingByte, DEC);
}
incomingByte = 0;
}

Does

Arduino 1 Arduino 2
TX1<--------------->RX0
RX0<--------------->TX1

imply

Arduino 1 Arduino 2
Gnd<--------------->Gnd

? ? ? ?

Well, your code on the sender is just going to send "1" over and over again; it won't actually count. And, you should declare a type for counter. Maybe something like this:

//Transmitter code

int counter = 1;

void setup(){
  Serial.begin(9600);
}

Void loop(){
  Serial.print(counter);
  delay(10);
  counter++;
}

Both ardunos are grounded to eachother.

i took out the counter bit because nothing was happening so i just wanted to eliminate all the extra stuff to see if i couldnt figure out where the problems were coming from.

How is this supposed to work? Using different pin pairs on the serial bus for what reason... and perhaps more importantly, to what end?

How about connecting as thus, where A1 = Arduino #1, and A2 = Arduino #2

A1-RX1 ---- A2-TX1 A1-TX1 ---- A2-RX1 A1-GND ---- A2-GND

... or ...

A1-RX0 ---- A2-TX2 A1-TX0 ---- A2-RX2 A1-GND ---- A2-GND

... etc ...

Thus, always use the same serial port pairs on both Arduinos to minimize confusion.

Also see the great work that Bill Porter did with Easy Transfer. Then you can send stuff, confirm that the other Arduino got it, etc.

max4260: they just never seem to connect.

Are you using the default Serial hardware port to talk to the host PC, or to talk to the remote Arduino? It isn't going to be happy doing both, but since you're printing trace messages to the same Serial port that you're using for your coms test, I suspect that's what you're asking it to do.