PCF8575 input pull-up

I am using Arduino Pro micro and PCF8575 I2C expander module (similar like this). However I am wondering why PCF8575 input pull-up doesn't work. If I don't connect any IO-pins of PCF8575 module, shouldn't below code print 1111111111111111 because of input pull-up? However it prints 0000000000000000. The library I use is this.

#include <PCF8575.h>  //https://github.com/xreef/PCF8575_library

//#include <Wire.h>

PCF8575 pcf8575(0x20);
 
void setup()
{
  Serial.begin(9600);

  for(int i=0;i<16;i++) {
    pcf8575.digitalWrite(i, HIGH);
  }
  
  // Set pinMode to INPUT
  for(int i=0;i<16;i++) {
    pcf8575.pinMode(i, INPUT);
  }
 
  pcf8575.begin();
}
 
void loop()
{
for(int i=0;i<16;i++) {
      pcf8575.digitalWrite(i, HIGH);
  }
  
  PCF8575::DigitalInput di = pcf8575.digitalReadAll();
  Serial.print(di.p15);
  Serial.print(di.p14);
  Serial.print(di.p13);
  Serial.print(di.p12);
  Serial.print(di.p11);
  Serial.print(di.p10);
  Serial.print(di.p9);
  Serial.print(di.p8);
  Serial.print(di.p7);
  Serial.print(di.p6);
  Serial.print(di.p5);
  Serial.print(di.p4);
  Serial.print(di.p3);
  Serial.print(di.p2);
  Serial.print(di.p1);
  Serial.println(di.p0);

  delay(2000);

}

Hi @heke87
Did you run I2Cscanner to make sure the 0x20 address is correct?

No, but if I connect some IO pin to 3V3 then the pin is printed 1. So PCF8575 communicates correctly with Arduino.

Posting a schematic would help. Also what value of pull ups are you using on the I2C bus. Run the scanner just to make us happy:-) It should read the same every time.

Pull up resistors on the PCF8575 pcb are 10kohm (between VCC - SCL and VCC - SDA). I2CScanner prints "I2C device found at address 0x20" everytime. Schematic is this:

Hi
I don't have the micro arduino nor the PCF8575, but I have an arduino mini and a PCF8574 which is similar to PCF8574.
I'm going to mount here on the breadboard and see what goes with your code.

Hi
I used the PCF8575.h library with PCF8574 and got these results with the changes I made to its code.
Note: The I2C address of my PCF is 0x38

11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111

#include <PCF8575.h>  //https://github.com/xreef/PCF8575_library

//#include <Wire.h>

PCF8575 pcf8575(0x38);     // My PCF8574 address

void setup()
{
  Serial.begin(115200);

  pcf8575.pinMode(P0, INPUT);
  pcf8575.pinMode(P1, INPUT);
  pcf8575.pinMode(P2, INPUT);
  pcf8575.pinMode(P3, INPUT);
  pcf8575.pinMode(P4, INPUT);
  pcf8575.pinMode(P5, INPUT);
  pcf8575.pinMode(P6, INPUT);
  pcf8575.pinMode(P7, INPUT);
  pcf8575.begin();
}
//--------------------------------------------------
void loop()
{
   PCF8575::DigitalInput di = pcf8575.digitalReadAll();

    Serial.print(di.p7);
    Serial.print(di.p6);
    Serial.print(di.p5);
    Serial.print(di.p4);
    Serial.print(di.p3);
    Serial.print(di.p2);
    Serial.print(di.p1);
    Serial.println(di.p0);

  delay(2000);

}

I am going to take a SWAG because I do not use a library for that part. That is what it should be reading. When it is initialized the output pins are written as one's. This is because it is a quasi I/O port with week pull up fets and a N-fet as the output driver. Try writing alternating 0x55 and 0xAA between the reads, the bits will switch each time you write the alternate value.

I tried this code (below) which should change pins states between reads but no change. It always writes 0000000000000000. Maybe PCF8575 is broken?

I don't know how to write 0x55 or 0xAA with this library. Could you show code that should worked with only wire.h library? I could test it.

#include <PCF8575.h>  //https://github.com/xreef/PCF8575_library

PCF8575 pcf8575(0x20);
 
void setup()
{
  Serial.begin(115200);

  for(int i=0;i<16;i++) {
    pcf8575.digitalWrite(i, HIGH);
  }
  
  // Set pinMode to INPUT
  for(int i=0;i<16;i++) {
    pcf8575.pinMode(i, INPUT);
  }
 
  pcf8575.begin();
}
 
void loop()
{
  for(int i=0;i<16;i++) {
      pcf8575.digitalWrite(i, HIGH);
  }

  
  
  PCF8575::DigitalInput di = pcf8575.digitalReadAll();
  Serial.print(di.p15);
  Serial.print(di.p14);
  Serial.print(di.p13);
  Serial.print(di.p12);
  Serial.print(di.p11);
  Serial.print(di.p10);
  Serial.print(di.p9);
  Serial.print(di.p8);
  Serial.print(di.p7);
  Serial.print(di.p6);
  Serial.print(di.p5);
  Serial.print(di.p4);
  Serial.print(di.p3);
  Serial.print(di.p2);
  Serial.print(di.p1);
  Serial.println(di.p0);

  for(int i=0;i<16;i++) {
      pcf8575.digitalWrite(i, LOW);
  }

  di = pcf8575.digitalReadAll();
  Serial.print(di.p15);
  Serial.print(di.p14);
  Serial.print(di.p13);
  Serial.print(di.p12);
  Serial.print(di.p11);
  Serial.print(di.p10);
  Serial.print(di.p9);
  Serial.print(di.p8);
  Serial.print(di.p7);
  Serial.print(di.p6);
  Serial.print(di.p5);
  Serial.print(di.p4);
  Serial.print(di.p3);
  Serial.print(di.p2);
  Serial.print(di.p1);
  Serial.println(di.p0);
  
  delay(2000);

}

Do you have a DMM? What does it say? Try to use a LED (with a current limiting resistor) to see if the pins are driven LOW or HIGH or floating.

I measured pins states with DMM and it shows that they are at LOW state (= 0V). I used the code from my first message. I also tried to loop this code to see if pcf8757.digital.ReadAll() mixes something but it didn't change anything and DMM measured still 0V in all 16 IO-pins.

void loop()
{
for(int i=0;i<16;i++) {
      pcf8575.digitalWrite(i, HIGH);
  }
}

IIRC all pins are set to HIGH/INPUT at power up. Try to disconnect it from Arduino, power up and try to measure pins again.

I disconnect PCF8575 from Arduino, only GND and VCC is used. All pins seems to floating when it is measured with DMM.

A post was split to a new topic: Pcf problem with extra inputs

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.