I'm trying to write something to Serial with Python and read it in Arduino so Arduino will know my Python program is still alive. But the Pyserial serial.write() function doesn't seem to work properly?
I saw some discussions about this, and possible solution being letting some time pass after starting the serial connection and doing the write().
I tried it.. but doesnt work very well still.
import serial
import time
arduinoSerialData = serial.Serial('com6', 9600)
time.sleep(1)
while True:
arduinoSerialData.write('AAA')
arduinoSerialData.flush()
sleep(0.5)
And in Arduino I have this code:
void loop() {
if (Serial.readString().startsWith("AAA")) {
digitalWrite(7, LOW);
} else {
digitalWrite(7, HIGH);
}
delay(500);
I'm hoping I'm doing something wrong in the Arduino code and its not an PySerial oddity again.
But seeing how it works fine in the console and not when executing a file I dont know....
Also sorry about the previosu topic, I have a terrible fever and my brain was malfunctioning.