]> git.gir.st - RaspiRouter.git/blob - usr/bin/disp
updated README.md
[RaspiRouter.git] / usr / bin / disp
1 #!/usr/bin/python
2
3 # modified version if this tutorial's demo script (German):
4 # http://www.schnatterente.net/technik/raspberry-pi-32-zeichen-hitachi-hd44780-display
5
6 import time
7 import sys
8 import RPi.GPIO as GPIO
9 GPIO.setwarnings(False)
10
11 # Zuordnung der GPIO Pins (ggf. anpassen)
12 DISPLAY_RS = 7
13 DISPLAY_E = 8
14 DISPLAY_DATA4 = 25
15 DISPLAY_DATA5 = 24
16 DISPLAY_DATA6 = 23
17 DISPLAY_DATA7 = 18
18
19 DISPLAY_WIDTH = 16 # Zeichen je Zeile (colums per line)
20 DISPLAY_LINE_1 = 0x80 # Adresse der ersten Display Zeile
21 DISPLAY_LINE_2 = 0xC0
22
23 DISPLAY_CHR = True
24 DISPLAY_CMD = False
25 E_PULSE = 0.0005
26 E_DELAY = 0.0005
27
28 def main():
29 GPIO.setmode(GPIO.BCM)
30 GPIO.setup(DISPLAY_E, GPIO.OUT)
31 GPIO.setup(DISPLAY_RS, GPIO.OUT)
32 GPIO.setup(DISPLAY_DATA4, GPIO.OUT)
33 GPIO.setup(DISPLAY_DATA5, GPIO.OUT)
34 GPIO.setup(DISPLAY_DATA6, GPIO.OUT)
35 GPIO.setup(DISPLAY_DATA7, GPIO.OUT)
36
37 display_init()
38
39 # my screen is internally wired as a 2x8, so that's that bodge.
40 if len (sys.argv) > 1:
41 mystring = sys.argv[1].ljust (8, " ")
42 lcd_byte (DISPLAY_LINE_1, DISPLAY_CMD)
43 lcd_string (mystring[0:8])
44 lcd_byte (DISPLAY_LINE_2, DISPLAY_CMD)
45 lcd_string (mystring[8:16])
46
47
48 def display_init():
49 lcd_byte(0x33,DISPLAY_CMD)
50 lcd_byte(0x32,DISPLAY_CMD)
51 lcd_byte(0x28,DISPLAY_CMD)
52 lcd_byte(0x0C,DISPLAY_CMD)
53 lcd_byte(0x06,DISPLAY_CMD)
54 lcd_byte(0x01,DISPLAY_CMD)
55
56 def lcd_string(message):
57 message = message.ljust(DISPLAY_WIDTH," ")
58 for i in range(DISPLAY_WIDTH):
59 lcd_byte(ord(message[i]),DISPLAY_CHR)
60
61 def lcd_byte(bits, mode):
62 GPIO.output(DISPLAY_RS, mode)
63 GPIO.output(DISPLAY_DATA4, False)
64 GPIO.output(DISPLAY_DATA5, False)
65 GPIO.output(DISPLAY_DATA6, False)
66 GPIO.output(DISPLAY_DATA7, False)
67 if bits&0x10==0x10:
68 GPIO.output(DISPLAY_DATA4, True)
69 if bits&0x20==0x20:
70 GPIO.output(DISPLAY_DATA5, True)
71 if bits&0x40==0x40:
72 GPIO.output(DISPLAY_DATA6, True)
73 if bits&0x80==0x80:
74 GPIO.output(DISPLAY_DATA7, True)
75 time.sleep(E_DELAY)
76 GPIO.output(DISPLAY_E, True)
77 time.sleep(E_PULSE)
78 GPIO.output(DISPLAY_E, False)
79 time.sleep(E_DELAY)
80 GPIO.output(DISPLAY_DATA4, False)
81 GPIO.output(DISPLAY_DATA5, False)
82 GPIO.output(DISPLAY_DATA6, False)
83 GPIO.output(DISPLAY_DATA7, False)
84 if bits&0x01==0x01:
85 GPIO.output(DISPLAY_DATA4, True)
86 if bits&0x02==0x02:
87 GPIO.output(DISPLAY_DATA5, True)
88 if bits&0x04==0x04:
89 GPIO.output(DISPLAY_DATA6, True)
90 if bits&0x08==0x08:
91 GPIO.output(DISPLAY_DATA7, True)
92 time.sleep(E_DELAY)
93 GPIO.output(DISPLAY_E, True)
94 time.sleep(E_PULSE)
95 GPIO.output(DISPLAY_E, False)
96 time.sleep(E_DELAY)
97
98 if __name__ == '__main__':
99 main()
100
Imprint / Impressum