[Arduino] Arduino to Arduino Serial Communication

In this post, we will explore an easy method for transferring data from one Arduino board to another using Bill Porter’s EasyTransfer Library. Here’s a traditional method on how you hook up Arduino’s serial ports. TX to RX, RX to TX, Ground to Ground. TX is the transfer pin and RX is the receiver pin, therefore you connect the one to the other. Finally, in order for the two device to communicate with each other, the two boards must have a common ground. Here’s the wiring I drew using Fritzing, I figured it’s probably time to be neater in describing how to hook stuffs up, lol.

Library Download Link:
http://www.billporter.info/easytransfer-arduino-library/

The EasyTransfer library is actually quite easy to use once you figure it out. Basically, you set it up by declaring a common data structure on both board and initialize the library. Once you have done that, you can change your data values inside that data structure on the TX board and transmit the data set. When the RX Arduino receive the data, you can extract that data and do whatever you want with it. Here’s a simple example. An idea is to have the RX board send a “confirmation” that it has receive the data is order to ensure nothing is lost in the process. But that is not necessary at this time.

 

Ardino – Transferring


/* Yu Hin Hau
 * Easy Transfer Tutorial (Transfer)
 * 8/4/2012
 */

#include <EasyTransfer.h>

EasyTransfer ET;

//Declare Data Structure for the EasyTransfer Library
//Note: Data Structure must be same on TX and RX...

struct DATA_STRUCTURE{
 int int_data;
 char char_data;
};

DATA_STRUCTURE myData;

int counter;

void setup()
{
 //Initalizing EasyTransfer Serial Ports
 Serial.begin(9600);
 ET.begin(details(myData), &Serial);

counter = 0;
}

void loop()
{
 //Setting Values to Variables
 myData.char_data = counter;
 myData.int_data = counter++;

//Sending Data
 ET.sendData();
 delay(1000);
}

 

Arduino – Receiving

/* Yu Hin Hau
 * Easy Transfer Tutorial RX
 * 8/4/2012
 */

#include <EasyTransfer.h>

EasyTransfer ET;

struct DATA_STRUCTURE{
 int int_data;
 char char_data;
};

DATA_STRUCTURE myData;

void setup()
{
 Serial.begin(9600);
 ET.begin(details(myData), &Serial);
}

void loop()
{
 //Extract data if data is received
 if(ET.receiveData())
 {
 Serial.println(myData.char_data);
 Serial.println(myData.int_data);
 delay(250);
 }

}
Advertisements

9 thoughts on “[Arduino] Arduino to Arduino Serial Communication

  1. Hi,
    Can we use this library with rs485 library to make two arduinos card communicate over long wired distance?
    thanks in advance

  2. Hi,
    Can we use this library with rs485 library to make two arduinos card communicate over long wired distance?
    thanks in advance

  3. Two things, the first thing is that I made some test using two arduinos with two rs485 shield and works great. The second thing is: how can I receive multiple inputs in the receiver from multiple sensors in the transmitter. I don’t know how to do that. PLEASE HELP!

    Thanks, blessings!

    M. Soto Cora, PE, ME

    • Sorry, don’t have any experience with rs485. But as far as receiving data from multiple sensors through serial, you can try using the Software Serial library if the Arduino’s default Rx and Tx pins are taken. Basically, the reroute the Tx and Rx signal to the software Rx and Tx digital pin.
      http://arduino.cc/en/Reference/SoftwareSerial

      idk what sensors you are using, but I2C and SPI seems to work pretty well if you just want to chain them up and retrieve data by address.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s