mcauser / micropython-pcf8574

MicroPython driver for PCF8574 8-Bit I2C I/O Expander with Interrupt
MIT License
37 stars 6 forks source link

Not sure what I am doing wrong, device is on the bus, running module code always get ETIMEDOUT response? #3

Open Jibun-no-Kage opened 3 weeks ago

Jibun-no-Kage commented 3 weeks ago

Using MicroPython 1.24. Copied the pcf8574.py file into my ESP32 module, happen to be using thonny IDE. Run the following code...

import pcf8574
from machine import I2C

#
theI2C = I2C(0)
thePCF8574 = pcf8574.PCF8574(theI2C, 0x20)

thePCF8574.pin(2)

Just trying to read pin 2 for example. And I get the following error...

Traceback (most recent call last):
  File "<stdin>", line 51, in <module>
  File "pcf8574.py", line 36, in pin
  File "pcf8574.py", line 56, in _read
OSError: [Errno 116] ETIMEDOUT

I know the device is on the i2c bus...

theI2C.scan()
[32]

So not sure what I am doing wrong?

mcauser commented 3 weeks ago

ETIMEDOUT happens when the device isn't found on the bus, or doesn't respond in time. Does .scan() always show [32] or sometimes []? Does every pin read fail, or intermittently fails? There's also a .check() method for scanning the bus and raising if not found. I'd check the cables, pull-up resistors. Try adding a 2nd device on the I2C bus.