This build drives a 4-digit 7-segment LED display from an ESP32 running MicroPython, using a 74HC595 shift register module so you only need 3 GPIO pins instead of wiring up a dozen segment lines by hand. It's a handy way to show sensor readings, a clock, or debug values without needing a screen or a serial console.
The full tutorial, with every detail and the line-by-line code explanation, is on our site: ESP32 MicroPython 74HC595 4-Digit 7-Segment Display
What you need
- 38-pin ESP32 ESP-WROOM-32 Dev Module - Narrow
- 38-pin ESP32 ESP-WROOM-32 Dev Module - Wide
- 30-pin ESP32 ESP-WROOM-32 Dev Module - Wide
- ESP32 Uno-form board
- ESP32 S3 Uno-form board
- USB Cable Type-A to Type-C (for USB-A PC)
- USB Cable Type-C to Type-C (for USB-C PC)
- 74HC595 4-digit 7-segment Display
- Breadboard
- Jumper Wires
- Screw Terminal Expansion Board for ESP32
- Breakout Expansion Board for ESP32
- Power Splitter for ESP32
- DIYables ESP32 Starter Kit (ESP32 included)
- DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
- DIYables Sensor Kit (18 sensors/displays)
Wiring
The display module needs just three data lines plus power: SCLK, RCLK and DIO, wired here to GPIO 18, 17 and 16. The ESP32's logic runs at 3.3V, but the 74HC595 module works with both 3.3V and 5V, so you connect straight across with no level shifting. You can use any free GPIO pins on the ESP32 as long as you update the pin numbers in the code to match.
How it works
Two 74HC595 shift registers sit between the ESP32 and the LED segments. The ESP32 shifts out which segments to light and which digit to activate, serially, over those three pins. The library handles this for you with a hardware Timer that cycles through the 4 digits very fast, so to your eyes all 4 digits look lit at once even though only one is actually powered at any instant.
Code
After creating a Display4Digit7Segment74HC595 object with your pin numbers, you just call display.print() and the background timer keeps the display refreshed. print() auto-detects integers and floats, right-aligns them, and places the decimal point for you. You can also print text using a supported subset of letters, build temperature strings with a degree symbol constant, and show a time string where a dot stands in for the colon. Calling off() pauses the refresh timer and blanks the display while keeping the last content in memory, and on() resumes it, which is how you build a blinking effect.
esp32-micropython-74hc595-4-digit-7-segment-display.py
from DIYables_MicroPython_4Digit7Segment_74HC595 import Display4Digit7Segment74HC595
import time
display = Display4Digit7Segment74HC595(sclk_pin=18, rclk_pin=17, dio_pin=16, common_anode=True)
# The display auto-refreshes in the background using a hardware Timer.
# Just call display.print() and the display stays on automatically.
display.print(1234)
Things that go wrong
Integers only display correctly in the range -999 to 9999; anything outside that shows "Err" instead of a number, so check your value's range if you see that. Also, when printing strings, a . character doesn't take its own digit position, it just turns on the decimal dot of the digit before it, which can be surprising if you're counting characters to fit the 4-digit width.
Full tutorial
The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: https://newbiely.com/tutorials/esp32-micropython/esp32-micropython-74hc595-4-digit-7-segment-display

Top comments (0)