Pages: [1]   Go Down
Author Topic: Two arduino communication (serial)  (Read 450 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
« Last Edit: March 19, 2013, 04:10:35 pm by lutecky » Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 626
Posts: 34172
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So why do you need a libary to do that?
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

« Last Edit: March 19, 2013, 04:30:50 pm by Erdin » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 626
Posts: 34172
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49354
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Westbrook, CT
Offline Offline
Full Member
***
Karma: 2
Posts: 139
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You should consider the Wire library as well.
http://arduino.cc/en/Reference/Wire
Logged

Arduino Uno R3
Mac OSX Lion


Pages: [1]   Go Up
Jump to: