How to communicate between 2 boards?

I tried to make to boards talk to each other using the rx / tx pins. I connected rx to tx and tx to rx, so that a signal that is being send over a tx pin can be received by an rx pin.

I´m using printByte(byte) to send a byte from one board, while checking with serialAvailable() and serialRead on the other.

Unfortunately the whole matter does not seem to be as simple as i thought it would be.
Tried to connect the ground pins of the two boards but it did not work either.

Has anyone tried the same and can give me hint on what i´m doing wrong?

Hi Kr1

i’ve never tried this but …
have you unplug your serial or usb from your computer, cause the rx/tx are the same port connected to your computer.

hope this help.



thanks for the tip, i tried that already but had no luck with it…

I´m beginning to think about a workaround using analogRead() and analogWrite() to send signals between the boards.
That would be enough for the current project, but a real serial connection would still be sexy…

Any hint might help.

Strangely enough, when I tried this (sending serial data from a Wiring board to the Arduino board), it only worked when the Arduino board was connected and powered through the USB port. The RX and TX lights on the Arduino board didn’t flash.

You definitely need to tie the grounds together.

What baud rate were you using? Try using 9600 or 19200.

Can you post your code?

Thanks mellis!
Here´s my setup:

I am using two arduino boards (“multitasking” the hard way :wink:
They are powered from different power supplies, one by batteries (6V) the other from a regulated power supply (6V), might this be part of the problem?
None of the boards is connected via usb.
The serial pins ared tied together (rx > tx, tx > rx).
(do i have to set them to INPUT / OUTPUT ?)

When i connect the ground pins together, it seems that one board powers the other (power led turns on immediately, even with no power connected to that board)

No matter wether ground is connected or not, i don´t get the communication going.
The rx/tx leds dont blink, but they´re sort of on. The led that is supposed to light up once the board receives a value over the serial pins stays dark.

I have not tried the whole thing with the usb cable connected to one or both boards yet, since i´m planning to run the boards without a computer.
But i´m going to try connecting the usb now, same for the 19200 baudrate…

here are the code bits i used to test the communication:

sender board:

int ledPin = 13;   
byte txVal = 10;      

void setup() {
  pinMode(ledPin, OUTPUT);   
  //pinMode(0, INPUT);          //this did not seem to make any difference
  //pinMode(1, OUTPUT);       //this did not seem to make any difference

void loop () {

receiver board:

int ledPin = 13;  
byte rxVal = 0;  

void setup() {
  pinMode(ledPin, OUTPUT);  // declare the LED's pin as output
  beginSerial(9600);        // connect to the serial port

void loop () {
  // read the serial port
  if(serialAvailable() > 0){
    rxVal = serialRead();
    if (rxVal == 10){
    digitalWrite(ledPin, HIGH);

hey kr1,
it seems that you are continuously sending and empty byte…that might be the problem!
try setting a value to txVal
either in the declaration
byte txVal = 10;
(more appropriate is to make it an Integer → int txtVal = 10; and use printInteger(txVal) )

or in the loop

void loop () {
txVal++; //add 1 to txVal at every loop
printByte(txVal); //send the new value of txVal

or you can do both ( but start txVal = 0) else you wont see the effects

in the receiver board you could also make the led blink as many times as the txVal

if(serialAvailable()) {
rxVal = serialRead();
for(i=0; i<rxVal; i++) {
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);

you will need to synchronize the sender’s and receiver’s delays
because the receiver wont read again the serialbuffer untill it has completed blinking the first value it reads (if rxVal = 10 and every “for” loop takes 500+500ms = 1 second to complete, the receiver will redo the reading of the serial buffer only after 10 secs…but in the meantime the sender board has gone way faster ahead with its small delay(10); of 10 milliseconds

I’ve never tested this in making 2 boards communicate…it’s just an idea :slight_smile:

hope it helps

thanks for your advice… i´m going to try it as soon as i find time and post the results.
made a little mistake when posting the code (fixed it now). Of course txVal had a value assigned to it. So that could not have been a problem.

Synchronising the delays seems pretty hard to do, at least a very exact synchronisation, since both boards need to start their loops at exactly the same time, or am i wrong?
Since Arduino has a hardware serial buffer, i thought it should be possible to read whatever byte is there at any given time without having to synchronize the delays.

you can create your own “protocol” to ensure that they are syncronized

  • the sender sends a char “s” and loops untill it receives a confirmation “c” from the reader before starting its synchronized tasks
  • the receiver repetedely reads the serial untill it receives the “s” (for start value)
  • when it receives the “s” from the sender it will send back a “c” and start its main loop
  • the sender will receive the “c” that will make it start its main loop…

this is my crunchy version :slight_smile:
there probably is a better way or some special code in the Rs-232 serial protocol for bit sincronization…
but I certainly don’t know it :slight_smile:
if you discover please tell us.

but I imagine doing this blinded without a serial out on the pc screen is kind of hard…
good luck

ps. have a look at in the actionscript class example I’ve set up…
I had to create exactly that wait and response inside both Arduino and Flash…might give you some hints :slight_smile: