Go Down

Topic: Two arduino communication (serial) (Read 473 times) previous topic - next topic

lutecky

Mar 19, 2013, 10:02 pm Last Edit: Mar 19, 2013, 10:10 pm by lutecky Reason: 1
Hi,
I'm looking for and I can't find the library for serial two-way communication between the Arduino's. I need to send a few bytes of data to a second arduino, interpret them and send a reply, which will also be interpreted...

Grumpy_Mike

So why do you need a libary to do that?

Erdin

#2
Mar 19, 2013, 10:29 pm Last Edit: Mar 19, 2013, 10:30 pm by Erdin Reason: 1
If you have Arduino boards with a single serial port (Uno, Nano, mini) you can use SoftwareSerial, http://arduino.cc/en/Reference/SoftwareSerial
Create a TX and RX on both boards with SoftwareSerial, and connect TX to RX, and RX to TX. Don't use pin 0 or 1 (RX and TX for serial monitor and upload), and maybe also not 13(led). That's all.

If you have a Mega, you have more serial ports, Serial1 and more.
If you have a Leonardo or Micro, use the Serial1 port on pin 0 and 1.
For the Mega, Leonardo and Micro, use the standard Serial library, http://arduino.cc/en/Reference/serial


lutecky


So why do you need a libary to do that?

I have arduino uno (1) and mega (2) and I make connections:
1(rx) - 2(tx)
1(tx) - 2(rx)
1(5v) - 2(5v)
1(gnd) - 2(gnd)

In 1 I wrie:
void setup(){
serial.begin(57600);
}
void loop{
Serial.println("test");
delay(1000);
}

And in second arduino:
void setup(){
serial.begin(57600);
}
void loop{
}

When I connect second arduino to usb and open console I see nothing. Rx/tx leds dont blink...

Grumpy_Mike

The RX and TX LEDs are not controlled by the data input and output of the arduino. They are controlled by the USB host, so if you have not got them connected to a computer you will not see them blink.

Read the how to use this forum sticky before trying to post any more code.

PaulS

Quote
When I connect second arduino to usb and open console I see nothing.

Because there are no Serial.print() statements on the second Arduino.

Using the one serial port, do you want to talk to the PC or the other Arduino? Yes is not the correct answer.

Erdin

PaulS is right. You should first think about what you want to do.
I prefer do keep the normal serial port for the Arduino serial monitor and to upload sketches.
To communicate between the both, use other serial ports.
The Mega has extra serial ports, and the Uno could use SoftwareSerial.

If you want serious advice, please upload the complete sketches between code tags. Also let us know which pins you are using, perhaps you could make a photo of it.

mixania

Arduino Uno R3
Mac OSX Lion

Go Up