-
Notifications
You must be signed in to change notification settings - Fork 0
/
retro.py
executable file
·209 lines (182 loc) · 5.95 KB
/
retro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/python
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 background=dark
'''
Scroll message on a HP QDSP-6064 Bubble display using an
SN74HC595 Shift Register and 7 GPIO pins on a RaspberyPi
Or use a second shift register to control the cathodes for
the digits with -ds SR
GPIO pins are by BCM
First Shift register 74HC595N used to select segments
74HC595 Pin
8 Connected to ground
9 Serial Data Output to pin 14 of next shift register if used
10 Master Reset (active LOW) so kept high +3V3
11 Shift Register Clock input GPIO17 on Pi
12 Storage Register Clock Input GPIO27 on Pi
13 Output Enable (active LOW) so kept low with GND
14 Serial Data Input GPIO22 on Pi
16 +3V3
Output of shift register to bubble display pin number
[wiring info]
74HC595 Pin 74HC595 Output QDSP-6064 Pin
15 Q0 2
1 Q1 3
2 Q2 7
3 Q3 8
4 Q4 9
5 Q5 11
6 Q6 12
7 Q7 5
GPIO to bubble display to select digit
G5 1
G6 10
G13 4
G19 6
Alternatively use another shift register
74HC595 Pin 74HC595 Output QDSP-6064 Pin
15 Q0 1
1 Q1 10
2 Q2 4
3 Q3 6
Drive another bubble display with the rest of the outputs of the second
shift register
74HC595 Pin 74HC595 Output QDSP-6064 Pin
4 Q4 1
5 Q5 10
6 Q6 4
7 Q7 6
GPIO to shift register
G17 11 Shift Register Clock Input
G27 12 Storage Register Clock Input
G22 14 Serial Data Input
Output of shift register to segment of digit
74HC595 Pin Segment QDSP-6064 Pin
0 dot DP 5
1 top A 12
2 top right B 11
3 top left F 9
4 bottom D 8
5 middle G 7
6 bottom right C 3
7 bottom left E 2
'''
import RPi.GPIO as GPIO
import time
import threading
import atexit
import signal
import argparse
font={
'a':0b11101110,
'b':0b11111000,
'c':0b10011010,
'd':0b11110100,
'e':0b10111010,
'f':0b10101010,
'g':0b01111110,
'h':0b11101100,
'i':0b10001000,
'j':0b11010100,
'k':0b11101100,
'l':0b10011000,
'm':0b11000010,
'n':0b11100000,
'o':0b11011110,
'p':0b10101110,
'q':0b01101110,
'r':0b10100000,
's':0b01111010,
't':0b10111000,
'u':0b11011100,
'v':0b11010000,
'w':0b00011100,
'x':0b11101100,
'y':0b01111100,
'z':0b10110110,
'0':0b11011110,
'1':0b01000100,
'2':0b10110110,
'3':0b01110110,
'4':0b01101100,
'5':0b01111010,
'6':0b11111010,
'7':0b01000110,
'8':0b11111110,
'9':0b01111110,
'.':0b00000001,
' ':0b00000000,
}
message='playing with a retro bubble display on a raspberry pi 0123456789 ...'
word='playing.'
PIN_DATA=22
PIN_LATCH=27
PIN_CLOCK=17
PIN_DIGIT=[5,6,13,19]
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIN_DATA,GPIO.OUT)
GPIO.setup(PIN_LATCH,GPIO.OUT)
GPIO.setup(PIN_CLOCK,GPIO.OUT)
parser=argparse.ArgumentParser(description='Bubble Display Scroller')
parser.add_argument("-ds",help="Digit Select GPIO [G] or Shift Register [SR]",
choices=["G","SR"],default="G")
parser.add_argument("--message","-m",help="Message to scroll",default=message)
parser.add_argument("--digits","-d",help="How many digits 4 or 8",default=4,
choices=[4,8],type=int)
parser.add_argument("--firstMessage","-fm",help="message displayed before scrolling"
,default="0bubble0")
args=parser.parse_args()
#message=('{:^'+str(args.digits)+'}').format(args.message)
#print'{:^'+str(args.digits)+'}'
#print ('{:^'+str(args.digits)+'}').format(args.message)
message=args.message.center(len(args.message)+2*(1+args.digits),' ')
word=args.firstMessage
print(args.ds)
for i in PIN_DIGIT:
GPIO.setup(i,GPIO.OUT,initial=GPIO.HIGH)
def cleanup( ):
print('Terminating')
GPIO.cleanup()
atexit.register(cleanup)
signal.signal(signal.SIGTERM,cleanup)
def set_segments(byte):
#print(bin(byte))
GPIO.output(PIN_LATCH, 0)
for x in range(8):
GPIO.output(PIN_DATA, (byte >> x) & 1)
GPIO.output(PIN_CLOCK, 1)
GPIO.output(PIN_CLOCK, 0)
#GPIO.output(PIN_LATCH, 1)
def set_digit(d):
GPIO.output(PIN_DIGIT[d],0)
def clear_digit():
for i in PIN_DIGIT:
GPIO.output(i,1)
def show_string(s):
for l in range(args.digits):
if args.ds=='G':
clear_digit()
set_segments(font[s[l]])
GPIO.output(PIN_LATCH,1)
set_digit(l)
time.sleep(0.0001)
else:
set_segments(~(128>>l) & 255)
set_segments(font[s[l]])
GPIO.output(PIN_LATCH,1)
time.sleep(0.0001)
class display_thread (threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
show_string(word)
myThread=display_thread()
myThread.start()
time.sleep(5)
try:
while True:
for x in range(len(message)-args.digits):
word=message[x:]
time.sleep(0.2)
finally:
cleanup()