Can't make 2 arduinos communicate on the hardware serial pins

Hi!

I'm trying to communicate between two Arduino Duemilanove using the built in Serial class, and the TX RX (0 and 1) pins.

Yes, Baud rates match, and its the good old default 9600
Yes, TX is connected against RX on the other board and vice versa.
No, they don't have their ground pins connected, but they are powered from the same line, so they should have a common ground anyway.
Yes, the USB cabel to the CP is always removed when trying the board-board communication.

The point is that 1 board is a slave, controlling multiple motors, and reading back, and count their encoder signal, while the other board (master) reads multiple sensors, and sends serial messages (single bytes) to order the slave to turn motors accordingly to the per-defined byte command.

The master and slave codes are unnecessary, both is tested with the PC, and operate nearly as expected. The point is I use Serial.begin(9600); and Serial.available(), Serial.read, Serial.write. The only unexpected behavior is that when the arduino is powered, it does not start the expected transmitting (serial leds don't flash) until a suitable program on the computer don't start to listen on the given port.

I tried connecting the two arduinos with home made printer-printer cable (a cable with plug on both ends that goes into this arduino), and with connecting pins 0 and 1 (TX, RX). None did work. The serial leds stay dark, and no communication occurs.

My sniffer says that there might me some king of built in handshake that must be done, and the PC does it automatically before communication happens, or it may be due both arduinos keep resetting their selves from the communication opening, but I doubt that.

Anyway, I can't find out, nor solve this on my own. Any suggestions?

No, they don't have their ground pins connected, but they are powered from the same line, so they should have a common ground anyway.

What does "same line" mean? If they have the same power source, they have their ground pins connected. Else you have to do it.

If you don't see the serial LEDs flashing, the Arduino probably doesn't really boot. Describe how you distribute the power to the two boards. What voltage do you apply? What other boards that might consume power are also connected (to the Arduinos directly or to the same power source)?

My sniffer says that there might me some king of built in handshake that must be done, and the PC does it automatically before communication happens, or it may be due both arduinos keep resetting their selves from the communication opening, but I doubt that.

There is no handshake, however when you open Arduino's "Serial Monitor" It toggles the reset line on the Arduino (resetting the board)

I tried connecting the two arduinos with home made printer-printer cable (a cable with plug on both ends that goes into this arduino), and with connecting pins 0 and 1 (TX, RX). None did work. The serial leds stay dark, and no communication occurs.

I'm confused with this statement: Can you simplify your setup? Use one wire to make each Rx-to-Tx connection

The master and slave codes are unnecessary, both is tested with the PC, and operate nearly as expected. The point is I use Serial.begin(9600); and Serial.available(), Serial.read, Serial.write. The only unexpected behavior is that when the arduino is powered, it does not start the expected transmitting (serial leds don't flash) until a suitable program on the computer don't start to listen on the given port.

Post your code, it won't hurt and it might help; Since I'm failing to see how you can test a two-board communication setup using a PC as and say that it works ;0)

Okay, first of all thats for the fast reply. I f you insist I post all those informations.

Testing both arudino with PC happened with the USB cable (the same that is used for programming), and the on the PC I sent the very same serial messages that the other arduino should have. All replies and behavior was the same as expected, thats why I know the code is ok. By the way, meanwhile I also tested the two card together with Software serial, and it worked that way.

First picture, showing ONLY the two attempts to make connection between the two arduinos. The 3rd picture shows the home made printer-printer cabel (Its properly soldered, and has contact on all 4 lines)

The second picture shows the power supply lines, and all the connection that is between the arduinos right now.

The 4th picture shows the whole bunch of chaos. Currently most of the thing your see aside to the arduinos and the motor shiled are disconnected, only the micro servo is actually connected and used. This picture does not perfectly represent the second picture. Here the master arduino has pins 2 and 3 for a SoftwareSerial connection to Slave pin 0 and 1.

What happened so far: after 10+ hours of experimenting, and troubleshooting I decided to try the SoftwareSerial (That is now exactly the same as the NewSoftwareSerial), on one side of the two arduinos. If the problem was that both arduinos keep resetting each other, this would solve it. It did not, so not that was the problem.
Even thou the motor controlling arduino only has the 0 and 1 pins unused (default HW Serial TX RX pins) out of all digital and analog pins , I used a Serial.end() in the setup, to make sure it is not used as HW serial, and attached a SoftwareSerial there as well.

With this it started to work properly.

The problem is, that I don't wish to sacrifice the safety of an input buffer, and to throw away all built in hardware aid, and make my CPU time eat itself while listening on an unbuffered software serial port, or make my system get flooded with interrupts that are not meant to be handled by the CPU, but a hardware that is already there in that damn arduino card.

I do look forward for any answer. Thank you in advance!

Oh, forgot the code, here it is:

Master:

#include <SoftwareSerial.h>
#define TOP 120
#define BOTT 30
#define LED 13
#define vTX 3
#define vRX 2

SoftwareSerial mySerial(vRX, vTX);

int state;

void setup() {
  digitalWrite(LED, HIGH);
  delay(100);
  digitalWrite(LED, LOW);
  delay(100);
  digitalWrite(LED, HIGH);
  delay(100);
  digitalWrite(LED, LOW);
  delay(100);
  digitalWrite(LED, HIGH);
  mySerial.begin(9600);           // set up Serial library at 9600 bps
  Serial.begin(9600); // DEBUG
  state=0;
  delay(150);
  Serial.println("Now begining to listen for slave...");
  while(state == 0)
  {
      if(mySerial.available() != 0) // we got someting
      {
        Serial.println("I got something...");
        if(mySerial.read() == 100)
        {
        Serial.println("Yeah, thats my slave!!");
        mySerial.write(101); // we send a handshake back, with that, both arduino contune to the loop
        state = 1;
        }      
      }
  }
  mySerial.flush();
} //end of SETUP

// Main loop of MASTER
void loop() {
  digitalWrite(LED, LOW);
  
  mySerial.write(48);
  Serial.println("Turn up!");
  
  delay(500);
  digitalWrite(LED, HIGH);
  delay(100);
  digitalWrite(LED, LOW);
  
  mySerial.write(49);
  Serial.println("Turn down!");
  
  delay(500);
  digitalWrite(LED, HIGH);
  delay(100);
  digitalWrite(LED, LOW);
    
}

Slave:

#include <AFMotor.h>
#include <Servo.h>
#include <SoftwareSerial.h>
#define TOP 120
#define BOTT 30
#define LED 13
#define vTX 1
#define vRX 0

SoftwareSerial mySerial(vRX, vTX);
int state;


// DC hobby servo
Servo servo1;

void setup() {
  delay(300);
  Serial.end();           // make sure TX RX pins are free to use
  delay(300);
  mySerial.begin(9600);
  
  state = 0;
  digitalWrite(LED, HIGH);
  
  servo1.attach(10);
  
  delay(10);
  
  
  while( state == 0 )
  {
  mySerial.write(100); // we tell the master we are ready
    for(int i= 0; i<200;i++)
    {
      delay(3);
      if(mySerial.available() != 0) // we got someting
      {
        if(mySerial.read() == 101) state = 1; //handshakeing done
      }
      if(i>100) digitalWrite(LED, LOW); else digitalWrite(LED, HIGH);
    }
  }
mySerial.flush();
} // end of SETUP

int i;

// Main loop of SLAVE
void loop() {
  digitalWrite(LED, LOW);

  
  
  
  while (mySerial.available() == 0);
  
  int command = mySerial.read();
  
  switch (command)
  {
    case 48: // 0 in acsii
      servo1.write(BOTT);
    break;
    
    
    case 49: // 1 in acsii
      servo1.write(TOP);
    break;
    
    default: // Error occured
  delay(75);
  digitalWrite(LED, HIGH);
  delay(75);
  digitalWrite(LED, LOW);
  delay(75);
  digitalWrite(LED, HIGH);
  delay(75);
  digitalWrite(LED, LOW);
  delay(75);
  digitalWrite(LED, HIGH);
  delay(75);
  digitalWrite(LED, LOW);
  delay(75);
  digitalWrite(LED, HIGH);
  delay(75);
    break;
  }
    
}

Now it uses Software serial, but the only difference to the original code is I changed all "Serial." to "mySerial." and added some debugging to the master.

First of all: you cannot connect the Arduinos by using an USB cable. This is NOT the hardware serial as you describe it, it's a USB slave on both sides, so no-one is the master, this can never work.

When you connect the RX/TX pins you must also connect the GND lines.

The Arduinos will probably not power up if you supply them with only 5V to the power connectors. If you have 5V regulated you can supply the boards directly through the 5V and GND pins of the shield connector but the main power connector uses a linear voltage regulator which needs at least 7V input.

Wow, if only Arduinos worked like this! But this is not the case; use digital pins 0 and 1 (they say Rx and Tx right on the board).

By the way, Pylon is right:

-From Arduino.cc- DC Barrel Jack Power Input
"Input Voltage (recommended): 7-12V
Input Voltage (limits): 6-20V"

You can get rid of the external 5V regulator and power the arduinos from the 8-10V Battery you have (assuming when fully charged it will never surpass the limits above). Personally, I think if you are using the battery to power motors you might want a separate smaller battery for the Arduinos to avoid noise-interferance generated by the motors.

By the way, the correct name for the cable you have made is a USB-B to USB-B cable (which I'm assuming you probably crossed over the signal lines, rendering it a non-functional USB-B to USB-B cable)

I see. Thanks for the information! And sorry for using wrong terminology for the USB cable.

So, if I use the DC jack as I do now, I should supply 7+ volts there unregulated, without any filtering capacity or amperage limiting resistor?

By the way, as mentioned, with Software Serial, on digital pins it already worked properly, all communication done, and servo turned properly as commanded by the master... using 5V in the DC jack. That could explain it by the way. As soon as I have the time I'll test it with higher voltage supplied, and using native Serial, and post the results

Thank you!

Yes! The main problem is solved! thanks to all who helped!
The problem was indeed the voltage level. 5V in the DC jack was enough to power the ATmega, and do everything EXCEPT the normal Serial connection on TX RX pins. Replacing the 5V with 8~10v directly from battery made it work.

Thank your very much!