Skip to content

Instantly share code, notes, and snippets.

@vvzen
Created March 21, 2018 15:26
Show Gist options
  • Save vvzen/4a9e9d44e973f0b1e46115cadf60d3d5 to your computer and use it in GitHub Desktop.
Save vvzen/4a9e9d44e973f0b1e46115cadf60d3d5 to your computer and use it in GitHub Desktop.
import serial
import re
import Adafruit_CharLCD as LCD
# LCD STUFF
lcd_rs = 25
lcd_en = 24
lcd_d4 = 23
lcd_d5 = 17
lcd_d6 = 18
lcd_d7 = 22
lcd_backlight = 4
lcd_columns = 16
lcd_rows = 2
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight)
# communication stuff
ser = serial.Serial(
port="/dev/ttyUSB0",
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
display_regex = r"d:\w+"
while True:
current_message = ser.read()
# if we get the ready message from the udoo
# we know the connection is established, so then just print it to the display
if current_message == "udooready":
lcd.clear()
lcd.message("udoo ready")
lcd.set_cursor(0, 1)
lcd.message("pi ready")
# if a message starts with d: , send this message to the lcd
elif re.match(display_regex, current_message):
lcd.clear()
lcd.message(current_message[2:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment