I am attempting to use pyserial to read the data from an arduino on Windows.
import serial
device = 'COM3'
baud = 9600
with serial.Serial(device,baud, timeout = 0) as serialPort:
while True:
line = serialPort.readline()
line = line.decode("utf-8")
if line:
print(line)
void setup() {
Serial.begin(9600);
}
void loop() {
int x = 12;
int y = 34;
int z = 56;
Serial.print(x);
Serial.print(',');
Serial.print(y);
Serial.print(',');
Serial.println(z);
}
The arduino Serial monitor is outputting exactly what I expect.
12,34,56
12,34,56
12,34,56
The python script on the other hand is outputting:
1
2,34
,56
12,
34,5
6
1
2,34
,56
12,
34,5
6
I have tried delaying the output from the Arduino, I have tried making a buffer in the arduino code and only output the data when the buffer was full, thinking maybe python would have time to read it correctly.
I have see numerous people on this site and others make similar code and suggest it works fine, I however cannot get coherent data from python. Anyone know my issue?