cancel
Showing results for 
Search instead for 
Did you mean: 

How to use multiple VL53L5CX Sensors

samir6577
Associate II

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.

4 REPLIES 4
John E KVAM
ST Employee

I think I see the issue.

Think of the LPn as 'off'.

Start with both 'off' (LPn down).

Then lift one LPn and bring the first sensor on line. 

Then issue the I2C change address. 

That part is now safely tucked away. 

Feel free to lift the other LPn and do the same. 

Do NOT drop the LPn pins - that resets the chip and you have to start all over.

A word of caution. 

An I2C address of 0x29 (default) is the same as a write address of 0x52 and a read address of 0x53.

Some systems spec the base address, and some the write address. 

Oddly, it's up to you to figure out which one your I2C system likes to use. 

- john

 


Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'

Hi John,

 

Thanks, for your reply. Using your advice and then editing the platform.c file to add the write address of 0x66 (for a 7-bit address 0x33) I was able to get 2 sensors working at 7-bit addresses 0x33 and 0x29, thank you very much! One thing I noticed was that only using power off is the I2C address reset and that toggling I2C_RST does not reset the modified the modified address. Are you able to confirm that this is the case? Furthermore my final application will require 4 sensors on one bus, do you know if the VL53L5CX-SATEL boards that I am using have sufficient pull-up resistors on SDA and SCL for this use case?

 

Thanks,

Samir

John E KVAM
ST Employee

Good job on the I2C address setting. 

Actually, dropping the LPn pin will basically turn off the sensor. And it clears the address. The I2C_RST is useful if for some reason the I2C encountered a glitch and the bus hung. (The dreaded 'bus stuck low' problem.)

It will clear the current I2C transaction, but not reset anything. 

The amount of pullup you need depends not only on the satellite board, but on the wire length as well.

As a software guy, I'd suggest using two different I2C busses. Most MCUs that have one have an option for a second I2C. But I'm not smart enough to tell you about how much pull-up you need.

- john

 


Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'

Thanks for your response John. One thing to note is that on the VL53L5CX-SATEL boards there is a power enable pin "PWREN" which I had forgot about which when toggled will reset the address. Toggling LPn for me by itself didn't have that effect, I suppose the intention there is that LPn for all other sensors can be low while addresses are changed to accommodate multiple sensors and when pulled high again those addresses won't be reset? Also in the user manual UM2884 VDDIO, AVDD and LPn must be toggled to perform a reset, but nevertheless my program using multiple sensors is now working, thank you!