Read from serial port
suggest changeInitialize serial device
import serial
#Serial takes two parameters: serial device and baudrate
ser = serial.Serial('/dev/ttyUSB0', 9600)
to read a single byte from the serial device
data = ser.read()
to read a given number of bytes from the serial device
data = ser.read(size=5)
to read one line from the serial device.
data = ser.readline()
to read the data from the serial device while something is being written over it.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents