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

    [Solved]M5Stick and VL53L1X

    M5 Stick/StickC
    4
    9
    14.3k
    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.
    • C
      cepics
      last edited by m5-docs

      Hi all,

      I'm trying VL53L1X sensor on M5Stick through grove connection

      VL53L1X---------------------M5Stick
      VIN-------------------------------5v grove
      GRD-------------------------------grd grove
      SDA--------------------------------G21 grove
      SCL---------------------------------G22 grove

      uploading this sketch

      /*
        This example shows how to take simple range measurements with the VL53L1X. The
        range readings are in units of mm.
      */
      
      #include <Wire.h>
      #include <VL53L1X.h>
      
      VL53L1X sensor;
      
      void setup()
      {
      
        Serial.begin(115200);
        Wire.begin();
        Wire.setClock(400000); // use 400 kHz I2C
      
        sensor.setTimeout(500);
        if (!sensor.init())
        {
          Serial.println("Failed to detect and initialize sensor!");
          while (1);
        }
      
        // Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
        // You can change these settings to adjust the performance of the sensor, but
        // the minimum timing budget is 20 ms for short distance mode and 33 ms for
        // medium and long distance modes. See the VL53L1X datasheet for more
        // information on range and timing limits.
        sensor.setDistanceMode(VL53L1X::Long);
        sensor.setMeasurementTimingBudget(50000);
      
        // Start continuous readings at a rate of one measurement every 50 ms (the
        // inter-measurement period). This period should be at least as long as the
        // timing budget.
        sensor.startContinuous(50);
      }
      
      void loop()
      {
        Serial.print(sensor.read());
        if (sensor.timeoutOccurred()) {
          Serial.print(" TIMEOUT");
        }
      
        Serial.println();
      }
      

      this is the serial monitor output...

      rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
      configsip: 0, SPIWP:0xee
      clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
      mode:DIO, clock div:1
      load:0x3fff0018,len:4
      load:0x3fff001c,len:1100
      load:0x40078000,len:9220
      load:0x40080400,len:6300
      entry 0x400806a4
      Failed to detect and initialize sensor!
      
      

      whats wrong??

      1 Reply Last reply Reply Quote 0
      • E
        ederle.d
        last edited by ederle.d

        M5Stick GROVE Interface SCL: GPIO13, SDA: GPIO25. Look at M5Stick doc

        1 Reply Last reply Reply Quote 0
        • m5-docsM
          m5-docs
          last edited by

          Yes, The grove pins on M5Stick are difference with M5Core.
          0_1552530776691_微信截图_20190314103152.png

          M5Stack documentation URL

          https://docs.m5stack.com

          1 Reply Last reply Reply Quote 0
          • C
            cepics
            last edited by

            Hi, tnks for answering...

            I'm using this setup.

            in the code there isn't setup for pins....

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

              I cant remember the exact code but you need to add
              Wire1.begin(); Note the 1!

              its something like Wire1.begin(13, 25);
              that you need to add after Wire.begin();

              Sorry, I lost my source so cant remember how I solved it.

              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
              • m5-docsM
                m5-docs
                last edited by

                Thanks for your reply. @ajb2k3

                @cepics As @ajb2k3 said, you need use Wire.begin(13, 25); for Grove port IIC initialization for assigning gpio13 and gpio25 to IIC function pins.

                M5Stack documentation URL

                https://docs.m5stack.com

                1 Reply Last reply Reply Quote 0
                • C
                  cepics
                  last edited by

                  Tnks a lot guys!!!!

                  I will try asaic....

                  1 Reply Last reply Reply Quote 0
                  • C
                    cepics
                    last edited by

                    /*
                    This example shows how to take simple range measurements with the VL53L1X. The
                    range readings are in units of mm.
                    */
                    
                    #include <Wire.h>
                    #include <VL53L1X.h>
                    
                    VL53L1X sensor;
                    
                    void setup()
                    {
                      Serial.begin(115200);
                      //Wire.begin();
                        Wire.begin(25, 13); // (SDA, SCL) grove stick
                      //Wire.begin(21, 22); // (SDA, SCL) grove stack
                      Wire.setClock(400000); // use 400 kHz I2C
                    
                      sensor.setTimeout(500);
                      if (!sensor.init())
                      {
                        Serial.println("Failed to detect and initialize sensor!");
                        while (1);
                      }
                      
                      // Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
                      // You can change these settings to adjust the performance of the sensor, but
                      // the minimum timing budget is 20 ms for short distance mode and 33 ms for
                      // medium and long distance modes. See the VL53L1X datasheet for more
                      // information on range and timing limits.
                      sensor.setDistanceMode(VL53L1X::Long);
                      sensor.setMeasurementTimingBudget(50000);
                    
                      // Start continuous readings at a rate of one measurement every 50 ms (the
                      // inter-measurement period). This period should be at least as long as the
                      // timing budget.
                      sensor.startContinuous(50);
                    }
                    
                    void loop()
                    {
                      //Serial.print(sensor.read()); //MM
                      Serial.print(sensor.read()/10); //CM
                      if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
                    
                      Serial.println();
                    }
                    

                    it works!!!

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

                      @cepics said in [Solved]M5Stick and VL53L1X:

                      /*
                      This example shows how to take simple range measurements with the VL53L1X. The
                      range readings are in units of mm.
                      */
                      
                      #include <Wire.h>
                      #include <VL53L1X.h>
                      
                      VL53L1X sensor;
                      
                      void setup()
                      {
                        Serial.begin(115200);
                        //Wire.begin();
                          Wire.begin(25, 13); // (SDA, SCL) grove stick
                        //Wire.begin(21, 22); // (SDA, SCL) grove stack
                        Wire.setClock(400000); // use 400 kHz I2C
                      
                        sensor.setTimeout(500);
                        if (!sensor.init())
                        {
                          Serial.println("Failed to detect and initialize sensor!");
                          while (1);
                        }
                        
                        // Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
                        // You can change these settings to adjust the performance of the sensor, but
                        // the minimum timing budget is 20 ms for short distance mode and 33 ms for
                        // medium and long distance modes. See the VL53L1X datasheet for more
                        // information on range and timing limits.
                        sensor.setDistanceMode(VL53L1X::Long);
                        sensor.setMeasurementTimingBudget(50000);
                      
                        // Start continuous readings at a rate of one measurement every 50 ms (the
                        // inter-measurement period). This period should be at least as long as the
                        // timing budget.
                        sensor.startContinuous(50);
                      }
                      
                      void loop()
                      {
                        //Serial.print(sensor.read()); //MM
                        Serial.print(sensor.read()/10); //CM
                        if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
                      
                        Serial.println();
                      }
                      

                      it works!!!

                      Glad it works and sorry for posting the pins the wrong way around.

                      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