PCF8575 I/O expander board Question about PULL-UPs

Stratocaster
Posts: 1
Joined: Wed May 07, 2025 11:51 pm

PCF8575 I/O expander board Question about PULL-UPs

Postby Stratocaster » Thu May 08, 2025 1:28 am

Hi all,

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:
circuit_image.png
circuit_image.png (1.75 MiB) Viewed 1167 times

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);
}

eriksl
Posts: 199
Joined: Thu Dec 14, 2023 3:23 pm
Location: Netherlands

Re: PCF8575 I/O expander board Question about PULL-UPs

Postby eriksl » Mon Jul 21, 2025 10:28 am

I'd recommend to read the datasheet carefully once again.

lbernstone
Posts: 1133
Joined: Mon Jul 22, 2019 3:20 pm

Re: PCF8575 I/O expander board Question about PULL-UPs

Postby lbernstone » Wed Sep 03, 2025 6:46 pm

When drawing/fritzing this, please use a 2-pin switch so there is no confusion about the connections.
A pull-up resistor should be placed on the MCU side of the switch. This means that in normal operation, the gpio is high, and when the switch opens, the pin goes low.
My guess is that you have the pull-up resistor on the wrong side, and so it is doing nothing but acting as a mini heater.

Who is online

Users browsing this forum: Perplexity-User and 3 guests