2026-01-31 1:48 AM - last edited on 2026-01-31 2:14 AM by Andrew Neil
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.