VL53L4CD works with "STM32duino VL5374CD" library but not the Pololu "VL53L1X" library

I struggled for a long time to try and get the VL53L4CD (product id #3692) to work with the recommended library (from the Resources list on the product page). I am using a Xiao esp32C3 uc. I tried the library examples and could not get past the point where it tries to initialize the sensor. I also tried adding my own pullups to the SDA/SCL lines (since I had to do that with a similar sensor that I tried - apparently the pullup values in the ESP32 were an issue). With or without the pullups, the library would always say that it failed to initialize the sensor. I switched to the “STM32duino VL53L4CD” library and those examples worked immediately. I am planning to work from that library but I wondered if I’m missing something re: the pololu library or if maybe the library has a problem with ESP32?

Rob

Hello, Rob.

We tried our VL53L4CD Arduino library here with an ESP32C3 and were not able to reproduce the same behavior. The only modification we needed to make to the Continuous example program was removing the while (!Serial) {} at the beginning of setup, and we did not need to add any additional pull-ups. So, whatever is going wrong likely has something to do with your particular setup. Is it possible anything changed with your hardware or connections between testing our library and the STM32duino library?

Since you already have it working with the STM32duino library, it probably makes sense to just keep using that. However, if you’d like help looking into this more, please post some pictures of your setup that show all of the connections along with details about all of the hardware you are using (your ESP32C3 board, power supply, etc.).

- Patrick

No pullups, just the connection to the sensor as shown in the photo. The wires are about 6" long. Modifications to the Pololu library were removing while (!Serial) {} and adding a small delay to the top of the setup function. Modifications to the STM32duino library were removing any references to the LED and again, adding a small delay to the top of setup. No other changes. The STM library works fine. The Polulu library says that it can’t initialize the sensor. I also tried specifying the SDA/SCL pin numbers with Wire.begin() but that had no effect.

Your connections look okay, and it worked for us using the same connections. Can you confirm that XSHUT is 3.3V when you power the system? Also, please post a screenshot of your Arduino IDE with the “Tools” menu expanded while your ESP32 is connected so we can see your settings.

What happens if you remove the if statement with sensor.init() from the example? Can you also try making the init() check work as a while loop that waits until sensor.init() returns true instead of only doing a single check, like this:

  while (!sensor.init())
  {
    Serial.println("Failed to detect and initialize sensor!");
    delay(500);
  }

If those modifications do not reveal anything, the next step would probably be to modify the library to print out what the sensor is actually returning during init() so you can see how it is actually failing.

- Patrick