Created
April 16, 2019 18:18
-
-
Save dizcza/cc52aea5ef98f8eba725a5793845c4c4 to your computer and use it in GitHub Desktop.
Capture UART messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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