# Connect two Arduinos via simple Serial connection

I have two Arduino UNO that I can't get to talk to each other. I made the following connections

A <---> B
0(RX)   1(TX)
1(TX)   0(RX)
GND     GND


I have then, in my code (running on both boards):

void setup()
{
Serial.begin(9600);
// ...
}

void loop()
{
if (Serial.available() >= 1) {
in_sample_value = Serial.read();
in_sample_available = true;
}
if (out_sample_available) {
Serial.write(out_sample_value);
out_sample_available = false;
}
}


in_sample_value is consumed in a ISR (that also sets the in_sample_available flag to false), out_sample_value is produced in another ISR (that also sets the out_sample_available flag to true). The problem is that both TX leds on both boards are continuously on but the RX leds are completely off on both boards. I know that the ISRs are running because I tested them. Can you see what I'm doing wrong?

## Addendum

To create a minimal test-case I just wired together pins 0 and 1 on one of the two boards and ran the following:

void setup() {
Serial.begin(9600);
}

uint8_t count = 0;

void loop() {
Serial.write(count++);
Serial.read();
}


As said above, the TX led is on, the RX led is off.

-
It is usually wise [tm] to reduce your code to the minimum possible complexity until you are SURE that you understand what is happening. Do you have to use ISR's? Conclusions like "knowing that they are running because you have tested them" is often a fatal mindset to adopt. Knowing that they appear to be running based on a test which you thought was adequately representative" adds enough weasel words that your brain need not get stuck in believing its own propaganda. Can you feed one back to itself to read it's own output? –  Russell McMahon Sep 22 '11 at 15:37
I need them because I'm sampling - for audio purposes - from the ADC and at the same time using one of the PWM as a DAC. –  CAFxX Sep 22 '11 at 15:44
You don't need them to test the serial though. –  Oli Glaser Sep 22 '11 at 15:51
You're right: please see the addendum to my question. –  CAFxX Sep 22 '11 at 15:53
I'm not at all "Arduino aware", but this sounds like a well enough documented way to do things to be worth trying jut to prove the basic principles. arduino.cc/en/Tutorial/SoftwareSerial Some issues though - arduino.cc/en/Reference/SoftwareSerial –  Russell McMahon Sep 22 '11 at 16:18
show 1 more comment

## 3 Answers

The RX/TX are the USB connection LEDs. They indicate whether your ATMEGA is transmitting (TX) or receiving data (RX) as opposed to the PC. If you're transmitting data, it's sent to both the USB converter chip and the connected node. After all, the USB chip is sending data to the host PC UART.

If you're receiving data from the connected node, the USB chip hasn't sent the data to the arduino, so no RX LED will be lit. It doesn't mean there is nothing sent though! The ATMEGA may still be receiving data, but the USB chip isn't involved, thus no LED will blink.

In other words, TX means data sent to USB, RX means data received from USB. These LEDs are directly tied to the USB UART converter chip, so you can't change their behaviour.

Having said that, my guess is that your code is probably working fine. If you're unfamiliar to a piece of hardware, don't always trust it! Especially these things can be deceiving if you think that the RX/TX are related to your microcontroller, whereas they are only related to the USB UART chip. Solution: look up schematics, find datasheets and figure out when certain indicators are lit.

-
add comment

I was wondering about these LEDs, so I looked on the UNO page and found this:

The RX and TX LEDs on the board will flash when data is being transmitted via the USB-to-serial chip and USB connection to the computer (but not for serial communication on pins 0 and 1).

If you can "repurpose" those LEDs (or toggle another pin and add an LED/resistor to it) and flash one on receiving a particular character then this might confirm whether the serial is working correctly. So in your code above add a uint8_t rx_char = 0 for receive that the read routine updates, and add an e.g.

if(rx_char < 128)
{
LED = 1;
}
else
{
LED = 0;
}

-
add comment

Although I am not connecting two arduinos together (yet), I did connect a Micron Industrial Voltage Meter to it using a SN75176A Serial converter.

I wanted to see if data was being sent so I connected two led's to the TX/RX pins and sure enough, the led's pulse every time data is sent or received.

Using this method, no programming was required. It's just 2 LED's, 1 resistor connected to cathode & ground and the LED's directly connected to TX & RX.

-
add comment