Labs / Electronic modules

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation, v1.3 · License: CC BY 4.0 · Driver code (lighting/pcf8574_led_driver): MIT License

Contents
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

I. Module Introduction

8-segment bar digital tube module based on PCF8574 chip, with PCF8574T/TR IO expansion chip as the core, realizes the control of the 8-segment bar digital tube through the I2C interface, and only needs two communication pins to complete the driving. The module is equipped with chip address selection bits. Each I/O pin can sink a maximum current of about 10mA, which is suitable for the display expansion scenario of bar digital tubes in embedded devices, and provides a concise multi-segment bar display control solution for the system.

II. Introduction to Major Chips

PCF8574DWR is an I²C bus expander chip that can expand the 2-wire I²C interface into an 8-bit parallel I/O port, requires no additional clock or control signals, and supports bidirectional data transmission. It is compatible with a wide supply voltage range of 2.5V to 6V, operates at a temperature range of -40°C to 85°C, features strong output drive capability (can directly drive LEDs), integrates a power-on reset circuit, and comes in a 16-pin SOIC package. With its compact size and high compatibility, it is widely used in scenarios requiring additional parallel interfaces such as microcontroller I/O port expansion, industrial control, and smart homes.

2.1 Chip Overview

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

2.2 Pin Definition

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

2.3 Functional Block Diagram

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

PCF8574DWR The functional block diagram is described as follows:

Typical Scenario (Taking I/O Expansion as an Example):

2.4 Performance Parameters

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

PCF8574DWR Some of the parameter descriptions are as follows:

2.5 Reference Circuit

None.

2.6 Chip Configuration

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
  1. Structure of I²C Target Address Byte

The I²C target address byte of the PCF8574DWR is 8 bits in total: the first 5 bits are fixed as "L, H, L, L"(i. e., binary 0100), the last 3 bits are determined by the levels of the chip's A2, A1, and A0 pins (L = low level, H = high level), and the final 1 bit is the read/write bit (R/ W, high for read, low for write).

  1. Correspondence Between I²C Target Addresses and Pins

The eight level combinations of A2, A1 and A0 correspond to different 8-bit read/write addresses:

When A2= A1= A0= L, the read address is decimal 65 (hexadecimal 41), and the write address is decimal 64 (hexadecimal 40);

When A2= A1= L and A0= H, the read address is 67 (43) and the write address is 66 (42);

By that analogy, each time the level of the A2/A1/A0 group is changed, the address increments according to the rule, and finally covers 8 different read and write address groups (for example, when A2= A1= A0= H, the read address is 79 (4F) and the write address is 78 (4E)).

  1. The levels of the address pins A0-A2 must not be modified during the START-STOP cycle of I²C communication; otherwise, address matching will fail.

This chip adopts I2C communication interface.

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

2.7.2 Quasi-bidirectional IO

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

The PCF8574 adopts a quasi-bidirectional IO design, eliminating the need for a separate direction register, and can control four states of IO — input high, input low, output high, and output low — through a single register:

Compared with the totem-pole IO, this design has the advantages of being adaptable to LED driving, simple architecture, and no need for command bytes (saving memory/bandwidth), and its functions are implemented in the circuit by the cooperation of a weak pull-up current source, an accelerated pull-up transistor, and an output low-sink current transistor.

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

2.7.3 Writing to and Reading from Ports

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

PCF8574 write port (output mode) follows the I²C communication process: the master first sends a START condition, then transmits the slave address (with the last bit set to 0 to indicate write mode); after the device acknowledges, the master sends 8-bit data from P7 to P0; once the clock line is pulled high and the device acknowledges, the data takes effect — when writing 0, the strong pull-down transistor remains continuously on; when writing 1, the strong pull-up only assists the voltage rise for half a clock cycle, and the high level is subsequently maintained by a 100μA weak pull-up.The master can continuously send multi-byte data (new data will overwrite old data), and finally send STOP / ReSTART to terminate;meanwhile, note that if the port is configured as an input, you must write 1 to it to turn off the strong pull-down transistor.

Combined with the Sequence Diagram and code examples, this process can be simplified as " START → Slave Address + Write → ACK → Data → ACK (repeatable) → STOP ", and the timing also reflects details such as the valid delay of data output and the dynamic change of pull-up current.

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

PCF8574 ’s port reading (input mode) is subject to a prerequisite: the port must be pre-written with 1 (this is the default state after power-on reset); its operation follows the I²C protocol: the master first sends a START condition, then transmits the slave address (with the last bit set to 1 to indicate read mode), and after the device acknowledges, it sends the port data byte to the master; the master can either send a NACK followed by a STOP to terminate the read, or send an ACK to continue reading the next byte.Note: Reading an output pin returns its actual logic level. If the input data changes faster than the host's reading pace, data will be lost due to failure to meet setup/hold time requirements. Combined with the Sequence Diagram and code examples, the process can be simplified as " START → Slave Address + Read → ACK → Data → ACK (repeatable) → Data → NACK → STOP ", and the timing also reflects the delay relationship between interrupts and data changes.

2.7.5 Power-on Reset

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

PCF8574 has the following power-on reset (POR) function logic: when VDD starts supplying power, the internal power-on reset circuit keeps the chip in a reset state until the VDD voltage reaches the power-on reset threshold VPOR; at this point the reset is released, and the chip's registers, I²C / SMBus finite-state machine will be initialized to the default state — all IO ports are configured as input mode with a weak current source pulled up to VDD. If you need to re-trigger the power-on reset subsequently, you must lower VDD below VPOR and then raise it back to the operating voltage to complete the reset cycle.

