Arduino Serial with PySerial?

Hello all,

I am trying to do simple serial communication across 2 Arduino's (both Mega). That is, I send data from computer #1, to arduino #1, data gets sent to arduino #2, which forwards the data to computer #2. I am using Python's PySerial to send data, Serial on the arduino to communicate with the computer, and Serial1 to do communication between the two arduino's.

However, the second arduino simply will not receive the data correct unless I put sleeps in the python code that sends, data. That is:

f = open(filename,'rb')

ser = serial.Serial(sendport.get(),2400)

...Later in code....

while True:
 contents = f.read(1)
 time.sleep(.005)
 ser.write(contents)

This works PERFECTLY. But once I comment out time.sleep(.005). The second arduino doesn't read. I am 100% by baud rates match, and it is more surprising that this doesn't work even at these slow speeds. As you can imagine, having to put 5 milliseconds between each byte ruins the speed.

Here is my (basic) arduino code:

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(2400);
Serial1.begin(2400);

}

void loop() // run over and over
{
  if (Serial1.available())
    Serial.write(Serial1.read());
  if (Serial.available())
    Serial1.write(Serial.read());
  
    
}

The python code loops faster than the Arduino can send .

@2400 baud every char takes about 4 milliseconds to arrive.

That was the relationship I originally assumed would hold, but I should have mentioned that I've been playing with other frequencies where that relationship seems to break down.

For instance, right now, I am playing with 57600 (1/57600=.0000173, 17 microseconds) and even with a 500 microsecond sleep (i.e. I changed time.sleep(.005) to time.sleep(.0005) I can't get reliable transmission. That is, I increased bauds by x20 but could only divide sleep time by 5. 115200 gives approximately the same results.

I am trying to do simple serial communication across 2 Arduino's (both Mega).

Below is some simple serial test code I've used to communicate between two arduinos.

//zoomkat 3-5-12 simple delimited ',' string tx/rx 
//from serial port input (via serial monitor)
//and print result out serial port
//Connect the sending arduino rx pin to the receiving arduino rx pin. 
//Connect the arduino grounds together. 
//What is sent to the tx arduino is received on the rx arduino.
//Open serial monitor on both arduinos to test

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like wer,qwe rty,123 456,hyre kjhg,
  //or like hello world,who are you?,bye!,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >0) {
        Serial.print(readString); //prints string to serial port out
        Serial.println(','); //prints delimiting ","
        //do stuff with the captured readString 
        readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}