2 arduino comminication

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.

arduino 1 code :

void setup() { Serial.begin(9600); pinMode(1,OUTPUT);

} void Send() { Serial.write(1); }

void loop() { Send(); delay(200); }

arduino 2 code :

void setup() { Serial.begin(9600); pinMode(1,INPUT);

} void Read() { int message = Serial.read(); Serial.print(message); Serial.println(); }

void loop() { Read();

}

help me plz :.

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.

i use this example : http://arduino.cc/en/Reference/SoftwareSerial

and i wrote that :
arduino Uno :

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);

void setup()  
{
  Serial.begin(57600);
  mySerial.begin(4800);
}

void loop() 
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

arduino Mega :

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);

void setup()  
{
  Serial.begin(57600);
  mySerial.begin(4800);
 
}

void loop() // run over and over
{
 mySerial.println("Hello, world?");
}

but it doesn’t work :roll_eyes:

Please use the normal baudrate of 9600 for the communication to the PC.

Are the Arduinos connected like this: Uno RX(10) to Mega TX(11) Uno TX(11) to Mega RX(10) Uno GND to Mega GND

Please add a delay(1000); after the "Hello, World ?". Sending it continuesly could overload a buffer.

hi sir,

i have interfacing code for ARDUINO UNO AND ADXL345 and interfacing code for ARDUINO UNO AND SIM900 SHIELD

so in order to run as one code.do we need 2 have 2 ARDUINO UNO orelse can v make some changes in program?

Try to mix code 1 and code 2 ? :roll_eyes:

hi sir,

could u guide me in joining 2 codes?

? to join a code you do copy, cntrl C of your code, and than paste here cntrl V. But click on the button "#" to obtain that : ``

jaya: hi sir,

could u guide me in joining 2 codes?

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.