2.7.6 Interrupt Function

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

2.8 PCB Routing Precautions

None.

III. Circuit Engineering

3.1 Circuit Source Engineering

To obtain the source project of the circuit, please follow the official account [Freak Embedded]

3.2 Module Usage Instructions

SCH_Schematic1_8-Segment Light Bar Display Module Based on PCF8574 Chip-V1.0.0_2025-11-17.pdf 2.2 MB

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

This module provides an I2C communication interface: it supports the standard I2C communication rate (100kHz), and can flexibly configure 8 types of A0, A1, A2 address selection bits to configure 0X20 - 0X27 and other I2C device addresses. It is compatible with 3.3V/5V logic levels, and can stably implement single-byte write of 8-bit data to control the on-off state of the 8-segment bar nixie tube (each bit of data corresponds to the on/off of one light bar). It is suitable for scenarios such as status indication of embedded devices, bar visualization of sensor values, and interactive display for maker projects, providing the system with simple and efficient multi-segment light bar display control capability.

3.3 Application Experiment

Here, we use the GraftPort-RP2040 development board for testing, and connect the 8-segment bar digital tube module based on the PCF8574 chip to communicate with the main controller via the I2C interface.

Here, we first use the HY2.0-4P cable to connect the module to the GraftPort-RP2040 development board's I2C0 interface:

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)
GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

The module connections are shown in the following table:

Development Board Pins

Module Pins

Description

Pin 4

SDA (Data Pin)

I2C data transmission line, corresponding to I2C0 's SDA

Pin 5

SCL (Clock Pin)

I2C clock signal line, corresponding to I2C0 SCL

Here, we need to search for the relevant driver packages on uPyPI: https://upypi.net/zh/

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

Enter pcf8574_led_driver to search, and the following will be displayed:

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

Click to copy the local installation command:

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

Here, we can use the mip tool to import module driver library code. The following are the usage commands for the mpremote tool:

mpremote mip install github:FreakStudioCN/GraftSense-Drivers-MicroPython/lighting/pcf8574_led_driver

After importing the 8-segment bar digital tube module based on PCF8574 chip - MicroPython driver code, copy the following main.py code into our project:

# Python env   : MicroPython v1.23.0
# -*- coding: utf-8 -*-
# @Time    : 2025/09/08 10:00
# @Author  : 侯钧瀚
# @File    : main.py
# @Description : Eight-segment light bar digital tube module based on the PCF8574 chip

# ======================================== Import Modules =========================================

from machine import I2C, Pin
#Import the pcf8574 module
from pcf8574 import PCF8574
#Import the eight-segment light bar digital tube module based on the PCF8574 chip
from led_bar import LEDBar
#Time-related module
import time

# ======================================== Global Variables ============================================

# ======================================== Functions ============================================

# ======================================== Custom Classes ============================================

# ======================================== Initialization ==========================================

# Power-on delay of 3 s
time.sleep(3)
# Print debug message
print("FreakStudio: Test PCF8574 Eight-Segment LED Display Module ")

i2c = I2C(id=0, sda=Pin(4), scl=Pin(5), freq=100000)
# Start scanning for devices on the I2C bus and return a list of slave addresses
devices_list = i2c.scan()
print('START I2C SCANNER')

# If devices_list is empty, no device is connected to the I2C bus
if len(devices_list) == 0:
    print("No i2c device !")
# If not empty, print the slave device addresses
else:
    print('i2c devices found:', len(devices_list))
    # Iterate over the slave device address list
    for device in devices_list:
        # Check whether the device address is the PCF8575 address
        if device >= 0x20 and device <= 0x27:
            print("I2C hexadecimal address: ", hex(device))

# Initialize PCF8574, assuming address 0x20
pcf = PCF8574(i2c, address=device)
# Create an LEDBar instance
ledbar = LEDBar(pcf)

# ========================================  Main Program  ===========================================

# 1. Turn on a single LED (turn on the 3rd LED)
ledbar.set_led(2, True)
time.sleep(1)

# 2. Turn off a single LED (turn off the 3rd LED)
ledbar.set_led(2, False)
time.sleep(1)

# 3. Set all LEDs (e.g., turn on the first 4)
ledbar.set_all(0b00001111)
time.sleep(1)

# 4. Display level (e.g., turn on the first 6 LEDs)
ledbar.display_level(6)
time.sleep(1)

# 5. Running light effect
for i in range(8):
    ledbar.set_all(1 << i)
    time.sleep(0.2)

# 6. Turn all off
ledbar.clear()

To flash the code, open a terminal and use the mpremote tool to connect to the main controller; the output is as follows:

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)

It can be seen that the lights will illuminate sequentially in accordance with the process specified in the code.

IV. Drivers

pcf8574_led_driver.zip 11 KB

None.

VI. Revision History

Document Version

Date of Modification

Modifier

Modified Content

v1.0

2025-11-17

Ling Gaoxing

Initialize the document

v1.1

2025-12-29

Li Zisheng

Added application experiments and production files

v1.2

2025-12-31

Xin Ruili

Create an open version of the document based on the internal document version v1.1.

v1.3

2026-03-29

Xin Ruili

Modified the application experiment section.

VII. Relevant Materials

7.1 Chip Datasheet

PCF8574 Manual.pdf 3.4 MB

7.2 Unique Icons for PCB Silkscreen

GraftSense - 8-segment Bar Digital Tube Module Based on PCF8574 Chip (Open Version)