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)
    #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");

    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.



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

    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?


  • 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.

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

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

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

  • @teastain said in Extend I/O (EXT_IO) how to read inputs? (arduino):

    did you ever figured it out, I am trying to do the same thing but no luck.
    It's quite crazy I couldn't find anyone talking about this online !!


  • @frexeta I don't think so. It's 5 months ago and skipped the 'project'

  • @frexetat I do not have a EXT.IO PCA type, only EXTIO2 with STM, but...could I add: the demo program does not seem to have a "read" in the loop and you must select all pin mode input OR output, which is inconvenient.
    these two links from M5Stack use different sketches!



    Also It is common in controls to use a pull up resistor on the input, maybe 1000 ohms? and connect the switch from the input to ground. Pressing the switch drags the input low, called active low and the signal name is usually "overscored" or preceded with a / symbol: "/sw1".
    As I said last year I do not have the PCA type to test!

    ioCon1.portMode0(ALLOUTPUT); //Set the port as all output in the sketch...maybe set ioCon1.portMode0(ALLINPUT); //Set the port as all input ?

  • Hey guys thanks for your reply.
    I ended up not using this library at all.
    In my case I need all the pins to be inputs which is convenient.

    here is my code if its helpful for anyone ( what I get is one binary number containing all the pins , which I turn into a decimal (0-255) and then use masking (& 128, & 64 ..etc to get all separate button's values):

    #include <Wire.h>
    #include <M5StickCPlus.h>

    #define IOEXT_addr 0x27
    #define CONFIGPORT0 0x03
    #define ALLINPUT 0xFF

    byte rdata = 0xFF;

    void setup() {



    delay (50);


    void loop() {


    if (Wire.available()) rdata = Wire.read();

    Serial.println (String(rdata, DEC));


  • @teastain it happens that calling the function to read just would give always 1 no matter what. Didn't matter if it was in output / INPUTALL or anything.
    I believe there is something wrong with the read function in this library.

    The code I shared works without any issues.
    Pull up resistors are not needed, I don't have any and it works just fine ::)

  • adding a little note :
    the command for ALLINPUTS is hex 0xFF which is 0b11111111 in binaries
    I am quite sure all the 1 are the pins (pin0 being on the right). with 1 being input and 0 being output.
    So 0b11111110 ( hex 0xFE) would probably be all inputs except pin 0 as output etc
    and hex (0x0) is 0b00000000 and actually correspong to the value of ALLOUTPUTS in the other library ...

  • @frexetat Screw the library, we'll just put the raw code in-line!
    Hardcore, love it.

  • I've been working in raw I2C write and M5Stack have told me that there is an issue with digital read functions with the EXTIO2 and the Stamp EXTI/O but won't tell me where the error is?
    Be careful when reading and writing to the EXT2 StampEXT as it is very easy to corrupt the I2C address register.