Raspberry PI 4 project 74HC595 with 8 LEDS
Raspberry PI 4 project 74HC595 with 8 LEDS
I have soldered the 74hc595 to a piece of vero board. I Also soldered the resistors and LEDs. I connect 3 signals to the raspberry pi GPIO signals, DATA (14), shift CLOCK (11) and the data latch (12).
The outputs q0-q7 are wired to an LED via a 330𝛀 𝒓𝒆𝒔𝒊𝒔𝒕𝒐𝒓python script
# FXV300 This script reads GPU temp
# and writes values to two TIL311 segment displays
# PIN 2 LATCH DATA INPUT B 0010
# PIN 3 LATCH DATA INPUT A 0001
# PIN 5 LATCH STROBE INPUT _[ ]_
# PIN 12 LATCH DATA INPUT D 1000
# PIN 13 LATCH DATA INPUT C 0100
import RPi.GPIO as gpio
import os
import time
import datetime
# import binascii
# this part sets up the GPIO pins as output
# The first value is the GPIO pin label,and the comment is the physical pin value
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(11, gpio.OUT) # Pin 23 - Serial Data 74HC595 Pin 14
gpio.setup(12, gpio.OUT) # Pin 32 - Data Clock 74HC595 Pin 11 SHCP shift register clock input
gpio.setup(13, gpio.OUT) # Pin 33 - Latch 74HC595 Pin 12 STCP storage register clock input
gpio.setup(25, gpio.OUT) # Pin 22 - TIL311 - Pin 5 Latch
while True:
def measure_temp():
temp = os.popen("vcgencmd measure_temp").readline()
return (temp.replace("temp=", ""))
x=measure_temp()
# print(x)
y=x[0] # 1st char of xx'c
z=x[1] #2nd char of xx'c
v1=ord(y)
v2=ord(z)
p = bin(v1)[0:]
q = bin(v2)[0:]
# print(p)
# print(q)
# print (v1), print(v2) # this is the ASCII value of the two numbers
# print (hex(ord(y)))
# print (hex(ord(z)))
from datetime import datetime
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print("Current Time =", current_time)
# First TIL311 showing 10s
gpio.output(25, gpio.LOW) # Data Latch set low
gpio.output(13, gpio.LOW) # Data Latch set low
# will send these 4 bits to TIL311 IC 1
if v2 == 48: # ascii48 hex 30 dec 0
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW) # bit3
gpio.output(12, gpio.HIGH)
# bit2
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit1
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit0
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
if v2 == 49: # ascii 49 hex 31 dec 1
# bit3
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit2
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit1
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit0
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
if v2 == 50: # ascii 50 hex 32 dec 2
# bit3
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit2
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit1
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit0
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
if v2 == 51: # ascii 51 hex 33 dec 3
# bit3
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit2
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit1
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit0
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
if v2 == 52: # ascii 52 hex 34 dec 4
# bit3
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit2
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit1
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit0
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
if v2 == 53: # ascii 53 hex 35 dec 5
# bit3
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit2
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit1
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit0
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
if v2 == 54: # ascii 54 hex 36 dec 6
# bit3
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit2
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit1
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit0
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
if v2 == 55: # ascii 55 hex 37 dec 7
# bit3
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit2
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit1
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit0
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
if v2 == 56: # ascii 56 hex 38 dec 8
# bit3
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit2
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit1
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit0
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
if v2 == 57: # ascii 57 hex 39 dec 9
# bit3
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit2
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit1
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit0
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# Next Nibble
if v1 == 48: # ascii48 hex 30 dec 0
# bit7
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit6
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit5
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit4
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
gpio.output(13, gpio.HIGH)
gpio.output(25, gpio.HIGH) #Data Latch
time.sleep(1.5)
if v1 == 49: # ascii 49 hex 31 dec 1
# bit7
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit6
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit5
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit4
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
gpio.output(13, gpio.HIGH)
gpio.output(25, gpio.HIGH) #Data Latch
time.sleep(1.5)
if v1 == 50: # ascii 50 hex 32 dec 2
# bit7
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit6
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit5
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit4
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
gpio.output(13, gpio.HIGH)
gpio.output(25, gpio.HIGH) #Data Latch
time.sleep(1.5)
if v1 == 51: # ascii 51 hex 33 dec 3
# bit7
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit6
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit5
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit4
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
gpio.output(13, gpio.HIGH)
gpio.output(25, gpio.HIGH) #Data Latch
time.sleep(1.5)
if v1 == 52: # ascii 52 hex 34 dec 4
# bit7
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit6
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit5
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit4
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
gpio.output(13, gpio.HIGH)
gpio.output(25, gpio.HIGH) #Data Latch
time.sleep(1.5)
if v1 == 53: # ascii 53 hex 35 dec 5
# bit7
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit6
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit5
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit4
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
gpio.output(13, gpio.HIGH)
gpio.output(25, gpio.HIGH) #Data Latch
time.sleep(1.5)
if v1 == 54: # ascii 54 hex 36 dec 6
# bit7
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit6
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit5
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit4
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
gpio.output(13, gpio.HIGH)
gpio.output(25, gpio.HIGH) #Data Latch
time.sleep(1.5)
if v1 == 55: # ascii 55 hex 37 dec 7
# bit7
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit6
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit5
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit4
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
gpio.output(13, gpio.HIGH)
gpio.output(25, gpio.HIGH) #Data Latch
time.sleep(1.5)
if v1 == 56: # ascii 56 hex 38 dec 8
# bit7
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH)
gpio.output(12, gpio.HIGH)
# bit6
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit5
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
# bit4
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW)
gpio.output(12, gpio.HIGH)
gpio.output(13, gpio.HIGH)
gpio.output(25, gpio.HIGH) #Data Latch
time.sleep(1.5)
if v1 == 57: # ascii 57 hex 39 dec 9
gpio.output(13, gpio.LOW)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH) # bit 7
gpio.output(12, gpio.HIGH)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW) # bit 6
gpio.output(12, gpio.HIGH)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.LOW) # bit 5
gpio.output(12, gpio.HIGH)
gpio.output(12, gpio.LOW)
gpio.output(11, gpio.HIGH) # bit4
gpio.output(12, gpio.HIGH)
gpio.output(13, gpio.HIGH) #Data Latch 74HC595
gpio.output(25, gpio.HIGH) #Data Latch TIL311 Latch
time.sleep(1.5)
if v1!= 20:
str1="CPU temp = "
str2=(x)
str=str1+str2
print (str)
TTL chips are easy to work with. They make ideal tools for many projects. Data sheets provide details how to use etc.....try for useful if you own a PI or Arduino
ReplyDelete