cancel
Showing results for 
Search instead for 
Did you mean: 

VL53L4CD can't measure distances below 70mm when interfaced with ESP32-S3?

Nithinkr
Visitor

I've interfaced the VL53L4CD with ESP32-S3, but I'm unable to get accurate ranging values below 70mm.

I'm using the ESP32-S3 with Arduino IDE.

How can I resolve this issue ?

#include <Wire.h>
#include "vl53l4cd_class.h"

#define SDA_PIN 8
#define SCL_PIN 9

VL53L4CD sensor(&Wire, -1); // -1 = XSHUT not used

void setup() {
 Serial.begin(115200);
 delay(1000);

 Wire.begin(SDA_PIN, SCL_PIN);
 Wire.setClock(400000);

 Serial.println("VL53L4CD Init...");

 if (sensor.begin() != 0) {
  Serial.println("VL53L4CD not detected");
  while (1);
 }

 Serial.println("VL53L4CD detected");

 sensor.VL53L4CD_SetRangeTiming(50, 0); // 50ms timing
 sensor.VL53L4CD_StartRanging();
}

void loop() {
 uint8_t dataReady = 0;
 VL53L4CD_Result_t results;

 sensor.VL53L4CD_CheckForDataReady(&dataReady);

 if (dataReady) {
  sensor.VL53L4CD_GetResult(&results);
  sensor.VL53L4CD_ClearInterrupt();

  Serial.print("Distance: ");
  Serial.print(results.distance_mm);
  Serial.println(" mm");
 }

 delay(20);
}

Edited to apply source code formatting - please see How to insert source code for future reference.

0 REPLIES 0