Class for I2C PCF8574 IO Expander

Today I posted my PCF8574 lib on the playground - -

The PCF8574 class has the following functionality - read8 and write8 (all pins) - these do the actual I2C IO - read and write (1 pin), - toggle(pin), - leftShift(n) and rightShift(n), - value() - returns the last value read. - lastError() - returns the last I2C error code. (0 ==> OK)

As always, comments and remarks are welcome.

Hi Rob, I'm playing with PCF8574 using your class. I want to blink three leds in order one by one; one blink for each: from dark to light to dark again in a loop. And I have a problem with this, because at first all three leds gets light one by one and after that they start to blink - but the blinking is inverse, that means from light to dark to light again.

Are the pins somehow activated (turned HIHG) before they can be used?

After a while I figured out that when I use function write(i, 0), the led on i PIN lights up, and when I use write(i, 1), the i led balckout. Why is it?

Can you post the code you use? (please use code tage - 2nd icon from the right)

Updated the class to version 0.1.05 (which was in the pipeline for ages).

Latest version on Arduino/libraries/PCF8574 at master · RobTillaart/Arduino · GitHub


  • toggleMask(uint8_t mask) // toggle multiple lines
  • rotateLeft(uint8_t n)
  • rotateRight(uint8_t n)
    and some refactoring

An update will come soon to fix a bug - PCF8574 - Write to another pin while input is pulled low sets it low · Issue #38 · RobTillaart/Arduino · GitHub -
This bug will occur if you use one PCF in mixed mode (partly input/partly output)

Note the rotate, shift and toggle functions only work well when all lines are used output.

Hi Rob

I've seen Wire.begin() in class constructor, called for each PCF8574.

Is there any incoming trouble due to multiple calls to Wire.begin(), before entering main() and init() hidden functions ?