Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pySerial - missed messages
#1
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.
Reply
#2
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.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  User serial/pyserial to send messages to an arudino via terminal manually bkapadia 2 2,760 Mar-10-2021, 11:26 AM
Last Post: Larz60+
  Pylint/pyflakes/flake8 missed AttributeError elyoni 2 1,877 Feb-19-2020, 07:36 AM
Last Post: elyoni
  logging messages ahead of print messages vindo 6 3,232 Jun-18-2019, 02:45 PM
Last Post: vindo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020