Pcf8574 I/O Expander

master
javadoc

The pcf8574 i/o expander is a circuit that can be used to expand the number of digitai I/O pins that you can use. It can be used as input, output or a combination of both. The device is i2c enabled so you can connect to it either thru the i2c interface on the Arduino or connect it directly to the i2c GPIO pins on a Raspberry PI. They come in a few different formats. The one I have tested looks like this:

 

The i2c address can easily be changed with the small switches. Some devices has addresses between 0x20 and 0x27 alternatviley  0x38 thru 0x3F. 

This circuit can sink more current that it can source, so for example if you want to blink a LED, you should connect the anode to Vcc and the resistance between the cathode and the pin on pcf8574.  


#file : service/Pcf8574.py edit raw
# Initiate the Arduino
arduino = Runtime.createAndStart("Arduino","Arduino")
arduino.connect("COM3")
# Select the Arduino as controller for the IO extender on bus 1 and i2c address 0x38
pcf = Runtime.createAndStart("Pcf","Pcf8574")
# From version 1.0.2316 use attach instead of setController
# pcf.setController(arduino,"1","0x38")
pcf.attach(arduino,"1","0x38")
# Set four pins as output. 
pcf.pinMode(0,"OUTPUT")
pcf.pinMode(1,"OUTPUT")
pcf.pinMode(2,"OUTPUT")
pcf.pinMode(3,"OUTPUT")
# Blink a LED on pin 1
pcf.write(1,1)
sleep(1)
pcf.write(1,0)
sleep(1)
pcf.write(1,1)
sleep(1)
pcf.write(1,0)
sleep(1)
pcf.write(1,1)
# Set four pins as output. 
pcf.pinMode(4,"INPUT")
pcf.pinMode(5,"INPUT")
pcf.pinMode(6,"INPUT")
pcf.pinMode(7,"INPUT")
# Read and display digital input
print pcf.read(4)
print pcf.read(5)
print pcf.read(6)
print pcf.read(7)