Hi,
I'm experimenting with the PCF8574 expander and there are a couple of things that I don't understand...
The first one is that it is supposed that for setting the pins as inputs, I should write 1 in all of the bits (PCF_01.write8(0b11111111)).
The fact is that if I don't write this byte the pins still work as inputs.
Any idea why?
The second and more important for me is that, when using Interrupts for triggering the readings (I've connected 8 pushbuttons with PullDown resistors to de 8 pins of the expander), I miss some of the pressings of the buttons and in some cases, if one pin stays in HIGH (let's say pin 3), the rest of the press buttons won't work until I push pin 3 again and leave it in LOW position.
If I do the reading in the LOOP (without using the Interrupts), I read everything without problems but I'd like to make the interruption work.
Can anybody tell me what I'm doing wrong?
This is part of the code. I've removed the part in which I show the status of the byte "pinsContent" through 8 LEDs connected to 8 digital Outputs of Arduino UNO because I'm sure it works fine.
#include <Wire.h>
#include <PCF8574.h>
PCF8574 PCF_01(0x20); // Address PCF8574 for I2C communication.
boolean triggerReading = false;
unsigned long prevMillis = millis();
byte pinsContent = 0;
void ISRoutine() { // In case Interrupt occurs, change the flag
if (millis() > prevMillis + 250) {
triggerReading = true;
prevMillis = millis();
}
}
void setup() {
PCF_01.write8(0b11111111); // Set all expander's pins as INPUTS.
pinMode(2, INPUT_PULLUP); // Set Arduino pin for interrupts.
attachInterrupt(digitalPinToInterrupt(2), ISRoutine, CHANGE); // PCF8574 will interrupt through Pin2 in every change on its pins.
}
void loop() {
// If any pin on PCF9574 has changed:
if (triggerReading) {
triggerReading = false; // Reset the flag for next time you need it.
pinsContent = PCF_01.read8(); // Read the status of the pins on the PCF8574 and store it in "pinsContent".
}
}
delay(100);
}
Para_pregunt_sobre_PCF8675.ino (1.66 KB)