- This topic has 2 replies, 2 voices, and was last updated 10 months, 4 weeks ago by .
Viewing 2 reply threads
Viewing 2 reply threads
- You must be logged in to reply to this topic.
Home › Forums › The libraries hosted on the site › PCF8575 16bits i2c digital I/O expander › Switches with pull-up resistors to PCF8575 Inputs
Tagged: Gratitude
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);
}
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
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
More