How to use pyserial to write two separate message? I'm using pyserial to communicate with my arduino. I set up the connection and everything works fine. Now I have these two writing commands:
pyserial.write(&quot;conn&quot;.encode())
pyserial.write(&quot;mod1&quot;.encode())

On my arduino:
while (!Serial.available());
String s = Serial.readString();
if (s==&quot;conn&quot;) do...;
if (s==&quot;mod1&quot;) do...;

The problem is that none of the if statements are true because s becomes &quot;connmod1&quot;, because the messages are sent almost at the same time I guess. I know I could use some delimiter to split the string, but I would like to know what the convenient solution might be?
If you want a quick, cheap, and easy solution, you could just use sleep() in your Python script to put a delay between the commands. This obviously isn't a perfect solution, but it's not difficult to implement.
Or, like you said, you could use a delimiter. It's not as easy to implement, but it'll work better.
If you go the delimiter rout, you'll probably need to use Serial.read() instead of Serial.readString(). That way you can examine characters individually as they come in. You can store your characters in a String or char array until you detect your delimiter and then execute your command.
Hope that helps!