Skip to content

Instantly share code, notes, and snippets.

@mikbuch
Created March 6, 2019 00:11
Show Gist options
  • Save mikbuch/9840a146df896abd66ba9f8811779516 to your computer and use it in GitHub Desktop.
Save mikbuch/9840a146df896abd66ba9f8811779516 to your computer and use it in GitHub Desktop.
import serial
# Source: https://pyserial.readthedocs.io/en/latest/shortintro.html#opening-serial-ports
# Additional info:
# * you have to install pyserial in order for this code to work, command `sudo pip install serial`
# * run this script with sudo: `sudo python read_serial.py`
with serial.Serial('/dev/ttyUSB0', 9600, timeout=1) as ser:
while True:
# read a '\n' terminated line
line = ser.readline()
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment