Arduino and Visuino: Use PCF8574/PCF8574A I2C GPIO to Add More Digital Channels to Arduino
by BoianM in Circuits > Arduino
6883 Views, 20 Favorites, 0 Comments
Arduino and Visuino: Use PCF8574/PCF8574A I2C GPIO to Add More Digital Channels to Arduino
No matter how many ports an Arduino board has, they never seem to be enough for the cool new project you have in mind ;-) . Luckily there is a solution. The Arduino has both I2C and SPI pins, and there are a number of I2C and SPI GPIO chips, and modules built with those chips. One of the cheapest and most widely used one is the PCF8574/PCF8574A. On the positive side it is widely available and there are ready cheap modules with it. The down side is that it has only 8 channels. The good news is that you can connect multiple such modules on the same I2C channel.
In this Instructable, I will show you how you can use PCF8574/PCF8574A GPIO I2C Module to add 8 more digital channels to your Arduino Nano.
Components
- One Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine)
- One PCF8574/PCF8574A GPIO Module (Also shown on Picture 2)
- One Button Sensor Module I got from this cheap 37 sensors set.
- One RGB LED Module I got from this cheap 37 sensors set.
- One small Breadboard (Any breadboard can be used, or any other way to connect the wires together)
- 7 Female-Male jumper wires
- 6 Female-Female jumper wires
Select the PCF8574/PCF8574A I2C Address
My PCF8574/PCF8574A GPIO Module has Jumpers that can be used to specify the I2C address.
If you position each Jumper to the "-" side it will set to value Zero (Picture 1) for the Address bit, and if you switch it to the "+" side, it will set One (Picture 3) for the Address bit.
The PCF8574 and PCF8574A have a different set of addresses. The following is the table of addresses based on the +/- settings of the jumpers:
- A2="-", A1="-", A0="-" for PCF8574 (32), for PCF8574A (56) (Picture 1)
- A2="-", A1="-", A0="+" for PCF8574 (33), for PCF8574A (57) (Picture 2)
- A2="-", A1="+", A0="-" for PCF8574 (34), for PCF8574A (58)
- A2="-", A1="+", A0="+" for PCF8574 (35), for PCF8574A (59)
- A2="+", A1="-", A0="-" for PCF8574 (36), for PCF8574A (60)
- A2="+", A1="-", A0="+" for PCF8574 (37), for PCF8574A (61)
- A2="+", A1="+", A0="-" for PCF8574 (38), for PCF8574A (62)
- A2="+", A1="+", A0="+" for PCF8574 (39), for PCF8574A (63) (Picture 3)
Connect the PCF8574/PCF8574A GPIO Module to the Arduino
- Connect Female-Male Power(Red wire), and Ground(Black wire) to the PCF8574/PCF8574A GPIO Module (Picture 1), and leave the Male ends unconnected
- Connect Female-Female SDA(Green wire), and SCL(Yellow wire) to the PCF8574/PCF8574A GPIO Module (Picture 1)
- Connect the other end of the SDA wire(Green wire) to SDA/Analog pin 4 of the Arduino Nano board(Picture 2)
- Connect the other end of the SCL wire(Yellow wire) to SCL/Analog pin 5 of the Arduino Nano board(Picture 2)
- Connect Female-Male Ground(Black wire) to the Ground pin of the Arduino board(Picture 2), and leave the Male end unconnected
- Connect another Female-Male Power(Red wire) to the 5V Power pin of the Arduino board(Picture 2), and leave the Male end unconnected
- Picture 3 shows where are the Ground, 5V Power, SDA/Analog pin 4, and SCL/Analog pin 5 pins of the Arduino Nano
Connect the Button and the LED Modules to the PCF8574/PCF8574A GPIO Module
- Connect Female-Female Button Signal (Brown wire) to the "Signal" Pin of the Button Module
- Connect Female-Male Power (Red wire) to the "+" pin of the Button Module
- Connect Female-Male Ground (Black wire) to the "-" pin of the Button Module
- Connect Female-Male Ground (Black wire) to the "-" pin of the LED Module
- Connect Female-Female LED Blue Color (Blue wire) to the "B" pin of the LED Module
- Connect Female-Female LED Green Color (Gray wire) to the "G" pin of the LED Module
- Connect Female-Female LED Red Color (Orange wire) to the "R" pin of the LED Module
- Connect the other end of the Button Signal (Brown wire) to the P0 pin of the PCF8574/PCF8574A GPIO Module
- Connect the other end of the LED Red Color (Orange wire) to the P1 pin of the PCF8574/PCF8574A GPIO Module
- Connect the other end of the LED Green Color (Gray wire) to the P2 pin of the PCF8574/PCF8574A GPIO Module
- Connect the other end of the LED Blue Color (Blue wire) to the P3 pin of the PCF8574/PCF8574A GPIO Module
Connect the Power Wires Together
Connect the Male ends of the 3 Power wires(Red wires) - from the Button Module, the PCF8574/PCF8574A GPIO Module, and the Arduino together as example with the help of a Breadboard (Picture 1) - In my case I used a small Breadboard
Connect the Ground Wires Together
Connect the Male ends of the 4 Ground wires(Black wires) - from the LED Module, the Button Module, the PCF8574/PCF8574A GPIO Module, and the Arduino together as example with the help of a Breadboard (Picture 1) - In my case I used a small Breadboard
Start Visuino, and Select the Arduino Board Type
To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/.
Please be aware that there are some critical bugs in Arduino IDE 1.6.6.
Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!
The Visuino: https://www.visuino.com also needs to be installed.
In Visuino: Add and Connect PCF8574/PCF8574A GPIO Component
First we need to add component to control the PCF8574/PCF8574A GPIO:
- From the Component Toolbox expand the "Input/Output" Category, then the "Digital" sub-category, select the "PCF8574/PCF8574A GPIO" component (Picture 1), and drop it in the design area (Picture 2)
- In the Object Inspector, you may need to change the value of the "Address" property of the GPIO1 component (Picture 2) (See Step 2 of the Instructable for more details on selecting the I2C Address)
- The PCF8574 addresses are between 32 to 39 depending on the jumper settings
-
The PCF8574A addresses are between 56 to 63 depending on the jumper settings
- Connect the "Out" pin of the GPIO1 component to the "In" pin of the "I2C" channel of the Arduino component (Picture 3)
In Visuino: Add and Configure Debounce Button, Counter, and Unsigned to Digital Components
Next we will add components to have button clocking a counter and sending the first 3 bits of the counter to the Red, Green, and Blue color pins of the LED:
- Type "button" in the Filter box of the Component Toolbox then select the "Debounce Button" component (Picture 1), and drop it in the design area (This component will reduce, the debouncing noise when the button is pressed. For more details see this Instructable)
- Type "count" in the Filter box of the Component Toolbox then select the "Counter" component (Picture 2), and drop it in the design area
- Type "to un" in the Filter box of the Component Toolbox then select the "Integer To Unsigned" component (Picture 3), and drop it in the design area
- Type "to dig" in the Filter box of the Component Toolbox then select the "Unsigned To Digital" component (Picture 4), and drop it in the design area (Picture 5)
- In the Object Inspector set the value of the "Output Pins" property of the UnsignedToDigital1 component to "3" (Picture 6)
In Visuino: Connect the Components
- Connect the "Out" output pin of the "Channel[ 0 ]" channel of the GPIO1 component to the "In" input pin of the Button1 component (Picture 1)
- Connect the "Out" output pin of the Button1 component to the "In" input pin of the Counter1 component (Picture 2)
- Connect the "Out" output pin of the Counter1 component to the "In" input pin of the IntegerToUnsigned1 component (Picture 3)
- Connect the "Out" output pin of the IntegerToUnsigned1 component to the "In" input pin of the UnsignedToDigital1 component (Picture 4)
- Click in the "Out" box containing the pins of the UnsignedToDigital1 component to start connecting all the Out pins at once (Picture 5)
- Move the mouse over the "In" input pin of the "Channel[ 1 ]" channel of the GPIO1 component. The Visuino will automatically spread the wires so they will connect correctly to the rest of the pins (Picture 5)
Generate, Compile, and Upload the Arduino Code
- In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
- In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)
And Play...
Congratulations! You have completed the project.
Picture 1 and the Video show the connected and powered up project. Every time you press the Button the counter will increment, and the LED will change its color.
On Picture 2 you can see the complete Visuino diagram.
Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.com