ESP32 MicroPython 74HC595 4-Digit 7-Segment Display

The ESP32 is a powerful, Wi-Fi-enabled microcontroller widely used in IoT and embedded projects. Paired with MicroPython and the DIYables 4-Digit 7-Segment Display module (74HC595), you can easily show numbers, text, and sensor readings on a bright LED display.

This tutorial walks you through:

ESP32 MicroPython 4-Digit 7-Segment Display 74HC595

Components Needed

1×ESP-WROOM-32 Dev Module
1×Alternatively, ESP32 Uno-form board
1×Alternatively, ESP32 S3 Uno-form board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×74HC595 4-digit 7-segment Display
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for ESP32
1×Recommended: Breakout Expansion Board for ESP32
1×Recommended: Power Splitter for ESP32

Or you can buy the following kits:

1×DIYables ESP32 Starter Kit (ESP32 included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

The 4-Digit 7-Segment Display 74HC595 Module

The DIYables 4-Digit 7-Segment Display 74HC595 module is a compact LED display driven by two 74HC595 shift registers. It shows 4 digits and 4 decimal point dots. Because the shift registers handle all the segment and digit driving, the ESP32 only needs 3 GPIO pins (clock, latch, and data) instead of the 12+ pins a raw display would require.

The ESP32 communicates with the module by shifting out segment data and digit-select data serially. The library handles this automatically using a hardware Timer for multiplexing — each digit is refreshed in turn at high speed, so all 4 digits appear lit simultaneously.

Key features of the module:

  • Only 3 wires for data (SCLK, RCLK, DIO) plus power.
  • 4 decimal point dots — individually controllable.
  • Common anode or common cathode variants available.
  • 5V or 3.3V compatible.

Pin Description

Pin Purpose ESP32 Connection
SCLK (SH_CP) Serial clock input Connect to GPIO18
RCLK (ST_CP) Register clock / latch Connect to GPIO17
DIO (DS) Serial data input Connect to GPIO16
VCC 3.3V to 5V power input Connect to 3.3V
GND Ground Connect to GND
4-Digit 7-Segment Display 74HC595 Pinout

Wiring

The ESP32 operates at 3.3V logic. The 74HC595 module works with both 3.3V and 5V, so you can wire directly — no level shifting needed.

74HC595 Module ESP32 Notes
SCLK (SH_CP) GPIO18 Serial clock
RCLK (ST_CP) GPIO17 Latch / register clock
DIO (DS) GPIO16 Serial data
VCC 3.3V Power
GND GND Ground
The wiring diagram between ESP32 4-Digit 7-Segment Display 74HC595

This image is created using Fritzing. Click to enlarge image

Tip: You can use any available GPIO pins on the ESP32. Just update the pin numbers in the code.

Detailed Instructions

Here's instructions on how to set up and run your MicroPython code on the ESP32 using Thonny IDE:

  • Make sure Thonny IDE is installed on your computer.
  • Confirm that MicroPython firmware is loaded on your ESP32 board.
  • If this is your first time using an ESP32 with MicroPython, check out the ESP32 MicroPython Getting Started guide for step-by-step instructions.
  • Connect the ESP32 board to the 4-digit 7-segment display module according to the provided diagram.
  • Connect the ESP32 board to your computer with a USB cable.
  • Open Thonny IDE on your computer.
  • In Thonny IDE, go to Tools Options.
  • Under the Interpreter tab, choose MicroPython (ESP32) from the dropdown menu.
  • Make sure the correct port is selected. Thonny IDE usually detects it automatically, but you might need to select it manually (like COM3 on Windows or /dev/ttyUSB0 on Linux).
  • Navigate to the Tools Manage packages on the Thonny IDE.
  • Search "DIYables-MicroPython-4Digit7Segment-74HC595", then find the 4-Digit 7-Segment Display library created by DIYables.
  • Click on DIYables-MicroPython-4Digit7Segment-74HC595, then click Install button to install the library.
ESP32 4-Digit 7-Segment Display 74HC595 library
  • Copy the provided MicroPython code and paste it into Thonny's editor.
  • Save the code to your ESP32 by:
    • Clicking the Save button or pressing Ctrl+S.
    • In the save dialog, choose MicroPython device.
    • Name the file main.py.
  • Click the green Run button (or press F5) to execute the script.
  • Observe the display — you should see numbers, text, or other content appear on the 7-segment display.

Starter Code Template

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)

ESP32 Code — Display Integers

