TCA9555 Library for Arduino
TCA9555 is a 16-bit I2C I/O expander from Taxes Instruments. It allows the easy addition of 16 I/O ports on any device that supports the I2C bus. This makes it attractive for expanding the number of I/O pins on the standard Arduino platform using ATmega328. Up to eight TCA9555′s can be used on the same I2C bus and thus allowing up to an additional 128 digital pins to be added.
Keith Neufeld had provided a basic C library for PCA9555 in his blog post.TCA9555 is an improved version of PCA9555. Functionally speaking, TCA9555 is identical to PCA9555 and both versions have the same pin-out. So the code for PCA9555 can be used with TCA9555 without any change.
To make it even easier to use, I wrote a C++ Arduino library that can be used with either PCA9555 or TCA9555. The library exposes all the functionalities of the chip.
Here is some sample code demonstrating how this library can be used:
#include <Wire.h>
#include <TCA9555.h>
// intializaing TCA9555, A2 A1 A0 are set to 000.
TCA9555 tca9555(0,0,0);
void setup()
{
Serial.begin(9600);
Wire.begin();
//set the pin directions for both ports to
//output
tca9555.setPortDirection(TCA9555::DIR_OUTPUT);
//change P00 (pin 4), P01 (pin 5) and P17 (pin 20) to high.
tca9555.setOutputStates(1<<8 | 3);
//read back the pin states
Serial.print(tca9555.getInputStates());
}
void loop()
{
}
Download TCA9555 Library: TCA9555.tar.gz


Hi, I know this is an old post but could you tell me how this command works please ?
//change P00 (pin 4), P01 (pin 5) and P17 (pin 20) to high.
tca9555.setOutputStates(1<<8 | 3);
I would like to know why you set: 1<<8 | 3 for making P00, P01 and P17 high.
Thanks you for your help. :)
Hi Arien,
It may have been my mistake in the sample code. The function setOutputStates takes a word (16bit), the high byte is P17-P10 and the low byte is P7-P0. so the mask I gave in the sample code (1<<8|3) 00000010000011 should map to port 0,1 and 10 not 17.
Hi,
Thanks for your reply now I know how bitmask works :)
Thank you for this library :)
Great work and it help me a lot :)
Thanks. Glad I could help.