Issue
I have a question when I tried to receive and read the data from Arduino nano to Python (in raspberry pi), where some data seems to loss like:
b',972.63,0,10.00\n'
b'0.00,0,10.00\n'
b'\n'
b'2.62,2150.54,0,10.00\n'
b'\n'
b'61.88,2600.20,0,10.00\n'
b'\n'
b'\n'
b'13.29,1422.29,0,10.00\n'
b'50.24,3396.87,0,10.00\n'
And my python code is
import serial
serial_port = '/dev/ttyUSB0'
baud_rate = 1000000
while True:
ser = serial.Serial(serial_port, baud_rate, timeout=1)
data = ser.readline()
print(data)
And I checked the serial monitor in Arduino IDE, and didn't find any problems there. Can I ask is this issue a common situation or how can I avoid this? Thank you in advance.
Solution
You don't need to initialize serial object every time in a loop,
try move ser = serial.Serial(...)
out of while
loop, like
ser = serial.Serial(...)
while True:
data = ser.readline()
print(data)
Answered By - balun Answer Checked By - Clifford M. (WPSolving Volunteer)