- This topic has 2 replies, 2 voices, and was last updated 8 months, 3 weeks 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
3D Printer 3D printer upgrade ABB Arduino Arduino IDE Arduino SAMD boards Aurora AWS CNC Cyclone PCB Factory Cyclone PCB Factory how to build It Display DynamoDB E32 E70 EByte esp01 esp32 esp8266 File System Firmware i2c Library LoRa MicroPython Milling PCB My PCB Networking PCB pinout Power saving Raspberry Pi REST API RF rp2040 SD Card Sensors Sleep and Wake UP SPI STM32 Temperature Tutorial Web Server Wemos D1 mini WiFi