The SATEL-VL53L8CX dev boards were all out of stock, so I picked up the LS53LX-SlL8 Light Saber Sensor VL53L8CX by Gilisymo for debugging before I build my own PCB. I am interfacing with the sensor via the Adafruit itsy bitsy nRF52840 (but have also used the xiao nRF52840 Sense and the ESP32-S3 QtPy for debugging purposes).
I had previously been able to work with the VL53L5CX easily using the Sparkfun library with a very similar set up. However, using the STM32duino library I can't communicate with the sensor via my nRF52840. The
vl53l8cx_set_i2c_address() function fails some of the time, and other times it will succeed but the following vl53l8cx_is_alive() function will fail. My physical set up (with this devboard) is connecting ground to ground, 3v to Vin, SDA to SDA, SCL to SCL, and the A3 GPIO pin of my MCU to the LPn pin. I have validated that the A3 pin is responsive when I digitalWrite high and low, so it should function as a LPn control pin. I am also certain that the pins are connected correctly. I tried using an I2C scanner to make sure the default address in the library is correct (the macro for default address is set to 0x52) and I found that the I2C scanner sometimes finds 0x14 and other times it finds 0x29, but never 0x52. I am not sure if this is an artifact of the I2C address missing the read/write bit in the scanner, but this is interesting because 0x52 is 0b1010010, 0x29 is 0b101001, and 0x14 is 0b10100, so it is as if the I2C address keeps getting shifted.
Interestingly, the ESP32-S3 with the exact same physical set up and code will allow the sensor to initialize but then never receives data. But I was hoping to use the nRF52840 specifically because I can power it at 1.8v to get 1.8v logic level for IOVDD on this sensor.
Is this an issue with interfacing with the nRF52 specifically? I am confused because I am using the devboard as intended and the API out of the box with no modifications.
Here is my code, and it never makes it passed is_alive() but often gets stuck at setting the I2C address:
#include <Arduino.h>
#include <Wire.h>
#include <vl53l8cx_class.h>
#define LPN_PIN A3
VL53L8CX sensor_vl53l8cx_top(&Wire, LPN_PIN);
void setup() {
// Initialize serial for output.
Serial.begin(115200);
pinMode(LPN_PIN, OUTPUT);
// Initialize I2C bus.
Wire.begin();
sensor_vl53l8cx_top.begin();
uint8_t status = VL53L8CX_STATUS_OK;
uint8_t isAlive = 0;
// Reset the sensor by toggling the LPN pin
sensor_vl53l8cx_top.vl53l8cx_off();
sensor_vl53l8cx_top.vl53l8cx_on();
status = sensor_vl53l8cx_top.vl53l8cx_set_i2c_address(0x29);
while(!status) {
Serial.println("address not set");
delay(1000);
}
status = sensor_vl53l8cx_top.vl53l8cx_is_alive(&isAlive);
while(!status) {
Serial.println("Not Alive");
delay(1000);
}
status = sensor_vl53l8cx_top.vl53l8cx_init();
while(!status) {
Serial.println("Not init");
delay(1000);
}
}