""" Example: Display integer numbers on 4-digit 7-segment display with 74HC595. Works with: ESP32, Raspberry Pi Pico, Arduino Nano ESP32, Arduino Nano R1 WiFi Wiring guide: ESP32: 74HC595 Module ESP32 ────────────── ────── SCLK (SH_CP) -> GPIO18 RCLK (ST_CP) -> GPIO17 DIO (DS) -> GPIO16 VCC -> 3.3V GND -> GND Raspberry Pi Pico: 74HC595 Module Raspberry Pi Pico ────────────── ───────────────── SCLK (SH_CP) -> GP2 RCLK (ST_CP) -> GP1 DIO (DS) -> GP0 VCC -> 3.3V (pin 36) GND -> GND (pin 38) Arduino Nano ESP32: 74HC595 Module Arduino Nano ESP32 ────────────── ────────────────── SCLK (SH_CP) -> D18 (GPIO18) RCLK (ST_CP) -> D17 (GPIO17) DIO (DS) -> D16 (GPIO16) VCC -> 3.3V GND -> GND Arduino Nano RP2040 Connect: 74HC595 Module Arduino Nano RP2040 Connect ────────────── ─────────────────────────── SCLK (SH_CP) -> D2 (GP2) RCLK (ST_CP) -> D1 (GP1) DIO (DS) -> D0 (GP0) VCC -> 3.3V GND -> GND """ from DIYables_MicroPython_4Digit7Segment_74HC595 import Display4Digit7Segment74HC595 import time # Pin configuration - change the pins to match your wiring and board # ESP32 / Arduino Nano ESP32: SCLK=18, RCLK=17, DIO=16 # Raspberry Pi Pico / Nano RP2040: SCLK=2, RCLK=1, DIO=0 SCLK_PIN = 18 RCLK_PIN = 17 DIO_PIN = 16 display = Display4Digit7Segment74HC595(SCLK_PIN, RCLK_PIN, DIO_PIN, common_anode=True) while True: # Display integers numbers = [0, 42, 1234, -5, -123, 9999] for num in numbers: display.print(num) time.sleep(2) # Display with zero padding display.print(42, zero_pad=True) # Shows "0042" time.sleep(2)

Try It

  • Wire the module, connect the ESP32 via USB.
  • Upload the code using Thonny IDE.
  • The display cycles through several integers (0, 42, 1234, -5, -123, 9999) and a zero-padded number (0042).

Integer Display

The print() method auto-detects integers and formats them right-aligned on the display.

Method Call Display Shows Notes
display.print(0) " 0" Single digit, right-aligned
display.print(42) " 42" Two digits
display.print(1234) "1234" All four digits
display.print(-5) " -5" Negative with minus sign
display.print(-123) "-123" Negative, full width
display.print(9999) "9999" Maximum positive value
display.print(42, zero_pad=True) "0042" Leading zeros

Integer range: -999 to 9999. Values outside this range display "Err".

ESP32 Code — Display Floats

""" Example: Display float numbers on 4-digit 7-segment display with 74HC595. Works with: ESP32, Raspberry Pi Pico, Arduino Nano ESP32, Arduino Nano R1 WiFi Wiring guide: ESP32: 74HC595 Module ESP32 ────────────── ────── SCLK (SH_CP) -> GPIO18 RCLK (ST_CP) -> GPIO17 DIO (DS) -> GPIO16 VCC -> 3.3V GND -> GND Raspberry Pi Pico: 74HC595 Module Raspberry Pi Pico ────────────── ───────────────── SCLK (SH_CP) -> GP2 RCLK (ST_CP) -> GP1 DIO (DS) -> GP0 VCC -> 3.3V (pin 36) GND -> GND (pin 38) Arduino Nano ESP32: 74HC595 Module Arduino Nano ESP32 ────────────── ────────────────── SCLK (SH_CP) -> D18 (GPIO18) RCLK (ST_CP) -> D17 (GPIO17) DIO (DS) -> D16 (GPIO16) VCC -> 3.3V GND -> GND Arduino Nano RP2040 Connect: 74HC595 Module Arduino Nano RP2040 Connect ────────────── ─────────────────────────── SCLK (SH_CP) -> D2 (GP2) RCLK (ST_CP) -> D1 (GP1) DIO (DS) -> D0 (GP0) VCC -> 3.3V GND -> GND """ from DIYables_MicroPython_4Digit7Segment_74HC595 import Display4Digit7Segment74HC595 import time # Pin configuration - change the pins to match your wiring and board # ESP32 / Arduino Nano ESP32: SCLK=18, RCLK=17, DIO=16 # Raspberry Pi Pico / Nano RP2040: SCLK=2, RCLK=1, DIO=0 SCLK_PIN = 18 RCLK_PIN = 17 DIO_PIN = 16 display = Display4Digit7Segment74HC595(SCLK_PIN, RCLK_PIN, DIO_PIN, common_anode=True) while True: # Display floats with auto decimal places floats = [1.5, 12.34, 3.141, -1.2, 0.5] for num in floats: display.print(num) time.sleep(2) # Display with specific decimal places display.print(23.5, decimal_places=1) # Shows "23.5" time.sleep(2) # Display 1.5 with auto decimal places display.print(1.5) # Shows "1.5" time.sleep(2) # Display 1.5 with 2 decimal places display.print(1.5, decimal_places=2) # Shows "1.50" time.sleep(2) # Display 1.5 with 2 decimal places and zero padding display.print(1.5, decimal_places=2, zero_pad=True) # Shows "01.50" time.sleep(2)

