Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pins are not able to trigger eachother #14

Open
netpipe opened this issue Jul 25, 2018 · 1 comment
Open

pins are not able to trigger eachother #14

netpipe opened this issue Jul 25, 2018 · 1 comment

Comments

@netpipe
Copy link

netpipe commented Jul 25, 2018

when i bridge pins P0 and P1 together with this code it reads 0 untill i connect P1 to vcc. also this behavior seems to make push button rotary encoders not work.

PortExpander_I2C library works better in this regard if you want to use as reference.

i think its better to have the pins high then goto ground to read states

#include "Arduino.h"
#include "PCF8574-swire.h"

// Set i2c address
PCF8574 pcf8574(0x20,6,7);
unsigned long timeElapsed;
void setup()
{
	Serial.begin(115200);

	pcf8574.pinMode(P0, OUTPUT);
	pcf8574.pinMode(P1, INPUT);
	pcf8574.begin();
    pcf8574.digitalWrite(P0, HIGH);
}

void loop()
{
    pcf8574.digitalWrite(P0, HIGH);
     delay(50);
	uint8_t val = pcf8574.digitalRead(P1);
 Serial.println(pcf8574.digitalRead(P1));
	if (val==HIGH) Serial.println("KEY PRESSED");
 
	delay(50);
}
@francescolavra
Copy link

When the code executes pcf8574.digitalWrite(P0, HIGH), its actually configuring P0 as input (a PCF8574 pin cannot be configured as output with high value); so in your loop() function you have both P0 and P1 configured as inputs, and if these pins are only connected to each other and not connected to anything else, the input value you read from P1 (and also from P0 for that matter) could be either high or low (PCF8574 pins configured as inputs don't have internal pull-up or pull-down resistors). So if you expect to read 1 from P1, you should connect an external pull-up resistor to this pin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants