xreef / PCF8575_library

i2c 16bits digital expander with i2c digital expander for Arduino, Raspberry Pi Pico and rp2040 boards, esp32, SMT32 and ESP8266. Can read write digital values with only 2 wire. Very simple and encoder support. Uncommet NOT_SEQUENTIAL_PINOUT define to have pins like datasheet and not sequential one.
MIT License
53 stars 19 forks source link

Ports as inputs not work at all #14

Closed viktak closed 6 months ago

viktak commented 10 months ago

Hi, First of all, thanks for all your hard work on this and the PCF8574. That one I use all the time with no problems. Recently, I tried to do the same things with the PCF8575. All the ports work as expected as OUTPUT like this:

void setup(){
    Wire.begin(SDA_GPIO, SCL_GPIO);

    for (size_t i = 0; i < 16; i++)
        pcf.pinMode(i, OUTPUT);

    for (size_t i = 0; i < 16; i++)
        pcf.digitalWrite(i, HIGH);

    pcf.begin();
}

void loop(){
    if (millis() - i2cMillis > 250)
    {
        for (size_t i = 0; i < 16; i++)
            pcf.digitalWrite(i, 1 - pcf.digitalRead(i));

        i2cMillis = millis();
    }
}

Awesome! But when I try to use the ports as input they fail miserably:

void setup(){
    Wire.begin(SDA_GPIO, SCL_GPIO);

    for (size_t i = 0; i < 16; i++)
        pcf.pinMode(i, INPUT);

    pcf.begin();
}

void loop(){
    PCF8575::DigitalInput di = pcf.digitalReadAll();
    SerialMon.printf("%u - %u - %u - %u - %u - %u - %u - %u\r\n", di.p0, di.p1, di.p2, di.p3, di.p4, di.p5, di.p6, di.p7);
}

resulting in this:

0 - 0 - 0 - 0 - 0 - 0 - 0 - 0

Looking at the circuit with an oscilloscope I can see that although all the pins are pulled up to 3.3V with a 10k resistor, the PCF8575 pulls them down constantly to Gnd.

I have already spent 2 days on trying to figure out what went wrong, but I'm stuck. Any idea what I'm missing?

Thanks for any pointers!

ps: my environment is Windows 11 64 bit, VS Code with PlatformIO. and this is the relevant bit of platformio.ini:

##################################################
#   ENVIRONMENT
##################################################

[env:esp32s3]
board = esp32-s3-devkitc-1

platform = espressif32
framework = arduino

##################################################
#   PRE-BUILD
##################################################
extra_scripts = 
    pre:../../scripts/preIncrementBuildNumber.py
    platformio_upload.py

##################################################
#   BUILD
##################################################

build_type = release

board_build.filesystem = littlefs

lib_deps =
    ; xreef/PCF8574 library @ ^2.3.6    
    xreef/PCF8575 library @ ^1.1.1

##################################################
#   UPLOAD
##################################################

upload_protocol = esptool
upload_port = COM5
upload_speed = 921600
mariusmotea commented 7 months ago

I have the same issue, but not sure how they worked in some previews tests. Looks like when are declared as inputs the pins output LOW.

Update: the pins are working, but they draw about 100mA because of the very low internal resistance (~30ohm)

viktak commented 7 months ago

@mariusmotea Did you actually try it with pull up resistors? I'm asking, because I did, and it did not make a difference..