I saw a lot of forum and websites and I still don't understand how to communicate between 2 arduino shields.
I connected tx -> rx and i use Serial library but it doesn't work.
Are you using the Arduino Uno (or nano or mini) ?
Those have only one hardware serial port.
To test the communication, it would be nice to send that to the serial monitor of the Arduino IDE on the PC.
That is possible with the SoftwareSerial library, http://arduino.cc/en/Reference/SoftwareSerial
Create a software serial port on both Arduinos. Let one transmit data. Use the other to receive data over the software serial port and write it to the serial monitor of the Arduino IDE.
A few notes about your sketch:
You don't need to make the pins input or output. The Serial.begin() takes care of that.
If you connect the sender Arduino to the PC, can you see something ? You have to use readable data ofcourse, like the character 'A'.
How did you connect the receiving Arduino ? The RX pin is overridden by the sender Arduino ? and the TX pin to the PC ?
Thanks for your answer, I want to send information with the arduino Mega and receive with arduino Uno (SMD R2).
"How did you connect the receiving Arduino ? The RX pin is overridden by the sender Arduino ? and the TX pin to the PC ?"
i just connected Tx of arduino mega with Rx of arduino Uno. And i connected My Uno to the PC with USB.
"If you connect the sender Arduino to the PC, can you see something ? "
i receive just " " on 9600 and others strange characters if i am on others bauds for exemple : xxx or ààà
I think this is best: make them work one by one, and don't mix the Arduino IDE serial communication with the communication between the Arduinos. That way you can upload your sketches and use the serial monitor without problems.
Use one of the other serial ports (Serial1 or so) of the Mega to send data.
Write a sketch that sends readable data, like this: Serial1.println("Hello");
Create a SoftwareSerial port on the Uno, and read the characters that are received. Write them to the serial monitor of the Arduino IDE.
Upload both your sketches, so we can check it.
Paste your sketch between the code tags. Above the text input field are buttons. The '#' button is for the code tags.
It's either trivial, or practically impossible, depending on the nature of the code.
If both sketches use a non-blocking design and there is no conflict in the use of hardware, and both sketches can fit in the available program space and memory, you could just copy/paste both sets of global definitions, both sets of code in setup() and loop(), and both sets of supporting functions/classes into a combined sketch.
If either sketch is designed using a blocking approach, or there is a hardware conflict, or you run out of space, it gets much more complicated.