基本說明:
HS420361K-32可以視為4組5101BS所組成,除了共有4跟針腳分別控制四位數字,顯示LED二極體的電壓控制不大相同外,基本原理與5101BS是相同的。HS420361K-32針腳設計,每次更新只能對其中一位數進行更新,所以讓四位數字同時有數值是不可能的。必須藉由視覺殘留原理,透過不停更新四組顯示值來達成視覺上的四位數值顯示。
接線:
硬體設計可以參閱ref.1 4.1,這邊透過74HC595來控制顯示器訊號,4組顯示部份直接連接在RPi的GPIO上
74HC595晶片
QB | pin 6 | VCC | 3.3V | |
QC | pin 4 | QA | pin 7 | |
QD | pin 2 | SER | GPIO#16 | |
QE | pin 1 | OE | GND | |
QF | pin 9 | RCLK | GPIO#20 | |
QG | pin 10 | SRCLK | GPIO#21 | |
QH | pin 5 | SRCLR | 3.3V | |
GND | GND | QH' |
HS420361K-32顯示器
pin 1 | QE | pin 12 | GPIO#2 | |
pin 2 | QD | pin 11 | QA | |
pin 3 | QH | pin 10 | QF | |
pin 4 | QC | pin 9 | GPIO#3 | |
pin 5 | QG | pin 8 | GPIO#4 | |
pin 6 | GPIO#17 | pin 7 | QB |
Python程式:
import RPi.GPIO as GPIO
import time
SRCLK = 21
RCLK = 20
SER = 16
D1 = 2
D2 = 3
D3 = 4
D4 = 17
def init():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
GPIO.setup(SRCLK, GPIO.OUT)
GPIO.setup(RCLK, GPIO.OUT)
GPIO.setup(SER, GPIO.OUT)
GPIO.output(SER, GPIO.LOW)
GPIO.output(SRCLK, GPIO.LOW)
GPIO.output(RCLK, GPIO.LOW)
GPIO.setup(D1, GPIO.OUT)
GPIO.setup(D2, GPIO.OUT)
GPIO.setup(D3, GPIO.OUT)
GPIO.setup(D4, GPIO.OUT)
GPIO.output(D1, GPIO.HIGH)
GPIO.output(D2, GPIO.HIGH)
GPIO.output(D3, GPIO.HIGH)
GPIO.output(D4, GPIO.HIGH)
def display(frag):
for v in frag:
if v:
GPIO.output(SER, GPIO.HIGH)
else:
GPIO.output(SER, GPIO.LOW)
GPIO.output(SRCLK, GPIO.HIGH)
GPIO.output(SRCLK, GPIO.LOW)
GPIO.output(RCLK, GPIO.HIGH)
GPIO.output(RCLK, GPIO.LOW)
def display4Digits(number):
num = {' ': [0, 0, 0, 0, 0, 0, 0, 0],
'0': [0, 0, 1, 1, 1, 1, 1, 1],
'1': [0, 0, 0, 0, 0, 1, 1, 0],
'2': [0, 1, 0, 1, 1, 0, 1, 1],
'3': [0, 1, 0, 0, 1, 1, 1, 1],
'4': [0, 1, 1, 0, 0, 1, 1, 0],
'5': [0, 1, 1, 0, 1, 1, 0, 1],
'6': [0, 1, 1, 1, 1, 1, 0, 1],
'7': [0, 0, 0, 0, 0, 1, 1, 1],
'8': [0, 1, 1, 1, 1, 1, 1, 1],
'9': [0, 1, 1, 0, 1, 1, 1, 1],
'E': [0, 1, 1, 1, 1, 0, 0, 1],
'F': [0, 1, 1, 1, 0, 0, 0, 1]}
digits = {1: D1, 2: D2, 3: D3, 4: D4}
for t in range(100):
for i in range(4):
d = number[i]
display(num[d])
GPIO.output(digits[i+1], GPIO.LOW)
time.sleep(0.01)
GPIO.output(digits[i+1], GPIO.HIGH)
init()
display4Digits("89EF")
GPIO.cleanup()
參考文件:
2. https://theokelo.co.ke/how-to-get-your-hs420361k-32-4-digit-7-segment-display-working-with-an-arduino/
沒有留言:
張貼留言