]> git.gir.st - RaspiRouter.git/blob - usr/bin/dispchar
updated README.md
[RaspiRouter.git] / usr / bin / dispchar
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 (0x0c, DISPLAY_CMD) #cursor off
36 if len (sys.argv) > 1:
37 message = sys.argv[1]
38 lcd_byte(ord(message[0]),DISPLAY_CHR)
39 lcd_byte (0x10, DISPLAY_CMD) #shift curpos left
40 #mychar = ord(sys.argv[1])
41 #print (mychar)
42 #lcd_byte (mychar, 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) #advance cursor
54 #lcd_byte(0x01,DISPLAY_CMD) #clear display
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