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.
also happens on Windows as well so RPI is not at fault
... maybe, but it does not exclude python problemsSerial.println()
from the Arduino code?"I was written in RPI"
and don't read it. Does it work if you readser
regularly?