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

Setting a single pin sets others to "strong low" if they sense a low input #3

Open
egueli opened this issue Oct 8, 2023 · 0 comments

Comments

@egueli
Copy link

egueli commented Oct 8, 2023

Preconditions:

  1. Connect the PCF8574 to a Raspberry Pi without anything connected to its 8 pins
  2. Given pcf is an instance of PCF8574, verify that list(pcf.port) == [True] * 8 (all high due to the weak internal pull-ups)

Steps to reproduce:

  1. Connect pin 0 to ground
  2. Verify that list(pcf.port) == [False] + [True] * 7 (pin 0 pulled to ground)
  3. Set any pin except 0 to low using the indexed syntax: pcf.port[1] = False
  4. Disconnect pin 0 from ground
  5. Print the result of pcf.port[0]

Expected: True
Actual: False

The expected result is True because pin 0 should be set as input since this is the default; and being disconnected from ground, it should be pulled high by the weak pull-up resistor.

The likely reason for the actual value may be here, where it reads from the device to obtain the current pin modes. What the code actually gets is the input states. It shouldn't use this information; rather, it should keep the pin modes in an internal variable and use that to obtain the final byte to send.

A workaround for this bug is to not use indexed setting at all, but always set all the pin modes at once by setting pcf.port to an array of 8 booleans.

Note: I'm actually using a PCF8575C and using the PCF8575 library, which is based on this one but supports 16 pins. I can verify it has the same issue, I'll report a bug there too. Also the "C" makes the pins open-drain, so I ran the steps above with external pull-up resistors.

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

1 participant