🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Read SHT30 and SHT40 from ENVIII-HAT and ENVIV-UNIT at the same time

    Units
    3
    5
    1.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      Ivanks
      last edited by

      Is it possible to change the I2C address?

      I'm really interested to use a M5StickC Plus2 with an Unit and Hat sensor without any other hardware to read temperature

      Both sensors SHT30 and SHT40 uses the same address by default (0x44).

      I saw in the datasheet of the components that we can change de I2C address dynamically, but I've tried without any success.

      Also in the sht4x library has two address options

      #define SHT40_I2C_ADDR_44 0x44
      #define SHT40_I2C_ADDR_45 0x45

      Is there a way to do that?

      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by felmue

        Hello @Ivanks

        you are corrrect, SHT30 has an ADDR pin which allows to change the I2C address:

        The address of the sensor can be changed dynamically during operation by switching the level on the ADDR pin.

        However in the ENVIII hat the ADDR pin is connected to GND. See schematic here. This means In order to change the I2C address you'd need to modify your ENVIII on a hardware level.

        In contrast, according to its datasheet, SHT40 doesn't have an ADDR pin - the I2C address is predefined and reflected in the part number (A -> 0x44, B -> 0x45)

        Products Details
        SHT40-AD1B base RH&T accur., 0x44 I2C addr.
        SHT40-BD1B base RH&T accur., 0x45 I2C addr.

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 0
        • robskiR
          robski
          last edited by

          would using pahub be helpfull? to "hide" unit address behind hub address?

          M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ

          1 Reply Last reply Reply Quote 0
          • I
            Ivanks
            last edited by

            Nice, thank you guys for the considerations.

            For now the solution that I've found is to establish a connection once per sensor and end communication.

            I'm not sure if is a good practice with I2C communication, but is working for a simple using.
            Of course it has a little more delay in the measurements.

              if (!sht3x.begin(&Wire1, SHT3X_I2C_ADDR, 0, 26, 400000U)) {
                Serial.println("Couldn't find SHT3X");
                while (1) delay(1);
              }
              if (sht3x.update()) {
                Serial.print("SHT30 - Temperatura: ");
                Serial.print(sht3x.cTemp);
                Serial.print(" - Umidade: ");
                Serial.println(sht3x.humidity);
            
                //DISPLAY
                StickCP2.Display.fillRect(110, 30, 100, 30, BLACK);
                StickCP2.Display.setCursor(5, 30);
                StickCP2.Display.setTextColor(BLUE);
                StickCP2.Display.printf("SHT30: %.1f", sht3x.cTemp);
              }
            
              Wire.end();
              delay(1000);
            
              if (!sht4x.begin(&Wire, SHT40_I2C_ADDR_44, 32, 33, 400000U)) {
                Serial.println("Couldn't find SHT4X");
                while (1) delay(1);
              }
            
              sht4x.setPrecision(SHT4X_HIGH_PRECISION);
              sht4x.setHeater(SHT4X_NO_HEATER);
            
              if (sht4x.update()) {
                Serial.print("SHT40 - Temperatura: ");
                Serial.print(sht4x.cTemp);
                Serial.print(" - Umidade: ");
                Serial.println(sht4x.humidity);
            
                //DISPLAY
                StickCP2.Display.fillRect(110, 60, 100, 30, BLACK);
                StickCP2.Display.setCursor(5, 60);
                StickCP2.Display.setTextColor(YELLOW);
                StickCP2.Display.printf("SHT40: %.1f", sht4x.cTemp);
              }
              Wire.end();
              delay(1000);
            
            1 Reply Last reply Reply Quote 1
            • felmueF
              felmue
              last edited by

              Hello @Ivanks

              I think that is a perfectly valid solution. Thanks for sharing.

              Thanks
              Felix

              GPIO translation table M5Stack / M5Core2
              Information about various M5Stack products.
              Code examples

              1 Reply Last reply Reply Quote 0
              • First post
                Last post