Template: PCF8574 IO Expansion Board RPi Guide
From Waveshare Wiki
Revision as of 06:38, 2 September 2023 by Waveshare-admin (talk | contribs) (Text replacement - "https://www.waveshare.com/w/upload/" to "https://files.waveshare.com/upload/")
Raspberry Pi
Enable I2C Interface
Open a terminal and run the following commands:
sudo raspi-config Choose Interfacing Options -> I2C -> Yes.
Reboot Raspberry Pi:
sudo reboot
Install libraries
Install Library
If you use the bookworm system, you can only use lgpio library, bcm2835 and wiringPi can't be installed and used.
BCM2835
#Open the Raspberry Pi terminal and run the following command wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz tar zxvf bcm2835-1.71.tar.gz cd bcm2835-1.71/ sudo ./configure && sudo make && sudo make check && sudo make install # For more, you can refer to the official website at: http://www.airspayce.com/mikem/bcm2835/
WiringPi
#Open the Raspberry Pi terminal and run the following command cd sudo apt-get install wiringpi #For Raspberry Pi systems after May 2019 (earlier than that can be executed without), an upgrade may be required: wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v # Run gpio -v and version 2.52 will appear, if it doesn't it means there was an installation error # Bullseye branch system using the following command: git clone https://github.com/WiringPi/WiringPi cd WiringPi . /build gpio -v # Run gpio -v and version 2.70 will appear, if it doesn't it means there was an installation error
lgpio
#Open the Raspberry Pi terminal and run the following command wget https://github.com/joan2937/lg/archive/master.zip unzip master.zip cd lg-master sudo make install # You can refer to the official website for more: https://github.com/gpiozero/lg
- Python3
sudo apt-get update sudo apt-get install python3-pip sudo apt-get install python3-pil sudo apt-get install python3-numpy sudo pip3 install RPi.GPIO sudo pip3 install spidev
Download examples
Open a terminal of the Raspberry Pi
sudo apt-get install p7zip-full -y sudo wget https://files.waveshare.com/upload/1/14/PCF8574-Code.7z 7z x PCF8574-Code.7z -O./PCF8574-Code cd PCF8574-Code/RaspberryPi/
Hardware connection
PCF8574 | Raspberry Pi | Description |
Board order | ||
VCC | 5V | Power input |
GND | GND | Power ground |
SDA | 3 | I2C data input |
SCL | 5 | I2C clock pin |
Run examples
C examples
cd ~/PCF8574-Code/RaspberryPi/ cd wiringPi sudo make clean sudo make sudo ./test
Python example
cd ~/PCF8574-Code/RaspberryPi/ cd python sudo python3 PCF8574.py
Expected result
Check the voltage level of every IO, P0 ~ P3 is set to High and the P4 ~ P7 is set to Low.