Float Display

The decimal point dot is automatically placed at the correct position. You can let the library choose the number of decimal places, or specify it manually.

Method Call Display Shows Notes
display.print(1.5) " 1.5" Auto decimal places
display.print(12.34) "12.34" Auto — 2 decimal places
display.print(3.141) "3.141" Auto — 3 decimal places
display.print(23.5, decimal_places=1) "23.5" Forced 1 decimal place
display.print(1.5, decimal_places=2) " 1.50" Forced 2 decimal places with trailing zero
display.print(1.5, decimal_places=2, zero_pad=True) "01.50" Zero-padded with 2 decimal places

ESP32 Code — Display Text, Degree, and Temperature

""" Example: Display text, special characters, and temperature on 4-digit 7-segment display. Works with: ESP32, Raspberry Pi Pico, Arduino Nano ESP32, Arduino Nano R1 WiFi Wiring guide: ESP32: 74HC595 Module ESP32 ────────────── ────── SCLK (SH_CP) -> GPIO18 RCLK (ST_CP) -> GPIO17 DIO (DS) -> GPIO16 VCC -> 3.3V GND -> GND Raspberry Pi Pico: 74HC595 Module Raspberry Pi Pico ────────────── ───────────────── SCLK (SH_CP) -> GP2 RCLK (ST_CP) -> GP1 DIO (DS) -> GP0 VCC -> 3.3V (pin 36) GND -> GND (pin 38) Arduino Nano ESP32: 74HC595 Module Arduino Nano ESP32 ────────────── ────────────────── SCLK (SH_CP) -> D18 (GPIO18) RCLK (ST_CP) -> D17 (GPIO17) DIO (DS) -> D16 (GPIO16) VCC -> 3.3V GND -> GND Arduino Nano RP2040 Connect: 74HC595 Module Arduino Nano RP2040 Connect ────────────── ─────────────────────────── SCLK (SH_CP) -> D2 (GP2) RCLK (ST_CP) -> D1 (GP1) DIO (DS) -> D0 (GP0) VCC -> 3.3V GND -> GND """ from DIYables_MicroPython_4Digit7Segment_74HC595 import Display4Digit7Segment74HC595 import time # Pin configuration - change the pins to match your wiring and board # ESP32 / Arduino Nano ESP32: SCLK=18, RCLK=17, DIO=16 # Raspberry Pi Pico / Nano RP2040: SCLK=2, RCLK=1, DIO=0 SCLK_PIN = 18 RCLK_PIN = 17 DIO_PIN = 16 display = Display4Digit7Segment74HC595(SCLK_PIN, RCLK_PIN, DIO_PIN, common_anode=True) while True: # Display text strings texts = ["HELP", "Hi", "COOL", "done"] for text in texts: display.print(text) time.sleep(2) # Display temperature with degree symbol display.print_temperature(25, 'C') # Shows "25°C" time.sleep(2) display.print_temperature(72, 'F') # Shows "72°F" time.sleep(2) # Display string with degree constant display.print("25" + display.DEGREE + "C") # Same as print_temperature(25, 'C') time.sleep(2) # Display string with dots display.print("1.2.3.4") # Shows "1.2.3.4" with dots on digits 0,1,2 time.sleep(2)

Supported Characters

The display can show a subset of alphabetic characters that are legible on a 7-segment display:

  • Digits: 0-9
  • Letters: A, b, C, c, d, E, F, G, H, h, I, i, J, L, n, O, o, P, r, S, t, U, u, Y
  • Special: ° (degree), - (dash), _ (underscore), (space)

