Hello,
I'm using a PCF8574 (red one) along with NodeMCU (lolin) on i2c D1 & D2. Buttons are connected to ports P0 to P7 with 2.2K pull-ups.
With the following code, and when a button is pressed, I always get (0 when the input port is set to input and 1 when set to input_pullup) on all ports.
Makes me wonder why, as the same configuration works fine on Arduino Uno. (i2c on A4 & A5)
I need to ignore the Uno for its memory limitations.
I've tried different libraries with the same sad result.
What am I missing please help?
#include "Arduino.h"
#include "PCF8574.h"
#define INTERRUPTED_PIN D7
void keyPressedOnPCF8574();
void ICACHE_RAM_ATTR keyPressedOnPCF8574();
PCF8574 pcf8574(0x20, INTERRUPTED_PIN, keyPressedOnPCF8574);
unsigned long timeElapsed;
void setup()
{
Serial.begin(9600);
pcf8574.pinMode(P0, INPUT_PULLUP);
pcf8574.pinMode(P1, INPUT_PULLUP);
pcf8574.pinMode(P2, INPUT_PULLUP);
pcf8574.pinMode(P3, INPUT_PULLUP);
pcf8574.pinMode(P4, INPUT_PULLUP);
pcf8574.pinMode(P5, INPUT_PULLUP);
pcf8574.pinMode(P6, INPUT_PULLUP);
pcf8574.pinMode(P7, INPUT_PULLUP);
pcf8574.begin();
delay(500);
timeElapsed = millis();
}
unsigned long lastSendTime = 0; // last send time
unsigned long interval = 4000; // interval between sends
bool startVal = HIGH;
bool keyPressed = false;
void loop()
{
if (keyPressed){
uint8_t val0 = pcf8574.digitalRead(P0);
uint8_t val1 = pcf8574.digitalRead(P1);
uint8_t val2 = pcf8574.digitalRead(P2);
uint8_t val3 = pcf8574.digitalRead(P3);
uint8_t val4 = pcf8574.digitalRead(P4);
uint8_t val5 = pcf8574.digitalRead(P5);
uint8_t val6 = pcf8574.digitalRead(P6);
uint8_t val7 = pcf8574.digitalRead(P7);
Serial.print("P0 ");
Serial.print(val0);
Serial.print(" P1 ");
Serial.print(val1);
Serial.print(" P2 ");
Serial.print(val2);
Serial.print(" P3 ");
Serial.print(val3);
Serial.print("P4 ");
Serial.print(val4);
Serial.print(" P5 ");
Serial.print(val5);
Serial.print(" P6 ");
Serial.print(val6);
Serial.print(" P7 ");
Serial.println(val7);
keyPressed= false;
}
}
void keyPressedOnPCF8574(){
keyPressed = true;
}