Switches with pull-up resistors to PCF8575 Inputs

Home Forums The libraries hosted on the site PCF8575 16bits i2c digital I/O expander Switches with pull-up resistors to PCF8575 Inputs

Tagged: 

Viewing 2 reply threads
  • Author
    Posts
    • #13981
      Henk le Roux

        Good day Renzo,

        I just wanted to let you know about a possible bug in your PCF8575 library. I have a pull-up resistor connected to one of the input pins of my PCF8575 but reading the pin with your library’s example shows a LOW input, which is not right. A search on this operation yielded this result from a user with a similar experience:

        https://forum.arduino.cc/t/wiring-switches-to-pcf8575-inputs/523465/17

        This long forum post boils down to the fact that page 12 of the PCF8575 datasheet states:

        “Before reading from the PCF8575, all ports desired as input should be set to logic 1.”

        Changing your KeyPressedPin1 example as follows seems to correct this issue:

        
        #include "Arduino.h"
        #include "PCF8575.h"
        
        // Set i2c address
        PCF8575 pcf8575(0x20);
        unsigned long timeElapsed;
        void setup() {
        	Serial.begin(115200);
        
        	pcf8575.pinMode(P1, OUTPUT);
        	pcf8575.begin();
        	pcf8575.digitalWrite(P1, HIGH);
        	pcf8575.pinMode(P1, INPUT);
        
        }
        
        void loop() {
        	uint8_t val = pcf8575.digitalRead(P1);
        	if (val==LOW) Serial.println("KEY PRESSED");
        	delay(50);
        }
        
      • #13982
        Renzo Mischianti
        Keymaster

          Hi Henk,
          It can be possible, in this library (differently from pcf8574 lib) I implemented only INPUT and not INPUT_PULLUP.
          You can try to set to 0 the debounce variable to prevent this problem

          
          #define READ_ELAPSED_TIME 10 // to 0
          

          Bye Renzo

        • #29869
          Istvan
          Participant

            Dear Hank,

            I just want to say a HUGE thank you for sharing your problem. I was stuck with not being able to read input as input_pullup, but after using your code, and setting the p1 to high initially it worked like a charm! Thank you a lot!

            Istvan

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.
        Exit mobile version