Skip to content

Instantly share code, notes, and snippets.

@dizcza
Created April 16, 2019 18:18
Show Gist options
  • Save dizcza/cc52aea5ef98f8eba725a5793845c4c4 to your computer and use it in GitHub Desktop.
Save dizcza/cc52aea5ef98f8eba725a5793845c4c4 to your computer and use it in GitHub Desktop.
Capture UART messages
import time
import serial
ser = serial.Serial(
port='/dev/ttyACM0', # dmesg | grep tty
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1,
)
if not ser.isOpen():
ser.open()
# Flush before receiving or sending any data
ser.flushInput()
ser.flushOutput()
while 1:
x = ser.readline().decode('utf-8').rstrip('\r\n')
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment