Arduino esp32 and VL53L5CX

Hello.

I have an issue using VL53L5CX with Arduino ESP32 nano.
The SparkFun_VL53L5CX breakout board is used.

The ESP32 and VL53L5CX are wired with the SDA and SCL with 3.3V and Ground.
I have not wired any of the other pins.

The below code is from the example and results in:

"Data not ready"

Any ideas?

#include <Arduino.h>
//VL53L5CX
#include <Wire.h>
#include <SparkFun_VL53L5CX_Library.h>


SparkFun_VL53L5CX VL53L5CX_TOF;
VL53L5CX_ResultsData measurementData; // Result data class structure, 1356 byes of RAM


int imageResolution = 0; //Used to pretty print output
int imageWidth = 0; //Used to pretty print output


void setup() 
{
  Serial.begin(115200);
  delay(5000);
  Serial.println("SparkFun VL53L5CX Imager Example");

  Wire.begin(); //This resets to 100kHz I2C
  Wire.setClock(400000); //Sensor has max I2C freq of 400kHz 
  
  Serial.println("Initializing sensor board. This can take up to 10s. Please wait.");
  if (VL53L5CX_TOF.begin() == false)
  {
    Serial.println(F("Sensor not found - check your wiring. Freezing"));
    while (1) ;
  }
  
  VL53L5CX_TOF.setResolution(8*8); //Enable all 64 pads
  imageResolution = VL53L5CX_TOF.getResolution(); //Query sensor for current resolution - either 4x4 or 8x8
  imageWidth = sqrt(imageResolution); //Calculate printing width

  VL53L5CX_TOF.startRanging();
}

void loop() 
{
  //Poll sensor for new data
  if (VL53L5CX_TOF.isDataReady() == true)
  {
    if (VL53L5CX_TOF.getRangingData(&measurementData)) //Read distance data into array
    {
      //The ST library returns the data transposed from zone mapping shown in datasheet
      //Pretty-print data with increasing y, decreasing x to reflect reality
      for (int y = 0 ; y <= imageWidth * (imageWidth - 1) ; y += imageWidth)
      {
        for (int x = imageWidth - 1 ; x >= 0 ; x--)
        {
          Serial.print("\t");
          Serial.print(measurementData.distance_mm[x + y]);
        }
        Serial.println();
      }
      Serial.println();
    }
  }
  else
  {
    Serial.println(F("Data not ready")); 
  }

  delay(1000); //Small delay between polling
}

So you have genuine Sparkfun module and you removed the protection tape from sensor?

Thanks for your reply.
Yes and Yes.

Run the i2c scanner from the examples menu to confirm that the sensor is visible on the bus.

Thanks for you help.

Scanner says:

Scanning...
I2C device found at address 0x29 !
done

Ok, good.

Try removing this line:

Wire.setClock(400000); //Sensor has max I2C freq of 400kHz

Thanks for your help, highly apricated.

Unfortunately this did not solve the problem.
Still the same : "Data not ready"

It was worth trying.

With the sketch you posted, what else do you see before the "data not ready" message on serial monitor?

SparkFun VL53L5CX Imager Example
Initializing sensor board. This can take up to 10s. Please wait.
Data not ready

And anything different after 10s?

I don't see anything in the code that forces it to wait for 10s, so maybe it's normal to see this message until the sensor is ready.

It does not wait 10 seconds it waits about 2 then runs the loop code.

This code in the loop:

if (VL53L5CX_TOF.isDataReady() == true)

Always returns false

FFS the Arduino I was using was broken.
It eventually started rebooting, I replaced it and now the program works.

Thanks for your help!