PCA9555 Demo Board

Arduino Interface PCA9555 GPIO Expander

by Lewis Loflin
  
  

YouTube Video for this project: PCA9555 32-Bit GPIO Expander with Arduino

In this series I'll be connecting the PCA9555D 32-bit GPIO expander board to an Arduino micro-controller. First we will start out simple with counting from 0 to 255 in binary on eight LEDs.

In part two we will connect a 4X4 keypad to an 8-bit port. Using "polling" the routine getKey() we will check for a key press and return a BCD value from 0 to 16 displayed on the eight LEDs. See Part 2

In part three we will learn to use the interrupt pin to jump to the key scan routine only when a key is pressed. A BCD value is output on the eight LEDs. See Part 3

In part four we will connect a type a Hd44780 type LCD display and learn how to enter data and manipulate character date and strings. In addition to the LCD display we will scan a keypad, use hardware interrupts, all connected through a single PCA9555 module. In addition I'll reveal some code little discussed with Arduino and we will convert/manipulate code for output to the LCD display. See Part 4

This was purchased off of Ebay lacking code examples which is what I'll be doing here. The code can be used with other GPIO expanders. The keypad, LCD display, LEDs are connected as shown above. I redrew the pin outs on the device because the people selling it miss labeled the pins and their pin table was confusing.

Except for the keypad routines which are new most of these are variations of code written for the Mp23016. See Arduino and the MCP23016 GPIO Expander I have found the PCA9555 superior to the Mp23016 in particular in regards to using interrupts and requiring no external RC oscillator.

YouTube Video for this project: PCA9555 32-Bit GPIO Expander with Arduino

Issues with Arduino

I'm now using version 1.0.5 only to run into a score of problems. My older code from version 0022 had to rewritten only to find out many user compiled libraries no longer worked. In addition anything written for the new version wouldn't even load on the older version. In my view this will create endless grief for users and has turned me off to Arduino.

That's not the only bugs I've found. The interrupt control routines attachInterrupt(), detachInterrupt(), interrupts(), and noInterrupts() don't work at all or improperly, at least for me. They did on 0022. This is why I try to avoid user supplied libraries and write my own code. I'll research that interrupt problem later on. I'm using an older NG Arduino with an ATMEGA168 that could be the problem.

The PCA9555D based 32-bit I/O I2C Expander board is for use with any micro-controller such as Arduino, PICAXE, Raspberry Pi, etc. utilizing the I2C standard. There are no external components needed with the only connections being SDA, SCL, VCC and GND. This makes it perfect for embedded systems that require more input/output GPIO pins.

32-bit I/O I2C Expander breakout board features includes:

- Simple I2C interface.
- Unique DIP design make it perfect for prototypes in a breadboard.
- Add 32 additional inputs or outputs to your design over an I2C interface.
- Stand alone module. No external components required.
- I2C address jumpers allow the use of 4 boards for a total of 128 extra I/Os pins.
- On board pull up resistors for INT, SDA and SCL.
- Operating power supply voltage range of 2.3V to 5.5V.
- PWR indication LED.
- All SMD components.
- Small footprint with 2x1 inches in size.
- Interrupt pins for every chip informs of any input change.
- 400kHz clock frequency.

All boards ship by default with addresses 0x20 for U1 and 0x21 for U2 unless buyer ask for specific settings. The board is fully assembled and is 100 percent made in the USA. It comes ready use.

PCA9555 Block Diagram

Command Registers:

0 Input port 0
1 Input port 1
2 Output port 0
3 Output port 1
4 Polarity Inversion port 0 -- 1 will invert bit on read.
5 Polarity Inversion port 1 -- works only on read.
6 Configuration port 0 -- 0 is output, 1 is input
7 Configuration port 1 -- 0 is output, 1 is input

A LED is connected through a 470 ohm resistor to VCC and the INT pin on the module. This displays interrupt on change which is cleared during a read of the port. That is not used in this demo.

Demo 1

The following counts from 0 to 255 binary on LEDs connected to pins 1 - 8.

The address for the 1st PCA9555 is 0x20. There are eight resistor/LED indicators on pins 1 - 8. This demo produces a binary count of 0 to 255 on Port1 on the PCA9555 module. The module has two PCA9555 ICs the 2nd at 0x21.



#include <Wire.h> // specify use of Wire.h library.

int i;
byte temp1;
void setup()

{
  pinMode(2, INPUT);  // IRQ input
  Wire.begin();
  Wire.beginTransmission(0x20);  // setup out direction registers
  Wire.write(0x06);  // pointer
  Wire.write(0x0F);  // DDR Port0 bits 0-3 input 4-7 output 
  Wire.write(0x00);  // DDR Port1 all output
  Wire.endTransmission(); 

  Wire.beginTransmission(0x20);  // 
  Wire.write(0x02);  // pointer
  Wire.write(0x00);  // clear bits 4-7 PORT0
  Wire.endTransmission(); 

  Wire.beginTransmission(0x20);  // invert bit
  Wire.write(0x04);  // pointer
  Wire.write(0xFF);  // invert bits PORT0 on read
  Wire.endTransmission(); 

  // clear LEDs PORT1
  Wire.beginTransmission(0x20);  
  Wire.write(0x03); // begin here
  Wire.write(temp1); 
  Wire.endTransmission();


  // Use 0x21 for LCD display.

  Wire.beginTransmission(0x21);  // setup out direction registers
  Wire.write(0x06);  // pointer
  Wire.write(0x00);  // DDR Port1 all output 
  Wire.write(0x00);  // DDR Port1 all output
  Wire.endTransmission(); 

  // setup port 0 D7 = E; D6 = RS 
  Wire.beginTransmission(0x21); 
  Wire.write(0x02); //pointer
  Wire.write(B10000000); // setup for command mode
  Wire.endTransmission(); 


}  // end setup

void loop() {

  i++; 
  // LEDs to GND PORT 1
  Wire.beginTransmission(0x20);  
  Wire.write(0x03); // begin here
  Wire.write(i); 
  Wire.endTransmission();

  if (i > 255) i = -1;
  delay(500); // delay 500 mSec.// end loop




 


donate