user82129: I'm having issues with Arduino and RPI3 serial communication, it'll become unresponsive after a little time. Tried increasing BAUD rate and same issue, also happens on Windows as well so RPI is not at fault, and even after increasing the delay the hang still happens.
RPI3 python code
import serial
import time

if __name__ == '__main__':
  ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1, writeTimeout=0)
  ser.flush()
  last = "on\n"

  while True:
    last = "on\n" if last == "off\n" else "off\n"
    ser.write(last.encode())
    print(last)
    time.sleep(0.5)

Arduino code
#define BAUD_RATE 115200
const int LED_PIN = 8;
String command;

void setup() {
  Serial.begin(BAUD_RATE);
  pinMode(LED_PIN, OUTPUT);
  delay(100);
}

void loop() {
  Serial.println("I was written in RPI");

  if (Serial.available()) {
    command = Serial.readStringUntil('\n');

    if (command.equals("on")) {
      digitalWrite(LED_PIN, HIGH);
    } else if (command.equals("off")) {
      digitalWrite(LED_PIN, LOW);
    }
  }

  delay(50);
}

after less than a minute I'll get this exception from python
BlockingIOError: [Errno 11] Resource temporarily unavailable
The Arduino TX and RX led's stay on when it becomes unresponsive rather than flashing like it normally does.

user60431: You are flooding the RPi/PC with "I was written in RPI" and don't read it. It will work if you read ser regularly.
On the delays: A message over a serial line has a transmission time, in your case 20 characters at 115200 baud from Arduino to RPi/PC. With the common 8n1 protocol, characters are sent at 11520 per second. With 20 characters this will take nearly 0.002 seconds, or 2 ms. The receiver needs a smaller delay than the sender to avoid overflows.
If the Arduino were using the USB directly (AFAIK it does not, between its USB interface and the actual AVR is a "real" serial line), the baudrate does not matter. A virtual serial line over USB is always really fast, independent of the announced baudrate. I once used 921600 baud with success. ;-) The baudrate is only used if a real serial line is involved.

82129: <p>I'm having issues with Arduino and RPI3 serial communication, it'll become unresponsive after a little time. Tried increasing BAUD rate and same issue, also happens on Windows as well so RPI is not at fault, and even after increasing the <code>delay</code> the hang still happens.</p>
<p>RPI3 python code</p>
<pre class="lang-python prettyprint-override"><code>import serial
import time

if __name__ == '__main__':
  ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1, writeTimeout=0)
  ser.flush()
  last = &quot;on\n&quot;

  while True:
    last = &quot;on\n&quot; if last == &quot;off\n&quot; else &quot;off\n&quot;
    ser.write(last.encode())
    print(last)
    time.sleep(0.5)
</code></pre>
<p>Arduino code</p>
<pre class="lang-cpp prettyprint-override"><code>#define BAUD_RATE 115200
const int LED_PIN = 8;
String command;

void setup() {
  Serial.begin(BAUD_RATE);
  pinMode(LED_PIN, OUTPUT);
  delay(100);
}

void loop() {
  Serial.println(&quot;I was written in RPI&quot;);

  if (Serial.available()) {
    command = Serial.readStringUntil('\n');

    if (command.equals(&quot;on&quot;)) {
      digitalWrite(LED_PIN, HIGH);
    } else if (command.equals(&quot;off&quot;)) {
      digitalWrite(LED_PIN, LOW);
    }
  }

  delay(50);
}
</code></pre>
<p>after less than a minute I'll get this exception from python</p>
<p><code>BlockingIOError: [Errno 11] Resource temporarily unavailable</code></p>
<p>The Arduino TX and RX led's stay on when it becomes unresponsive rather than flashing like it normally does.</p>
 60431: <p>You are flooding the RPi/PC with <code>&quot;I was written in RPI&quot;</code> and don't read it. It will work if you read <code>ser</code> regularly.</p>
<p>On the delays: A message over a serial line has a transmission time, in your case 20 characters at 115200 baud from Arduino to RPi/PC. With the common 8n1 protocol, characters are sent at 11520 per second. With 20 characters this will take nearly 0.002 seconds, or 2 ms. The receiver needs a smaller delay than the sender to avoid overflows.</p>
<p>If the Arduino were using the USB directly (AFAIK it does not, between its USB interface and the actual AVR is a &quot;real&quot; serial line), the baudrate does not matter. A virtual serial line over USB is always really fast, independent of the announced baudrate. I once used 921600 baud with success. ;-) The baudrate is only used if a real serial line is involved.</p>
