- This topic has 2 replies, 2 voices, and was last updated 1 year, 9 months ago by .
- 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
Just like a well-organized workbench, this website uses cookies to function properly and efficiently.
🛠️ The Essentials (Necessary): Some cookies are categorized as necessary and are stored on your browser because they are critical for the basic working of the site.
📊 The Analytics (Third-party): We also use third-party cookies to help us analyze traffic and understand which projects you like the most. These are stored only if you give us the green light.
You can choose to opt-out, but keep in mind that disabling them might make the site experience a bit less "smooth".
| Cookie | Duration | Description |
|---|---|---|
| cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
| cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
| cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
| cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
| cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
| viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
