# -*- coding: iso-8859-1 -*- import time import RPi.GPIO as GPIO class LCD: # Zuordnung der GPIO Pins (ggf. anpassen) def __init__(self,rs=7,e=8,d4=25,d5=24,d6=23,d7=18): self.DISPLAY_RS = rs self.DISPLAY_E = e self.DISPLAY_DATA4 = d4 self.DISPLAY_DATA5 = d5 self.DISPLAY_DATA6 = d6 self.DISPLAY_DATA7 = d7 self.DISPLAY_WIDTH = 16 # Zeichen je Zeile self.DISPLAY_LINE_1 = 0x80 # Adresse der ersten Display Zeile self.DISPLAY_LINE_2 = 0xC0 # Adresse der zweiten Display Zeile self.DISPLAY_CHR = True self.DISPLAY_CMD = False self.E_PULSE = 0.00005 self.E_DELAY = 0.00005 def display_init(self): self.lcd_byte(0x33,self.DISPLAY_CMD) self.lcd_byte(0x32,self.DISPLAY_CMD) self.lcd_byte(0x28,self.DISPLAY_CMD) self.lcd_byte(0x0C,self.DISPLAY_CMD) self.lcd_byte(0x06,self.DISPLAY_CMD) self.lcd_byte(0x01,self.DISPLAY_CMD) def goto_line(self, line): if line == 1: self.lcd_byte(self.DISPLAY_LINE_1, self.DISPLAY_CMD) else: self.lcd_byte(self.DISPLAY_LINE_2, self.DISPLAY_CMD) def lcd_string(self,message): message = message.ljust(self.DISPLAY_WIDTH," ") for i in range(self.DISPLAY_WIDTH): self.lcd_byte(ord(message[i]),self.DISPLAY_CHR) def lcd_byte(self,bits, mode): GPIO.output(self.DISPLAY_RS, mode) GPIO.output(self.DISPLAY_DATA4, False) GPIO.output(self.DISPLAY_DATA5, False) GPIO.output(self.DISPLAY_DATA6, False) GPIO.output(self.DISPLAY_DATA7, False) if bits&0x10==0x10: GPIO.output(self.DISPLAY_DATA4, True) if bits&0x20==0x20: GPIO.output(self.DISPLAY_DATA5, True) if bits&0x40==0x40: GPIO.output(self.DISPLAY_DATA6, True) if bits&0x80==0x80: GPIO.output(self.DISPLAY_DATA7, True) time.sleep(self.E_DELAY) GPIO.output(self.DISPLAY_E, True) time.sleep(self.E_PULSE) GPIO.output(self.DISPLAY_E, False) time.sleep(self.E_DELAY) GPIO.output(self.DISPLAY_DATA4, False) GPIO.output(self.DISPLAY_DATA5, False) GPIO.output(self.DISPLAY_DATA6, False) GPIO.output(self.DISPLAY_DATA7, False) if bits&0x01==0x01: GPIO.output(self.DISPLAY_DATA4, True) if bits&0x02==0x02: GPIO.output(self.DISPLAY_DATA5, True) if bits&0x04==0x04: GPIO.output(self.DISPLAY_DATA6, True) if bits&0x08==0x08: GPIO.output(self.DISPLAY_DATA7, True) time.sleep(self.E_DELAY) GPIO.output(self.DISPLAY_E, True) time.sleep(self.E_PULSE) GPIO.output(self.DISPLAY_E, False) time.sleep(self.E_DELAY)