Skip to content

Latest commit

 

History

History
77 lines (55 loc) · 2.63 KB

README.md

File metadata and controls

77 lines (55 loc) · 2.63 KB

Pca95x4 - I2C GPIO Expander

The PCA95x4 provides 8 bits of General Purpose parallel Input/Output (GPIO) expansion for I2C-bus applications. Not to be confused with the PCA954x, which is a group of I2C bus multiplexers.

Documentation

  • Philips I2C IO expanders application notes can be found here

NXP

Texas Instruments

Board

Connection Diagram

Usage

This example shows how to write value out to 8 LEDs using a PCA95x4 device and a RPi3.

I2cConnectionSettings i2cConnectionSettings = new(1, 0x38);
I2cDevice i2cDevice = I2cDevice.Create(i2cConnectionSettings);
pca95x4 = new Pca95x4(i2cDevice);

Cycle output bits

pca95x4.Write(Register.Configuration, 0x00);  // Make all outputs.
pca95x4.Write(Register.OutputPort, 0xFF);  // Set all outputs.

for (int bitNumber = 0; bitNumber < 8; bitNumber++)
{
    pca95x4.WriteBit(Register.OutputPort, bitNumber, false);  // Clear output.
    Thread.Sleep(500);
    pca95x4.WriteBit(Register.OutputPort, bitNumber, true);  // Set output.
}

Read Input Port

pca95x4.Write(Register.Configuration, 0xFF);  // Make all inputs.
byte data = pca95x4.Read(Register.InputPort);
Console.WriteLine($"Input Port: 0x{data:X2}");

Check Input Register Polarity Inversion

pca95x4.Write(Register.Configuration, 0xFF);  // Make all inputs.
byte data = pca95x4.Read(Register.InputPort);
Console.WriteLine($"Input Register: 0x{data:X2}");
pca95x4.InvertInputRegisterPolarity(true);
data = pca95x4.Read(Register.InputPort);
Console.WriteLine($"Input Register Polarity Inverted: 0x{data:X2}");
pca95x4.InvertInputRegisterPolarity(false);
data = pca95x4.Read(Register.InputPort);
Console.WriteLine($"Input Register: 0x{data:X2}");

Binding Notes

PCA9534/PCA9554 and PCA9534A/PCA9554A are identical except for a few differences.

  • The removal of the internal I/O pull-up resistor which greatly reduces power consumption when the I/Os are held LOW.
  • Each has a fixed I2C address. This allows for up to 16 of these devices (8 of each) on the same I2C bus.