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



  • @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' !



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

    @marelli7
    Hello,
    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 !!

    thanks



  • @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!

    https://github.com/m5stack/M5-ProductExampleCodes/blob/master/Unit/EXTIO/Arduino/EXT_IO/EXT_IO.ino

    https://github.com/m5stack/M5Stack/blob/master/examples/Unit/EXT_IO_PCA9554PW/EXT_IO_PCA9554PW.ino

    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() {
    M5.begin();
    Wire.begin();

    Wire.beginTransmission(IOEXT_addr);

    Wire.write(CONFIGPORT0);
    Wire.write(ALLINPUT);
    Wire.endTransmission();

    delay (50);

    Wire.beginTransmission(IOEXT_addr);
    Wire.write((uint8_t)0);
    Wire.endTransmission();
    }

    void loop() {

    Wire.requestFrom(IOEXT_addr,1);

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



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