How to use multiple VL53L5CX Sensors
Hello all,
I am having difficulty using multiple VL53L5CX sensors on the same I2C bus on my Jetson Nano. I am able to get a single one working but not multiple. I am following the procedure in the documentation by pulling the LPn low of the sensor I don't want to change the address of and then changing the address of the other sensor, then pulling the LPn pin high again. When I run my program it outputs the following:
Opened ST TOF Dev = 11
Opened ST TOF Dev = 12
test
Sensor detected
Sensor Initialized
Set Address failed 254.
When I run i2cdetect -y -r 1 it shows 2 devices detected at 0x20 and 0x29, but I am not changing the address of the other sensor to 0x20. Here is the relevant section of my code below:
// setup GPIO for enable pins
int gpio_init = gpioInitialise();
gpioSetMode(7, JET_OUTPUT);
gpioSetMode(8, JET_OUTPUT);
gpioWrite(7,0);
gpioWrite(8,0);
gpioWrite(7,1);
gpioWrite(8,1);
VL53L5CX_Configuration dev;
VL53L5CX_Configuration dev2;
uint8_t is_alive, status, is_ready;
uint8_t is_alive2, status2, is_ready2;
VL53L5CX_ResultsData Results;
status = vl53l5cx_comms_init(&dev.platform);
status = vl53l5cx_is_alive(&dev, &is_alive);
status2 = vl53l5cx_comms_init(&dev2.platform);
status2 = vl53l5cx_is_alive(&dev2, &is_alive2);
gpioWrite(7,0);
gpioWrite(8,0);
gpioWrite(7,1);
gpioWrite(8,1);
printf("test\n");
if(status || status2)
{
printf("VL53L5CX comms init failed\n");
return -1;
}
if ((!is_alive || status) || (!is_alive2 || status2)) {
printf("VL53L5CX Not Detected\n");
return status;
}
else{
printf("Sensor detected\n");
//return status;
}
status = vl53l5cx_init(&dev);
status2 = vl53l5cx_init(&dev2);
if(status || status2){
printf("Sensor Not Initialized\n");
return status;
}
else{
printf("Sensor Initialized\n");
}
gpioWrite(7,0);
status2=vl53l5cx_set_i2c_address(&dev2,0x98);
gpioWrite(7,1);
if(status2){
printf("Set Address failed %u \n",status2);
return status2;
}
// set both sensors to 8x8 resolution
status = vl53l5cx_set_resolution(&dev, VL53L5CX_RESOLUTION_8X8);
if(status){
printf("Set resolution sensor 1 failed\n");
}
status2 = vl53l5cx_set_resolution(&dev2, VL53L5CX_RESOLUTION_8X8);
if(status2){
printf("Set resolution sensor 2 failed\n");
}
status = vl53l5cx_start_ranging(&dev);
status2 = vl53l5cx_start_ranging(&dev2);My LPn pins are connected to GPIO 7 and 8. Any help is appreciated.