Temperature Display

Method Call Display Shows Notes
display.print_temperature(25, 'C') "25°C" Celsius
display.print_temperature(72, 'F') "72°F" Fahrenheit
display.print_temperature(-5, 'C') "-5°C" Negative temperature
display.print_temperature(100, 'C') "100°" No room for unit

You can also build temperature strings manually using the DEGREE constant:

display.print("25" + display.DEGREE + "C") # Same as print_temperature(25, 'C')

Dot Handling in Strings

A . character in a string activates the decimal point dot on the preceding digit rather than occupying its own position:

display.print("1.2.3.4") # Shows digits 1, 2, 3, 4 with dots on digits 0, 1, 2

ESP32 Code — Display Time

""" Example: Display time with blinking dot separator on 4-digit 7-segment display. Note: This module has dots only (no colon). The dot on digit 1 is used as a time separator. Works with: ESP32, Raspberry Pi Pico, Arduino Nano ESP32, Arduino Nano R1 WiFi Wiring guide: ESP32: 74HC595 Module ESP32 ────────────── ────── SCLK (SH_CP) -> GPIO18 RCLK (ST_CP) -> GPIO17 DIO (DS) -> GPIO16 VCC -> 3.3V GND -> GND Raspberry Pi Pico: 74HC595 Module Raspberry Pi Pico ────────────── ───────────────── SCLK (SH_CP) -> GP2 RCLK (ST_CP) -> GP1 DIO (DS) -> GP0 VCC -> 3.3V (pin 36) GND -> GND (pin 38) Arduino Nano ESP32: 74HC595 Module Arduino Nano ESP32 ────────────── ────────────────── SCLK (SH_CP) -> D18 (GPIO18) RCLK (ST_CP) -> D17 (GPIO17) DIO (DS) -> D16 (GPIO16) VCC -> 3.3V GND -> GND Arduino Nano RP2040 Connect: 74HC595 Module Arduino Nano RP2040 Connect ────────────── ─────────────────────────── SCLK (SH_CP) -> D2 (GP2) RCLK (ST_CP) -> D1 (GP1) DIO (DS) -> D0 (GP0) VCC -> 3.3V GND -> GND """ from DIYables_MicroPython_4Digit7Segment_74HC595 import Display4Digit7Segment74HC595 import time # Pin configuration - change the pins to match your wiring and board # ESP32 / Arduino Nano ESP32: SCLK=18, RCLK=17, DIO=16 # Raspberry Pi Pico / Nano RP2040: SCLK=2, RCLK=1, DIO=0 SCLK_PIN = 18 RCLK_PIN = 17 DIO_PIN = 16 display = Display4Digit7Segment74HC595(SCLK_PIN, RCLK_PIN, DIO_PIN, common_anode=True) hours = 12 minutes = 30 colon_on = True while True: display.print_time(hours, minutes, colon=colon_on) time.sleep(0.5) # Toggle dot separator every 500ms for blinking effect colon_on = not colon_on

Time Display

This module has dots only (no colon). The print_time() method uses the dot on digit 1 (second from left) as a time separator.

Method Call Display Shows Notes
display.print_time(12, 30) "12.30" Dot separator on
display.print_time(9, 5) "09.05" Auto zero-padding
display.print_time(12, 30, colon=False) "12 30" Dot separator off

Blinking effect: Toggle the colon parameter every 500ms in your main loop to create a blinking time separator.

API Summary

For the full API reference with detailed parameters and examples, see the Library Reference.

Method Description
print(value, decimal_places, zero_pad) Display int, float, or string (auto-detects type)
print_temperature(temperature, unit) Display temperature with ° symbol
print_time(hours, minutes, colon) Display time HH.MM with dot separator
clear() Clear the display buffer
off() Stop auto-refresh and blank the display
on() Restart auto-refresh
set_char(position, char) Set character at position (0-3)
set_number(position, number) Set digit 0-9 at position (0-3)
set_dot(position, state) Set decimal point at position (0-3)
set_segments(position, segments) Set raw segment bits at position (0-3)

Next Steps

  • Explore the Library Reference for the full API including low-level segment control.
  • Combine the display with sensors (e.g., DHT11, DS18B20) to build a temperature monitor.
  • Use print_time() with the ESP32's RTC or NTP to build a simple clock.
  • Add buttons to create a countdown timer or stopwatch.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!