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

    Bad Ultrasonic distance measure

    Scheduled Pinned Locked Moved Units
    4 Posts 3 Posters 6.3k Views
    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.
    • A Offline
      aafortinet
      last edited by

      My ultrasonic sensor reports a bad distance. For example, I measure to the ceiling of the room, and it reports 80 cm where it is above 2 meters.

      I have:

      • a Ultrasonic range sensor
      • a M5 CoreInk. The sensor is connected on GPIO 32 and 33.

      This is how I do it. Can you tell me what's wrong or an idea how to debug? thx

      #define M5_I2C_ADDR_ULTRASONIC 0x57
      Ink_Sprite InkPageSprite(&M5.M5Ink);
      
      void setup() {
        M5.begin(); //Init CoreInk.  
        digitalWrite(LED_EXT_PIN,LOW);
        
        if( !M5.M5Ink.isInit()) //Init CoreInk screen.
        {
          Serial.printf("[-] M5Ink init failed");  
          while (1) delay(100);
        }
      
        Wire.begin(32,33);
        Serial.printf("[+] Wire begin done\n");
      
        M5.M5Ink.clear();   //Clear screen. 
        Serial.printf("[+] Clearing eInk screen\n"); 
        delay(1000);
      
        if( InkPageSprite.creatSprite(0,0,200,200,true) != 0 ){
          Serial.printf("[-] Ink Sprite create failed");
        }
       
      }
      
      void loop() {
        static float distance = 0;
        distance = readDistance();
        Serial.printf("Distance=%.1f cm\n",distance);
        if ((distance < 150) && (distance > 0)) {
            char buffer[30];
            sprintf(buffer,"%.1f cm",distance);
            InkPageSprite.drawString(15,150,buffer,&AsciiFont24x48);
            InkPageSprite.pushSprite();
        }
      
        // Sleep 
        delay(2000);
      }
      A 1 Reply Last reply Reply Quote 0
      • A Offline
        aafortinet @aafortinet
        last edited by

        @aafortinet after more measures, the ultrasonic sensors seems to work correctly. It's just that (1) the units in my program were wrong, (2) it does not work below 2cm and above 150 and gives erroneous answer then. This range isn't very big, and typically I measured 2m.

        C 1 Reply Last reply Reply Quote 0
        • G Offline
          Genio
          last edited by

          Which kind of sensor are you using? is the ultrasonic unit?
          https://shop.m5stack.com/products/ultrasonic-distance-unit-i-o-rcwl-9620?variant=42084187930881

          1 Reply Last reply Reply Quote 0
          • C Offline
            creakygate @aafortinet
            last edited by

            @aafortinet A mate of mine had the same issue -- seemed not to work until he used it within the 2-150cm parameters. The all good.

            1 Reply Last reply Reply Quote 2

            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