I have simple sketch with a single button. See the image of the circuit diagram below. Also see the code below.
The problem: If I use pcf8575.pinMode(0, INPUT), the button never triggers. If I change it to INPUT_PULLUP, it works fine. see code below.
The code I am using is from the examples in the library. It uses INPUT as the pinMode and in the tutorial it show a similar circuit diagram as the one below.
I thought INPUT_PULLUP made use of an internal pullup resistor on the board in this case that would be the PCF8575 board, but this board doesn't have any internal pullups.
My question is why would this work with INPUT_PULLUP but not with INPUT? Or am I just doing something wrong? I tested the voltage when the button is not press and it's ~3.3v. When pressed it's 0v as expected.
thanks in advance for your help.
I using the following boards.
PCF8575 board: https://www.amazon.com/dp/B0CDWTC399? ... asin_title
ESP32-Wroom-32: https://www.amazon.com/dp/B08D5ZD528?r ... title&th=1
This Arduino PCF8575-Library: https://github.com/xreef/PCF8575_library
I am using a 10k ohm pull-up resistor wired to 3.3v.
See circuit diagram:
Code: Select all
#include "Arduino.h"
#include "PCF8575.h"
// Set i2c address
PCF8575 pcf8575(0x26);
void setup()
{
Serial.begin(115200);
pcf8575.pinMode(0, INPUT_PULLUP); // <====== this works, but just INPUT doesn't
pcf8575.begin();
pcf8575.digitalWrite(0, HIGH); //add this after I got it working with INPUT_PULLUP. It would fire first time through the loop.
//If I put a 100ms delay after the pcf8575.begin() in the setup, it wouldn't falsely. I figured setting the pin HIGH would be better adding delays.
}
void loop()
{
uint8_t val1 = pcf8575.digitalRead(0);
if (val1==LOW) Serial.println("KEY 1 PRESSED");
delay(50);
}