How to change the I2C address of EXT.IO2



  • Hello, I have a question.
    I want to implement two EXT.IO2 in M5stack basic.
    To do this, I need to change the I2C address of one of them.
    However, the program I made based on the EXT.IO2 sample sketch could not connect to the unit. (ERROR is responded on begin.) Please tell me what is the problem.
    I don't think it's a hardware issue since UIFlow could change it... :(

    #include <M5Stack.h>
    #include "M5_EXTIO2.h"

    M5_EXTIO2 extio;

    void setup() {
    int t_erro = 0;
    M5.begin();
    extio.begin(&Wire, 21, 22, 0x45);
    if(t_erro){
    M5.Lcd.print("Connect");
    }else{
    M5.Lcd.print("Error");
    }
    extio.setDeviceAddr(0x46);

    }
    void loop() {

    }



  • Hello @Gorilla

    in the program you've posted t_erro is always 0.

    Thanks
    Felix



  • @gorilla As I have a Core Basic and several EXT.IO2s I tried the Sample from M5Stack called DIGITAL_INPUT_OUTPUT downloaded directly, this minute and all I get is "extio Connect Error", same as you, you are not alone!
    I ran my homebrew EXT.IO2 no library version with the C code in-line and it works fine, connected and flashing.
    Attn @felmue I dug up my program from July, from AFTER you added "extio.setPinMode", which worked fine, then, but NOW the same program won't compile and throws error "class M5_EXTIO2' has no member named 'setPinMode'; did you mean 'setAllPinMode'?"
    Please help!



  • Hello @teastain

    there where some changes in the ESP32 Arduino framework which added functionality to setup an ESP32 as an I2C slave. Unfortunately this broke some of the M5Stack libraries.

    Please make sure you re-install the EXTI02 library to get the latest changes. Alternatively check this file M5Unit-EXTIO2/src/M5_EXTIO2.cpp and see if the begin() already has the (int) typecast like below.

    _wire->begin((int)_sda, (int)_scl);
    

    Note: The (int) typecast ensures that the begin() for an I2C master is called (and not an I2C slave).

    Thanks
    Felix



  • @felmue "For testing integrity" I'm using the github EXT.IO Zip download and running the DIGITAL_INPUT_OUTPUT example right from there and then later from my Arduino directory, after checking that both Libraries M5Stack And EXT_IO are up to date.
    Note, stubbornly I am using Arduino 1.8.19.
    The Example would not run until I added Wire.begin(21, 22); delay(1000);
    Seriously. I take it out and the sketch throws errors.
    I am also disappointed that setPinMode "came and went".
    I am becoming discouraged with M5Stack, unfortunately.



  • @felmue
    Oops, I found a mistake and will correct it.
    t_erro = extio.begin(&Wire, 21, 22, 0x45);

    However, even with this modification, "begin" still returns an error.

    Thanks for your reply.



  • @felmue , @teastain
    I have a good report.
    I was able to change my address using this procedure based on everyone's advice.

    1. remove the already installed M5Unit-EXTIO2 from the library folder.
    2. download the latest library from here as a zip file and install M5Unit-EXTIO2-main.
    3. wrote this sketch.

    #include <M5Stack.h>
    #include "M5_EXTIO2.h"

    M5_EXTIO2 extio;

    void setup() {
    int t_erro = 0;
    M5.begin();
    t_erro = extio.begin(&Wire, 21, 22, 0x45);
    if(t_erro){
    M5.Lcd.print("Connect");
    }else{
    M5.Lcd.print("Error");
    }
    extio.setDeviceAddr(0x47);

    }
    void loop() {
    }

    Thanks to you guys for helping me solve the problem. Thank you so much!



  • Hello @Gorilla

    thank you for reporting back. I am glad you figured it out. And yes, there were some recent changes to the EXTIO2 library regarding I2C so getting the latest is key.

    Thanks
    Felix