I am using a pcf8574 board from waveshare to give me 5 key inputs via i2c.
I wired up initially without pullup resistors and was getting intermittent indications of key press and wrong values , so, I stuck in some 10k resistors and provided 3.5 volts to the circuit. I was still getting odd indications so I thought maybe 5v.
It seemed to be ok for a good while and then I was getting odd key presses again, if I turn power off and wait for 10 min and then turn it all back on its good again, until its not.
So I suspect that I have not got the correct resistors or ......
#include <PCF8574.h>
#include <Wire.h>
#include <TimedAction.h>
PCF8574 PCF_38(0x38); // add switches to lines (used as input)
uint8_t expander = B00100000;
TimedAction timer = TimedAction(100, check_switch_multi);
int val;
void setup()
{
Serial.begin(9600);
PCF8574::PCF8574(expander);
Serial.println("\nTESTPCF8574\n");
}
void loop()
{
timer.check();
}
void check_switch_multi()
{
for (int sw = 0; sw < 5; sw++)
{
val = PCF_38.read(sw);
if (val == 0)
{
Serial.print(sw);
delay(200);
}
}
}
/* ************************************************************** */
void check_switch_single()
{
val = PCF_38.read(0); // get the value for pin i
Serial.print(val);
}
/*
expected serial output of pressing keys in order of 0123401234
Opening port
Port open
TESTPCF8574
0123401234
BUT occasionally I get random key presses the can start and then just continue
01234012340000000000000000000000000000000000000000 ...
0 with no key pressed
sometimes pressing 3 will illicit a 0 in the output
turn off the device wait 10 minutes turn it back on and its working ok again
*/