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

    ENV Hat 3 and StickC Plus 2 [Wire.513] requestFrom(): i2cRead returned Error 263

    M5 Stick/StickC
    3
    17
    1.2k
    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.
    • P
      PascalS
      last edited by

      Hi everyone,

      I am currently struggeling with getting my newly purchesd ENV 3 Hat and StickC Plus 2 to work.

      Current Error: "ENV Hat 3 and StickC Plus 2 [Wire.513] requestFrom(): i2cRead returned Error 263"

      My code looks like this:

      It is a combination of these two example (Example1, Example2)

      #include "M5StickCPlus2.h"
      #include "M5UnitENV.h"
      
      SHT3X sht3x;
      QMP6988 qmp;
      
      void draw_function(LovyanGFX* gfx) {
          int x      = rand() % gfx->width();
          int y      = rand() % gfx->height();
          int r      = (gfx->width() >> 4) + 2;
          uint16_t c = rand();
          gfx->fillRect(x - r, y - r, r * 2, r * 2, c);
      }
      
      void setup() {
          auto cfg = M5.config();
          StickCP2.begin(cfg);
          int textsize = StickCP2.Display.height() / 60;
          if (textsize == 0) {
              textsize = 1;
          }
          StickCP2.Display.setTextSize(textsize);
          
          if (!qmp.begin(&Wire, QMP6988_SLAVE_ADDRESS_L, 0, 26, 400000U)) {
              Serial.println("Couldn't find QMP6988");
              while (1) delay(1);
          }
      
          if (!sht3x.begin(&Wire, SHT3X_I2C_ADDR, 0, 26, 400000U)) {
              Serial.println("Couldn't find SHT3X");
              while (1) delay(1);
          }
      }
      
      void loop() {
          int x      = rand() % StickCP2.Display.width();
          int y      = rand() % StickCP2.Display.height();
          int r      = (StickCP2.Display.width() >> 4) + 2;
          uint16_t c = rand();
          StickCP2.Display.fillCircle(x, y, r, c);
          draw_function(&StickCP2.Display);
      
            if (sht3x.update()) {
              Serial.println("-----SHT3X-----");
              Serial.print("Temperature: ");
              Serial.print(sht3x.cTemp);
              Serial.println(" degrees C");
              Serial.print("Humidity: ");
              Serial.print(sht3x.humidity);
              Serial.println("% rH");
              Serial.println("-------------\r\n");
          }
      
          if (qmp.update()) {
              Serial.println("-----QMP6988-----");
              Serial.print(F("Temperature: "));
              Serial.print(qmp.cTemp);
              Serial.println(" *C");
              Serial.print(F("Pressure: "));
              Serial.print(qmp.pressure);
              Serial.println(" Pa");
              Serial.print(F("Approx altitude: "));
              Serial.print(qmp.altitude);
              Serial.println(" m");
              Serial.println("-------------\r\n");
          }
          delay(1000);
      }
      

      Produces the following output:

      *[377696][E][Wire.cpp:513] requestFrom(): i2cRead returned Error 263
      [377724][E][Wire.cpp:513] requestFrom(): i2cRead returned Error 263
      -----QMP6988-----
      Temperature: 0.00 C
      Pressure: 0.00 Pa
      Approx altitude: inf m
      -------------

      I am happy for any help to get these two to work :)

      Greetings Pascal

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

        Hello @PascalS

        hmm, your code works for me.

        Note: I don't have an ENV III hat, but I have the ENV III unit which I used to simulate ENV III hat. So it could be something subtle between the two making it work for me.

        That said, I suggest you first try with the ENV III example alone and if that still doesn't work try to only init and read either qmp or sht3x and see how that goes.

        Thanks
        Felix

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

        P 1 Reply Last reply Reply Quote 0
        • P
          PascalS @felmue
          last edited by

          @felmue Thanks for your test.

          Unfortunately I cant get either of them to connect.

          Is their a difference between Hat and Unit? Which library versions did you use?

          ajb2k3A 1 Reply Last reply Reply Quote 0
          • ajb2k3A
            ajb2k3 @PascalS
            last edited by

            @PascalS HATS use different pins to UNITS

            UIFlow, so easy an adult can learn it!
            If I don't know it, be patient!
            I've ether not learned it or am too drunk to remember it!
            Author of the WIP UIFlow Handbook!
            M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

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

              @PascalS

              the only difference between Hat and Unit (apart from the different GPIOs it uses as @ajb2k3 pointed out) is that the Hat is powered by 3.3 V from M5StickCPlus2 whereas the Unit is powerd by 5 V (with an internal DC/DC converter).

              I used the M5Unit-ENV library, copied the code you posted and manually wired the Unit to the Hat port. In other word I used exactly the code you posted without any modifications.

              Sorry, at this point I have not more ideas as to why it wouldn't work on your side.

              Thanks
              Felix

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

              P 1 Reply Last reply Reply Quote 0
              • P
                PascalS @felmue
                last edited by

                @felmue From your posts, I get the feeling that you have a lot of knowledge. :)

                As a last ressort, I tried to find a I2C scanner sketch and ended up with the following code.

                /*********
                  Rui Santos
                  Complete project details at https://randomnerdtutorials.com  
                *********/
                
                #include <Wire.h>
                 
                void setup() {
                  Wire.begin();
                  Serial.begin(115200);
                  Serial.println("\nI2C Scanner");
                }
                 
                void loop() {
                  byte error, address;
                  int nDevices;
                  Serial.println("Scanning...");
                  nDevices = 0;
                  for(address = 1; address < 127; address++ ) {
                    Wire.beginTransmission(address);
                    error = Wire.endTransmission();
                    if (error == 0) {
                      Serial.print("I2C device found at address 0x");
                      if (address<16) {
                        Serial.print("0");
                      }
                      Serial.println(address,HEX);
                      nDevices++;
                    }
                    else if (error==4) {
                      Serial.print("Unknow error at address 0x");
                      if (address<16) {
                        Serial.print("0");
                      }
                      Serial.println(address,HEX);
                    }    
                  }
                  if (nDevices == 0) {
                    Serial.println("No I2C devices found\n");
                  }
                  else {
                    Serial.println("done\n");
                  }
                  delay(5000);          
                }
                

                I was not sure, but in all the sketches they used sda=0 and scl=26.

                If I scan those, I cant get any devices found. However, if I scan the standard sda/scl = 21/22, then I find two devices (propably build into the Stick itself).

                Is this a sign for an hardware failure?

                Greetings Pascal

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

                  Hello @PascalS

                  from your first log I think the ENV III Hat was recognized properly else the log would have ended with either of the "Couldn't find ...".

                  Anyways, please find an I2C scanner for internal, Groove and Hat here.

                  Thanks
                  Felix

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

                  P 2 Replies Last reply Reply Quote 0
                  • P
                    PascalS @felmue
                    last edited by

                    @felmue Thanks for the link.

                    Strangely, they are now not showing up (not found is now in the log). That wasnt before.

                    1 Reply Last reply Reply Quote 0
                    • P
                      PascalS @felmue
                      last edited by

                      @felmue

                      The port scan went as expect, only internals are found.

                      I2C Scan - internal
                      ................................................................................0x51 ......................0x68 ......................
                      I2C Scan - Groove Port
                      ..............................................................................................................................
                      I2C Scan - Hat Port
                      ..............................................................................................................................

                      Does that mean a hardware error?

                      Greetings Pascal

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

                        Hello @PascalS

                        hmm, have you tried to power cycle M5StickCPlus2?

                        1. disconnect USB
                        2. remove HAT
                        3. press and hold power button until green LED lights up
                        4. release power button - green LED goes dark - M5StickCPlus2 is now off
                        5. re-attach HAT
                        6. re-connect USB - M5StickCPlus2 powers on
                        7. re-test

                        Thanks
                        Felix

                        P.S. if that doesn't make the HAT show up in the I2C scan or make it work with the original program then I am afraid that yes, there might be a hardware issue.

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

                        P 2 Replies Last reply Reply Quote 0
                        • P
                          PascalS @felmue
                          last edited by

                          @felmue Thanks for your help :)

                          Propably it is a hardware failure, I do not get any i2c signals back.

                          Wil return it and run it with new hardware. I update the thread when I heard back from the seller.

                          Thanks for your help!

                          Greetings Pascal

                          1 Reply Last reply Reply Quote 0
                          • P
                            PascalS @felmue
                            last edited by

                            @felmue Unfortunately, also a newly bought M5Stick and a newly bought ENV hat didn´t change anything.

                            Could it be that the hat port uses another Wire?

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

                              Hello @PascalS

                              hmm, that is really strange. Do you have any other hat to try if the hat port works for you in general?

                              ENV III hat is supported in UIFlow2. Maybe try with UIFlow2? Just to see if it works that way.

                              Thanks
                              Felix

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

                              P 1 Reply Last reply Reply Quote 0
                              • P
                                PascalS @felmue
                                last edited by

                                @felmue You were right, in UIFlow 2 it worked perfectly fine. However, I need them to work in Arduino, so that it fits with our current framework.

                                Do you know were the difference between UIFlow 2 and Arduino is?

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

                                  Hello @PascalS

                                  at least we know now that the hardware is ok.

                                  Apart from that I am stumped. Sorry.

                                  Thanks
                                  Felix

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

                                  P 1 Reply Last reply Reply Quote 0
                                  • P
                                    PascalS @felmue
                                    last edited by

                                    @felmue Finally I got the solution using separate Wires and PlattformIO to manage my libraries :)

                                    With the following ini file (PlattformIO config file)

                                    [env:miniscale]
                                    platform = espressif32@6.1.0
                                    board = m5stick-c
                                    framework = arduino
                                    lib_ldf_mode = deep
                                    monitor_speed = 115200
                                    build_flags = 
                                    	-DCORE_DEBUG_LEVEL=0
                                    	-Wl,--allow-multiple-definition
                                    lib_deps = 
                                    	https://github.com/m5stack/M5StickCPlus2.git
                                    	m5stack/M5Unit-ENV@^1.0.1
                                    

                                    Not knowing why, but I need the "-Wl" to run at all and the "--allow-multiple-definition" flag for the hat to work in conjunction with sensors mounted to the groove port.
                                    It worked, however, I need to change the I2C begin call from "Wire0" (just called Wire) to the secondary I2C channel Wire1

                                    Before:

                                    while (!qmp.begin(&Wire, QMP6988_SLAVE_ADDRESS_L, 0, 26, 400000U)) {
                                         Serial.println("QMP6988 not found");
                                     }
                                    

                                    After:

                                    while (!qmp.begin(&Wire1, QMP6988_SLAVE_ADDRESS_L, 0, 26, 400000U)) {
                                         Serial.println("QMP6988 not found");
                                     }
                                    

                                    Maybe this helps someone in the future :)

                                    ajb2k3A 1 Reply Last reply Reply Quote 1
                                    • ajb2k3A
                                      ajb2k3 @PascalS
                                      last edited by

                                      @PascalS Now I see the problem.
                                      Wire is hard defined and set to internal.

                                      You need to use Wire1 to access the external devices.
                                      I vaguely remember reading about this issue before but as I don't have arduino I had forgotten about it.
                                      Thanks for the reminder.

                                      UIFlow, so easy an adult can learn it!
                                      If I don't know it, be patient!
                                      I've ether not learned it or am too drunk to remember it!
                                      Author of the WIP UIFlow Handbook!
                                      M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

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