Extend I/O (EXT_IO) how to read inputs? (arduino)



  • the example 'EXT_IO_PCA9554PW.ino' only explains the Output mode (ioCon1.digitalWrite(i, LOW);) and works OK!
    But ... I need the unit as additional INput for my Core2.

    I'm using the 5V port with 470 Ohm and a push button connected to input pin 0

    My code doesn't work: the output is allways "HIGH" , even when nothing is connected to the input pins)
    code:
    #include "PCA9554.h"
    ...
    unsigned char in0 = 0; //byte in0 = 0;
    bool status0;
    ...
    void loop() {
    status0 = ioCon1.digitalRead(in0);
    if (status0) Serial.println("HIGH"); else Serial.println("LOW");
    delay(500);
    }

    Could someone please explain what I'm doing wrong here?

    The included code returns TRUE or FALSE when reading &pinNumber
    #define PCA9554_h
    ...
    bool digitalRead(byte &pinNumber);



  • Hello @Marelli7

    I think you need to switch the mode to all input before trying to read anything.

    ioCon1.portMode0(ALLINPUT);
    

    Thanks
    Felix



  • That was already in the setup:
    ioCon1.twiWrite(21, 22);
    ioCon1.portMode(ALLINPUT);

    I assume the 0 is not required as ioCon1.portMode(ALLOUTPUT); did work without portMode0()



  • Hello @Marelli7

    my bad. I was looking at this example.

    Have you tried to connect the push button to GND and the input pin?

    Thanks
    Felix



  • Yes I did, and all other pins. The input requires a positive DC voltage, connecting to GND won't help.

    There must be something wrong adressing the input port, even without any wire connected to any port the program reports an input.

    I'll try some other values for in0 in ioCon1.digitalRead(in0);

    I admit that I'm not familiar with (byte &pinNumber). Byte is equal to unsigned char (byte in0=0) didn't work either.
    Using digitalRead(&in0) gives a compile error.

    What value is required for &pinNumber?

    Would be nice to find someone who got this unit working. I can't be the first trying this....



  • The command portMode(ALLINPUT) doesn't seem to do what is expected.
    All pins are giving 3.3V. Pulling this to GND does not change the status of that portreading

    I wonder if this will work in UIFlow (the UIFlow example indicates that each port can be set to Read or Write individual)



  • @marelli7 Hi! Just curious if you have the EXT.IO (Pno. U011 using the PCA9554PW chip) or the newer EXT.IO-2 (Pno. U011-B using the STM32F030 chip) ?
    Obviously the chips are different! But is would be easy to confuse.
    I have the Stamp IO with the STM chip and am familiar with only that one.
    Just trying to help!



  • Terry, thanks !!

    I'm using the EXT.IO PCA. The IO2 with the STM seems not (yet) available in the Netherlands.
    I decided to focus on some other units rather then spending frustrating hours with this ....

    And Yes, I also do have the Stamp I/O with the STM chip. So it would be very helpful to point me to some arduino sketches. I'll check the examples codes also.

    Do you have, by any chance, a working sketch for the rotary encoder (UNIT Encoder) for the Core2 -also with the STM-chip?
    I couldn't get this encoder working on my Core2 and that's why I/m trying to read the encoder using External IO. But would be nice to get both (stamp & encoder) working

    (I'm a newbe to M5Stack but quite familiar with the ESP32)



  • @marelli7 When I got the StampIO with STM I was disappointed that each chip could only be used in one mode, "All Pin Mode". user felmue made a brilliant but astonishingly simple edit to the actual M5Stack StampIO library which was approved by M5Stack. It allows each pin to be a different mode, such as Pin1 Input, Pin2 Output, etc.
    https://imgur.com/EduKPmV

    #include <M5Stack.h>
    #include <M5_EXTIO2.h>
    M5_EXTIO2 extio;
    void setup() {
    M5.begin();
    while (!extio.begin(&Wire, 21, 22, 0x45)) {
    Serial.println("extio Connect Error");
    delay(100);
    }
    extio.setPinMode(1, RGB_LED_MODE);
    extio.setPinMode(0, DIGITAL_OUTPUT_MODE);
    }

    void loop() {
    extio.setLEDColor(1, 0x0f << (8)); //RGB sk6812 type
    delay(1000);
    extio.setLEDColor(1, 0x0f << (16));
    extio.setDigitalOutput(0, HIGH); // standard mini LED with resistor
    delay(1000);
    extio.setDigitalOutput(0, LOW);
    delay(1000);
    }

    Otherwise, sorry, I don't have any Encoder code!
    Neat profile picture, tho' !