Arduino Serial with PySerial?


hello all,

i trying simple serial communication across 2 arduino's (both mega). is, send data computer #1, arduino #1, data gets sent arduino #2, forwards data computer #2. using python's pyserial send data, serial on arduino communicate computer, , serial1 communication between 2 arduino's.

however, second arduino not receive data correct unless put sleeps in python code sends, data. is:

code: [select]
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. once comment out time.sleep(.005). second arduino doesn't read. 100% baud rates match, , more surprising doesn't work @ these slow speeds. can imagine, having put 5 milliseconds between each byte ruins speed.

here (basic) arduino code:
code: [select]


void setup()  
{
  // open serial communications , wait port open:
  serial.begin(2400);
serial1.begin(2400);

}

void loop() // run on , over
{
  if (serial1.available())
    serial.write(serial1.read());
  if (serial.available())
    serial1.write(serial.read());
  
    
}

the python code loops faster arduino can send .

@2400 baud every char takes 4 milliseconds arrive.


Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Arduino Serial with PySerial?


arduino

Comments