Python Forum

Full Version: pySerial - missed messages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
ESP32 is sending data via USB do desktop with Ubuntu 20.04 (at the end script will be used on RPI4).
Yesterday it was working, today not.

def read():
    port = '/dev/ttyUSB0'
    baudrate = 115200
    ser = serial.Serial(port, baudrate)
    data = ser.readline()
    text = data.decode(errors="ignore")
    return text
What serial monitor from arduino ide see:
Output:
x0.33 y0.76 z9.70 t0.19 x0.32 y0.73 z9.73 t0.19 x0.31 y0.74 z9.65 t0.19 ....
What is terminal output from script:
Output:
x0.27 z9.71 x0.26 z9.73 x0.29 z9.72 x0.29 z9.68 x0.28 z9.73 x0.28 z9.70 x0.28 z9.74 x0.20 z9.74 x0.33 z9.69 x0.29 z9.68 ....
The funniest thing is that it was working yesterday, today is not. What I'm doing wrong? I tried to set different timeout, as well as None, and many other parameters with no result.
I don't know what happens when you repeat this over and over on an already opened serial port.
ser = serial.Serial(port, baudrate)
Does this close the already open connection? If so, that would flush anything remaining in the read buffer. I would open the port once and read many times.
Can you post the section of serial output code of the ESP32 so that we can see what your python script should expect and if there is a better way to read it.