Over the last three years I build several Raspberry Pi powered robots. With the GPIOs of the Raspberry Pi it is possible to control for example a relays or LEDs. The robots I build got very complex over the years and my Raspberry Pi run out of free GPIO pins. I searched for a cheap and easy to program GPIO expander which is well known in the Raspberry Pi community to get support is necessary. I found the PCF8574 chip soldered on a board which then offers up to 8 additional I/O-ports. The PCF8574 board is connected to the Raspberry Pi with the I2C bus. This makes it very easy to wire everything up with four female-to-female jumpers. You find several Python projects and libraries using the PCF8574 board together with a Raspberry Pi.

The picture below shows the setup I build with the relays and the I/O port expander in the front. The DC motors on the left side are used for another test.

PCF8574 test setup with all electronics

PCF8574 test setup with all electronics

It is possible to mount several I/O port expander as a chain one by one. You only have to set a unique I2C address for each board with the yellow jumpers.

The next picture shows the relays and the I/O port expander in the front with the yellow jumpers.

PCF8574 test setup with relais

PCF8574 test setup with relais

After connecting the port expander with the Raspberry Pi by using the I2C bus and connecting the relays to the PCF8574 port expander it is time to install the Python software and to write a small test program.

Components List

Raspberry Pi 3 Model B Kit

Vilros Raspberry Pi 3 Ultimate Starter Kit
Preis: EUR 79,99
1 neu von EUR 79,990 gebraucht
Get Your First Taste Of raspberry Pi with this Ultimate Starter Kit from Vilors.

This Is the Raspberry Pi 3 Model B Ultimate Starter Kit From Vilros
It includes the new Raspberry Pi 3 Model B (Latest Version Released on 02/29/2016)

Raspberry Pi 3 Model B Technical Specifications:
• Broadcom BCM2837 64bit ARMv8 Quad Core Processor powered SingleBoard Computer running at 1.2GHz
• BCM43143 WiFi on board
• Bluetooth Low Energy (BLE) on board
• 40pin extended GPIO
• 4 x USB2 ports
• 4 pole Stereo output and Composite video port
• Full size HDMI
• CSI camera port for connecting the Raspberry Pi camera
• DSI display port for connecting the Raspberry Pi touch screen display
• MicroSD port for loading your operating system and storing data
• Upgraded switched Micro USB power source (now supports up to 2.4 Amps)

Kit Content
Raspberry Pi 3- Model B 1GB
Raspberry Pi Enclosure Case (Clear)
32GB Micro SD Card pre-loaded with NOOB
SD Card Adapter
5-Foot EU Micro USB Power Supply 2500 mA
High Quality HDMI Cable
400-Tie-point breadboard (white)
65 Jumper Wires -- 45 pcs--100mm, 10 pcs--150mm, 5 pcs--200mm, 5 pcs--250mm
GPIO Ribbon Cable with Breakout board
45 X 330 Resistors
45X 10K Resistors
2X Big 12mm Buttons
Heatsink for Raspberry Pi - Set of 2 Heat Sinks
10X Yellow LED
10X Red LED

NOTE: The SD Card may appear to be a smaller capacity when you test it on your computer due to partitions placed on the card once the software is installed.

WEEE-Reg.-Nr. DE 29056374

I2C Level Shifter

Price: $7.33
10 new from $6.990 used

PCF8574 Board

WINGONEER PCF8574 IO Erweiterungsplatine I / O-Expander I2C-Bus Auswertungs-Entwicklungs-Modul
Preis: EUR 7,99
1 neu von EUR 7,990 gebraucht
WINGONEER® trademark Reg.NO:012678447

Basierend auf dem I2C-Schnittstelle I / O-Erweiterungsmodulen unter Verwendung von zwei I / O auf acht erweitert werden kann I / O (bis zur gleichzeitigen Einsatz 8 PCF8574, erweitert zu 64 I / O)
Maximale Features: unterstützt zwei Arten von Schnittstellen, Zugriff auf das Zielbrett: Pin oder Sitzreihe
2 unterstützt I2C-Bus-Kaskade (über Pin, Sitzreihe Docking-Verfahren gleichzeitig mehrere I2C-Module verwendet werden können)

Typ: Modular / Komponenten und Teile
Band: keine
Schnittstelle: I2C
Board Type: Pin oder Sitzreihe

Technische Daten:
Typische Anwendungen: für I / O-Ressourcen-Beschränkungen der MCU I / O-Erweiterung
Die wichtigsten Ressourcen: PCF8574, I2C-Schnittstelle, die 8-Bit-Parallel
Größe: 54 * 15mm
Nettogewicht: 7g

Paket enthalten:
1x WINGONEER® PCF8574 PCF8574T Kommunikationsmodul

Software installation

The next chapter explains the steps to install the software libraries you need to get the PCF8574 board working on your Raspberry Pi. I assume that you are using a Raspberry Pi and an up to date Raspbian as operation system.

Please install all the software packages with following commands on your Raspberry Pi one after the other:

Command: suto apt-get update

Command: sudo apt-get install libffi-dev

My program uses the following library from “flyte” to easily control the pcf8574 board which is hosted on GitHub:

GitHub page: https://github.com/flyte/pcf8574.

To install the program form the GitHub user “flyte” you could use the following command.

Command: sudo pip install pcf8574

Python test program

I developed a small test program to control the 4-way relays. The program only switches the I/O ports of the PCF8574 chip. The relays switches depending on the state of the I/O ports.

Download the program, unzip the program and start it in the command line.

Download: PCF8574 – Relais Control

The program is also available on my GitHub repository too:

GitHub page: https://github.com/custom-build-robots/.

After starting the program you see some information about the switch state of the I/O ports. The Python code should give you an idea how to program your own program.

PCF8574 - test program

PCF8574 – test program


If you ran out of free GPIO pins on Raspberry Pi the PCF8547 board is a cheap and easy to implement solution to get 8 additional I/O ports. You could not only set the state of the ports you could also read the state of the ports as well. That is perfect if you are using buttons or switches in your project. The I2C bus makes it easy to connect everything together with only for cables. Two for SDA/SCL and tow wires for Vcc/GND.

(Visited 226 times, 1 visits today)