I am writing a program in Python (using PySerial) that needs to read data from the Arduino quickly. For this reason I have set the serial timeout to 0.01 seconds. (Baud rate is 115k) If I don't set the timeout this low I run into issues with there being a noticeable delay between sending a command and receiving a reply. As long as I have the timeout set low enough then its all fine, but the downside is that I have a message print out when I first connect to the Arduino to confirm that it has indeed connected. (Message reads "Connected" once the serial connection has been established in void setup)

Okay, the problem: If I don't have the timeout set to 0.9 seconds or higher, the initial 'connected' message gets cut off. Of course if I have it set that high I get the issues I first described.

I'm looking for a way to keep the timeout very low but also get this first connected message when the void setup runs. Is there a way to have my cake and eat it too?

I did try starting with the timeout set to 1 second and once the connected message prints out change it to 0.01 seconds, but it just kept giving me an error.

Any help would be appreciated.

  • 3
    If you can send a character to mean “end of message” (typically CR and/or LF), then you will not need timeouts. – Edgar Bonet Apr 13 at 16:05
  • you can always check available() or change the timeout. but I am not sure if I understand what you do – Juraj Apr 13 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.