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

    Arduino code for PaHuB2 + any I2C sensor

    Scheduled Pinned Locked Moved Units
    5 Posts 3 Posters 4.3k Views 1 Watching
    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.
    • E Offline
      EKTan
      last edited by

      Dear all,

      I looking for the sample code reading the values from the I2C module (like ENV III) that is connected to the PaHUB2 socket 0 (PaHUB2 has I2C address 0x71).

      Thank you.

      1 Reply Last reply Reply Quote 0
      • E Offline
        EKTan
        last edited by

        Dear all,
        I'm looking for the sample Arduino code to read the ENV III module that is connected to the PaHUB2 socket 0 (PaHUB2 has an I2C address 0x71).

        Thank you.

        teastainT 1 Reply Last reply Reply Quote 0
        • teastainT Offline
          teastain @EKTan
          last edited by teastain

          @ektan Sorry, this took me all day to write and de-bug.
          It is an ENVIII on position 0 and ENVII on position 1, as that is what I have!

          #include <M5Stack.h>  //use any controller by substituting the library
          #include "M5_ENV.h"
          SHT3X sht30;  // creates ONE instance!!!
          float tmp1 = 12.3;
          float hum1 = 0.0;
          float tmp2 = 12.3;
          float hum2 = 0.0;
          
          void setup() {
            M5.begin();
            M5.Power.begin();
            delay(100);
            Wire.begin();
            sht30.init();
            Wire.beginTransmission(0x70);  //(the PaHub)
            Wire.write(0x00);              //turns off all ports
            Wire.endTransmission();        // as it says!
            M5.Lcd.setTextSize(3);         //or lower for StickC
            M5.Lcd.setTextColor(RED);
            M5.Lcd.print("Setup  ");
            delay(1000);
          }
          void loop() {
            Wire.beginTransmission(0x70);  //(the PaHub)
            Wire.write(0x01);              //turns on port 0, ENV1
            Wire.endTransmission();
            if (sht30.get() == 0) {   // Obtain the data of shT30.  
              tmp1 = sht30.cTemp;     // Store the temperature obtained from shT30.
              hum1 = sht30.humidity;  // Store the humidity obtained from the SHT30.
                       } else {
              tmp1 = 0, hum1 = 0;
            }
            delay(100);
            Wire.beginTransmission(0x70);  //(the PaHub)
            Wire.write(0x02);              //reads the ENV at port 1
            Wire.endTransmission();
            if (sht30.get() == 0) {   // Obtain the data of shT30. 
              tmp2 = sht30.cTemp;     // Store the temperature obtained from shT30.
              hum2 = sht30.humidity;  // Store the humidity obtained from the SHT30.
              } else {
              tmp2 = 0, hum2 = 0;
            }
            delay(100);
            M5.Lcd.fillRect(0, 0, 320, 80, BLACK);
            M5.Lcd.setCursor(5, 5);
            M5.Lcd.print("Temp1=  ");
            M5.Lcd.setCursor(130, 5);
            M5.Lcd.print(tmp1, 1);  //one decimal place
            M5.Lcd.setCursor(5, 50);
            M5.Lcd.print("Temp2=  ");
            M5.Lcd.setCursor(130, 50);
            M5.Lcd.print(tmp2, 1);  //one decimal place
            delay(1000);
          }
          

          There is no PaHub library because the Wire C-code is in-line with the Arduino code.
          This is actually easier to understand and illustrates how the PaHub works.
          -Terry

          Cheers, Terry!

          100% M5Stack addict with several drawers full of product!

          E C 2 Replies Last reply Reply Quote 0
          • E Offline
            EKTan @teastain
            last edited by

            @teastain

            Thank you so much for the help.
            It works perfectly...

            1 Reply Last reply Reply Quote 0
            • C Offline
              crami25 @teastain
              last edited by

              @teastain In Arduino you can uise the PCA9548 library .
              Example : https://randomnerdtutorials.com/tca9548a-i2c-multiplexer-esp32-esp8266-arduino/

              1 Reply Last reply Reply Quote 0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post