PCF8574 library for ESP8266-01

Hi there,
Trying use ESP8266-01 (ESP01) module along with a PCF8574T module with Adafruit library and few more, but failed.

tested with;

Anyone could suggest a PCF8574T library which would work with ESP01 module please?

#include <pcf8574_esp.h>
#include <ESP8266WiFi.h>
#include <Wire.h>

TwoWire testWire;
PCF857x pcf8574(0x20, &testWire);

void setup() {
  WiFi.persistent(false);
  WiFi.mode(WIFI_OFF);
  WiFi.forceSleepBegin();
  delay(1);

  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  delay(1000);
  Serial.println("serial connected!");

  testWire.begin(0, 2);
  testWire.setClock(100000L);
  pcf8574.begin();

  Serial.println("Found PCF8574");
  delay(500);

  // DO NOTE: When you write LOW to a pin on a PCF8574 it becomes an OUTPUT.
  // It wouldn't generate an interrupt if you were to connect a button to it that pulls it HIGH when you press the button.
  // Any pin you wish to use as input must be written HIGH and be pulled LOW to generate an interrupt.
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
}

void loop() {
  Serial.println("in the loop..");
  digitalWrite(0, LOW);
  delay(1000);
  digitalWrite(0, HIGH);
  digitalWrite(1, LOW);
  delay(1000);
  digitalWrite(1, HIGH);
  digitalWrite(2, LOW);
  delay(1000);
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  delay(1000);
  digitalWrite(3, HIGH);
}

serial monitor I see only the following, but none of the LEDs are blinking.

serial connected!
Found PCF8574
in the loop..
in the loop..
in the loop..

Thanks.

I suggest that you look at the examples that come with the PCF8574 library.

One problem is probably that digitalWrite() will not control the PCF8574 pins but the normal pins of the ESP8266.

2 Likes

code was from an example.

you are absolutely correct. example code uses a different method

pcf8574.write(7, pcf8574.read(3));

Let me do the fixes and report back. thanks so much for highlighting.

You can try my lib - GitHub - RobTillaart/PCF8574: Arduino library for PCF8574 - I2C IO expander
Verified to work with AVR, ESP32 and RP2040 so I expect ESP8266 should work too
It has plenty examples.

Used the PCF8574 also in - GitHub - RobTillaart/I2CKeyPad: Arduino libray for 4x4 (or smaller) KeyPad connected to an I2C PCF8574

1 Like