Chapter 13 74HC595 & LED Bar Graph
We have used LED bar graph to make a flowing water light, in which 10 GPIO ports of ESP8266 is occupied. More GPIO ports mean that more peripherals can be connected to ESP8266, so GPIO resource is very precious. Can we make flowing water light with less GPIO? In this chapter, we will learn a component, 74HC595, which can achieve the target.
Project 13.1 Flowing Water Light
Now let’s learn how to use the 74HC595 IC chip to make a flowing water light using less GPIO.
Component List
ESP8266 x1
|
USB cable |
Breadboard x1
|
|
LED Bar Graph x1
|
Jumper wire M/M x17 |
74HC595 x1
|
Resistor 220Ω x8 |
Circuit
Schematic diagram |
|
Hardware connection. If you need any support, please feel free to contact us via: support@freenove.com |
|
Sketch
In this project, we will make a flowing water light with a 74HC595 chip to learn about its functions.
Move the program folder “Freenove_Ultimate_Starter_Kit_for_ESP8266/Python/Python_Codes” to disk(D) in advance with the path of “D:/Micropython_Codes”.
Open “Thonny”, click “This computer” -> “D:” -> “Micropython_Codes” -> “13.1_Flowing_Water_Light”. Select “my74HC595.py”, right click your mouse to select “Upload to /”, wait for “my74HC595.py”to be uploaded to ESP8266 and then double click “Flowing_Water_Light.py”.
13.1_Flowing_Water_Light
Click “Run current script” and you will see that Bar Graph LED starts with the flowing water pattern flashing from left to right and then back from right to left. If it displays nothing, maybe the LED Bar is connected upside down, please unplug it and then re-plug it reversely.
If you have any concerns, please contact us via: support@freenove.com
The following is the program code:
1import time
2from my74HC595 import Chip74HC595
3
4chip = Chip74HC595(14,12,13)
5# ESP8266-14: 74HC595-DS(14)
6# ESP8266-12: 74HC595-STCP(12)
7# ESP8266-13: 74HC595-SHCP(11)
8
9while True:
10 x=0x01
11 for count in range(8):
12 chip.shiftOut(1,x) #High bit is sent first
13 x=x<<1
14 time.sleep_ms(100)
15 x=0x01
16 for count in range(8):
17 chip.shiftOut(0,x) #Low bit is sent first
18 x=x<<1
19 time.sleep_ms(100)
Import time and my74HC595 modules.
1import time
2from my74HC595 import Chip74HC595
Assign pins for ESP8266 to connect to 74HC595.
1chip = Chip74HC595(14,12,13)
The first for loop makes LED Bar display separately from left to right while the second for loop make it display separately from right to left.
1x=0x01
2for count in range(8):
3 chip.shiftOut(1,x) #High bit is sent first
4 x=x<<1
5 time.sleep_ms(100)
6x=0x01
7for count in range(8):
8 chip.shiftOut(0,x) #Low bit is sent first
9 x=x<<1
10 time.sleep_ms(100)
Reference
- Class Chip74HC595
Before each use of the object Chip74HC595 , make sure my74HC595.py has been uploaded to “/” of ESP8266, and then add the statement “ from my74HC595 import Chip74HC595 “ to the top of the python file.
Chip74HC595(): An object. By default, 74HC595’s DS pin is connected to Pin(14) of ESP8266, ST_CP pin is connected to ESP8266’s Pin(12) and OE pin is connected to ESP’s Pin(5). If you need to modify the pins, just do the following operations.
chip=Chip74HC595() or chip=Chip74HC595(14,12,13,5)
shiftOut(direction, data): Write data to 74HC595.
direction: 1/0. “1” presents that high-order byte will be sent first while “0” presents that low-order byte will be sent first.
data: The content that is sent, which is one-byte data.
clear(): Clear the latch data of 74HC595.








