root@SpielzeugPI:~# cat lcd.sh #!/bin/bash cd /root o1="" o2="" while(true) do echo $(echo scale=1\;$(cat /run/t1)/1000|bc) > /run/line1 l1=$(cat /run/line1) l2=$(cat /run/line2) r=0 if test "$l1" != "$o1" then r=1 fi if test "$l2" != "$o2" then r=1 fi if test "$r" == "1" then ./hd44780_test.py "$l1" "$l2" o1="$l1" o2="$l2" fi sleep 1 done root@SpielzeugPI:~# cat hd44780_test.py #!/usr/bin/python import time,sys import RPi.GPIO as GPIO # Zuordnung der GPIO Pins (ggf. anpassen) LCD_RS = 4 LCD_E = 17 LCD_DATA4 = 18 LCD_DATA5 = 22 LCD_DATA6 = 23 LCD_DATA7 = 24 LCD_WIDTH = 24 # Zeichen je Zeile LCD_LINE_1 = 0x80 # Adresse der ersten Display Zeile LCD_LINE_2 = 0xC0 # Adresse der zweiten Display Zeile LCD_CHR = GPIO.HIGH LCD_CMD = GPIO.LOW E_PULSE = 0.0005 E_DELAY = 0.0005 def lcd_send_byte(bits, mode): # Pins auf LOW setzen GPIO.output(LCD_RS, mode) GPIO.output(LCD_DATA4, GPIO.LOW) GPIO.output(LCD_DATA5, GPIO.LOW) GPIO.output(LCD_DATA6, GPIO.LOW) GPIO.output(LCD_DATA7, GPIO.LOW) if bits & 0x10 == 0x10: GPIO.output(LCD_DATA4, GPIO.HIGH) if bits & 0x20 == 0x20: GPIO.output(LCD_DATA5, GPIO.HIGH) if bits & 0x40 == 0x40: GPIO.output(LCD_DATA6, GPIO.HIGH) if bits & 0x80 == 0x80: GPIO.output(LCD_DATA7, GPIO.HIGH) time.sleep(E_DELAY) GPIO.output(LCD_E, GPIO.HIGH) time.sleep(E_PULSE) GPIO.output(LCD_E, GPIO.LOW) time.sleep(E_DELAY) GPIO.output(LCD_DATA4, GPIO.LOW) GPIO.output(LCD_DATA5, GPIO.LOW) GPIO.output(LCD_DATA6, GPIO.LOW) GPIO.output(LCD_DATA7, GPIO.LOW) if bits&0x01==0x01: GPIO.output(LCD_DATA4, GPIO.HIGH) if bits&0x02==0x02: GPIO.output(LCD_DATA5, GPIO.HIGH) if bits&0x04==0x04: GPIO.output(LCD_DATA6, GPIO.HIGH) if bits&0x08==0x08: GPIO.output(LCD_DATA7, GPIO.HIGH) time.sleep(E_DELAY) GPIO.output(LCD_E, GPIO.HIGH) time.sleep(E_PULSE) GPIO.output(LCD_E, GPIO.LOW) time.sleep(E_DELAY) def display_init(): lcd_send_byte(0x33, LCD_CMD) lcd_send_byte(0x32, LCD_CMD) lcd_send_byte(0x28, LCD_CMD) lcd_send_byte(0x0C, LCD_CMD) lcd_send_byte(0x06, LCD_CMD) lcd_send_byte(0x01, LCD_CMD) def lcd_message(message): message = message.ljust(LCD_WIDTH," ") for i in range(LCD_WIDTH): lcd_send_byte(ord(message[i]),LCD_CHR) if __name__ == '__main__': # initialisieren GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(LCD_E, GPIO.OUT) GPIO.setup(LCD_RS, GPIO.OUT) GPIO.setup(LCD_DATA4, GPIO.OUT) GPIO.setup(LCD_DATA5, GPIO.OUT) GPIO.setup(LCD_DATA6, GPIO.OUT) GPIO.setup(LCD_DATA7, GPIO.OUT) display_init() lcd_send_byte(LCD_LINE_1, LCD_CMD) lcd_message(sys.argv[1]) lcd_send_byte(LCD_LINE_2, LCD_CMD) lcd_message(sys.argv[2]) root@SpielzeugPI:~# cat steuern.sh #!/bin/bash while(true) do t=$(t1) echo $t echo $t > /run/t1 if test "$t" -lt 23000 then relais 1 1 else relais 1 0 fi done