You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Connect the PCF8574 to a Raspberry Pi without anything connected to its 8 pins
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:
Connect pin 0 to ground
Verify that list(pcf.port) == [False] + [True] * 7 (pin 0 pulled to ground)
Set any pin except 0 to low using the indexed syntax: pcf.port[1] = False
Disconnect pin 0 from ground
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.
The text was updated successfully, but these errors were encountered:
Preconditions:
pcf
is an instance ofPCF8574
, verify thatlist(pcf.port) == [True] * 8
(all high due to the weak internal pull-ups)Steps to reproduce:
list(pcf.port) == [False] + [True] * 7
(pin 0 pulled to ground)pcf.port[1] = False
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.
The text was updated successfully, but these errors were encountered: