]> git.gir.st - RaspiRouter.git/blob - usr/bin/dispprogress
first commit
[RaspiRouter.git] / usr / bin / dispprogress
1 #!/usr/bin/python
2 import time
3 import sys
4 import RPi.GPIO as GPIO
5 GPIO.setwarnings(False)
6
7 # Zuordnung der GPIO Pins (ggf. anpassen)
8 DISPLAY_RS = 7
9 DISPLAY_E = 8
10 DISPLAY_DATA4 = 25
11 DISPLAY_DATA5 = 24
12 DISPLAY_DATA6 = 23
13 DISPLAY_DATA7 = 18
14
15 DISPLAY_WIDTH = 16 # Zeichen je Zeile
16 DISPLAY_LINE_1 = 0x80 # Adresse der ersten Display Zeile
17 DISPLAY_LINE_2 = 0xC0
18
19 DISPLAY_CHR = True
20 DISPLAY_CMD = False
21 E_PULSE = 0.0005
22 E_DELAY = 0.0005
23
24 def main():
25 GPIO.setmode(GPIO.BCM)
26 GPIO.setup(DISPLAY_E, GPIO.OUT)
27 GPIO.setup(DISPLAY_RS, GPIO.OUT)
28 GPIO.setup(DISPLAY_DATA4, GPIO.OUT)
29 GPIO.setup(DISPLAY_DATA5, GPIO.OUT)
30 GPIO.setup(DISPLAY_DATA6, GPIO.OUT)
31 GPIO.setup(DISPLAY_DATA7, GPIO.OUT)
32
33 display_init()
34
35 #lcd_byte(DISPLAY_LINE_1, DISPLAY_CMD)
36 #lcd_string("Luftinte")
37 #lcd_byte(DISPLAY_LINE_2, DISPLAY_CMD)
38 #lcd_string("rnet!")
39 while (1):
40 lcd_byte(0x0e, DISPLAY_CMD)#enable cursor
41 lcd_byte(0x02, DISPLAY_CMD)#put cursor to the left
42 lcd_byte(DISPLAY_LINE_1 - 1, DISPLAY_CMD)
43 for i in range (0, 8):
44 lcd_byte (0x14, DISPLAY_CMD)#advance cursor
45 time.sleep (0.5)
46 lcd_byte(DISPLAY_LINE_2 - 1, DISPLAY_CMD)
47 for i in range (0,8):
48 lcd_byte(0x14, DISPLAY_CMD)
49 time.sleep(0.5)
50 break
51 lcd_byte(0x0f, DISPLAY_CMD) #cursor blinky (als lade-anim)
52 lcd_byte (33, DISPLAY_CMD)
53
54 #if len (sys.argv) > 1:
55 # mystring = sys.argv[1].ljust (8, " ")
56 # lcd_byte (DISPLAY_LINE_1, DISPLAY_CMD)
57 # lcd_string (mystring[0:8])
58 # lcd_byte (DISPLAY_LINE_2, DISPLAY_CMD)
59 # lcd_string (mystring[8:16])
60
61
62 def display_init():
63 lcd_byte(0x33,DISPLAY_CMD)
64 lcd_byte(0x32,DISPLAY_CMD)
65 lcd_byte(0x28,DISPLAY_CMD)
66 #lcd_byte(0x0C,DISPLAY_CMD) #cursor off
67 lcd_byte(0x06,DISPLAY_CMD)
68 #lcd_byte(0x01,DISPLAY_CMD) #clear
69
70 def lcd_string(message):
71 message = message.ljust(DISPLAY_WIDTH," ")
72 for i in range(DISPLAY_WIDTH):
73 lcd_byte(ord(message[i]),DISPLAY_CHR)
74
75 def lcd_byte(bits, mode):
76 GPIO.output(DISPLAY_RS, mode)
77 GPIO.output(DISPLAY_DATA4, False)
78 GPIO.output(DISPLAY_DATA5, False)
79 GPIO.output(DISPLAY_DATA6, False)
80 GPIO.output(DISPLAY_DATA7, False)
81 if bits&0x10==0x10:
82 GPIO.output(DISPLAY_DATA4, True)
83 if bits&0x20==0x20:
84 GPIO.output(DISPLAY_DATA5, True)
85 if bits&0x40==0x40:
86 GPIO.output(DISPLAY_DATA6, True)
87 if bits&0x80==0x80:
88 GPIO.output(DISPLAY_DATA7, True)
89 time.sleep(E_DELAY)
90 GPIO.output(DISPLAY_E, True)
91 time.sleep(E_PULSE)
92 GPIO.output(DISPLAY_E, False)
93 time.sleep(E_DELAY)
94 GPIO.output(DISPLAY_DATA4, False)
95 GPIO.output(DISPLAY_DATA5, False)
96 GPIO.output(DISPLAY_DATA6, False)
97 GPIO.output(DISPLAY_DATA7, False)
98 if bits&0x01==0x01:
99 GPIO.output(DISPLAY_DATA4, True)
100 if bits&0x02==0x02:
101 GPIO.output(DISPLAY_DATA5, True)
102 if bits&0x04==0x04:
103 GPIO.output(DISPLAY_DATA6, True)
104 if bits&0x08==0x08:
105 GPIO.output(DISPLAY_DATA7, True)
106 time.sleep(E_DELAY)
107 GPIO.output(DISPLAY_E, True)
108 time.sleep(E_PULSE)
109 GPIO.output(DISPLAY_E, False)
110 time.sleep(E_DELAY)
111
112 if __name__ == '__main__':
113 main()
114
Imprint / Impressum