Introduction: 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.

Step 1: Components

  1. One Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine)
  2. One PCF8574/PCF8574A GPIO Module (Also shown on Picture 2)
  3. One Button Sensor Module I got from this cheap 37 sensors set.
  4. One RGB LED Module I got from this cheap 37 sensors set.
  5. One small Breadboard (Any breadboard can be used, or any other way to connect the wires together)
  6. 7 Female-Male jumper wires
  7. 6 Female-Female jumper wires

Step 2: 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)

Step 3: Connect the PCF8574/PCF8574A GPIO Module to the Arduino

  1. Connect Female-MalePower(Red wire), and Ground(Black wire) to the PCF8574/PCF8574A GPIO Module (Picture 1), and leave the Male ends unconnected
  2. Connect Female-FemaleSDA(Green wire), and SCL(Yellow wire) to the PCF8574/PCF8574A GPIO Module (Picture 1)
  3. Connect the other end of the SDA wire(Green wire) to SDA/Analog pin 4 of the Arduino Nano board(Picture 2)
  4. Connect the other end of the SCL wire(Yellow wire) to SCL/Analog pin 5 of the Arduino Nano board(Picture 2)
  5. Connect Female-Male Ground(Black wire) to the Ground pin of the Arduino board(Picture 2), and leave the Male end unconnected
  6. Connect another Female-Male Power(Red wire) to the 5V Power pin of the Arduino board(Picture 2), and leave the Male end unconnected
  7. Picture 3 shows where are the Ground, 5V Power, SDA/Analog pin 4, and SCL/Analog pin 5 pins of the Arduino Nano

Step 4: Connect the Button and the LED Modules to the PCF8574/PCF8574A GPIO Module

  1. Connect Female-Female Button Signal (Brown wire) to the "Signal"Pin of the Button Module
  2. Connect Female-MalePower (Red wire) to the "+" pin of the Button Module
  3. Connect Female-MaleGround (Black wire) to the "-" pin of the Button Module
  4. Connect Female-MaleGround (Black wire) to the "-" pin of the LED Module
  5. Connect Female-FemaleLED Blue Color (Blue wire) to the "B" pin of the LED Module
  6. Connect Female-FemaleLED Green Color (Gray wire) to the "G" pin of the LED Module
  7. Connect Female-FemaleLED Red Color (Orange wire) to the "R" pin of the LED Module
  8. Connect the other end of the Button Signal (Brown wire) to the P0 pin of the PCF8574/PCF8574A GPIO Module
  9. Connect the other end of the LED Red Color (Orange wire) to the P1 pin of the PCF8574/PCF8574A GPIO Module
  10. Connect the other end of the LED Green Color (Gray wire) to the P2 pin of the PCF8574/PCF8574A GPIO Module
  11. Connect the other end of the LED Blue Color (Blue wire) to the P3 pin of the PCF8574/PCF8574A GPIO Module

Step 5: Connect the Power Wires Together

Connect the Male ends of the 3 Power wires(Red wires) - from the Button Module, the PCF8574/PCF8574A GPIOModule, and the Arduino together as example with the help of a Breadboard (Picture 1) - In my case I used asmall Breadboard

Step 6: 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 GPIOModule, and the Arduino together as example with the help of a Breadboard (Picture 1) - In my case I used asmall Breadboard

Step 7: 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.

  1. Start Visuino as shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select "Arduino Nano" as shown in Picture 2

Step 8: In Visuino: Add and Connect PCF8574/PCF8574A GPIO Component

First we need to add component to control the PCF8574/PCF8574A GPIO:

  1. 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)
  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

  3. Connect the "Out" pin of the GPIO1 component to the "In" pin of the "I2C" channel of the Arduino component (Picture 3)

Step 9: 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:

  1. 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)
  2. Type "count" in the Filter box of the Component Toolbox then select the "Counter" component (Picture 2), and drop it in the design area
  3. 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
  4. 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)
  5. In the Object Inspector set the value of the "Output Pins" property of the UnsignedToDigital1 component to "3" (Picture 6)

Step 10: In Visuino: Connect the Components

  1. 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)
  2. Connect the "Out" output pin of the Button1 component to the "In" input pin of the Counter1 component (Picture 2)
  3. Connect the "Out" output pin of the Counter1 component to the "In" input pin of the IntegerToUnsigned1 component (Picture 3)
  4. Connect the "Out" output pin of the IntegerToUnsigned1 component to the "In" input pin of the UnsignedToDigital1 component (Picture 4)
  5. Click in the "Out" box containing the pins of the UnsignedToDigital1 component to start connecting all the Out pins at once (Picture 5)
  6. 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)

Step 11: Generate, Compile, and Upload the Arduino Code

  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

Step 12: 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

Comments