Adding on I2C two sensors with the same address

hi,

I m trying to add two sensors on I2C with the same address and create, in the ls /dev, two instances: range_finder0 and range_finder1. I saw in the Px4 code that it is not possible/support for this, correct me if I m wrong. The command I used to run is: vl53l5x start -X -b 1 R 25 for the first sensor and vl53l5x start -X -b 1 R 0 for the second sensor. I used one GPIO to choose between the sensors: when 1 is low, the second high. I can create two instances for the sensors, only if I comment the ‘continue’ from if (iterator.instance()) { PX4_WARN("Already running on bus %i", iterator.bus()); continue; }.
Is it a good start for adding support for the two sensors and create the two instances? I mention also that my problem with this is that I am reading the data from one sensor in the both instances:range_finder0 and range_finder1. Any ideas?

Thanks :slight_smile:

You should not have multiple I2C devices with the same I2C address on the same bus. Does your pixhawk provide multiple i2c busses? Does the vl53l5x provide an option to set a different I2C address? Do you have a documentation available for vl53l5x? If all these do not work, I am considering writing some kind of support for tca9548a, which can handle the i2c address conflict.

Hi,
1.PX4 has multiple busses but I must use one: I2C1
2.No, does not. Has only one 0x52;
3.yes, I have.
I must use this I2C one both but toggling the GPIO pin. So, is not a good idea my start according your answer. It has not two addresses but has this GPIO pin and the possibility to set the device in low power mode.
So, is that the only possibility, with the multiplexer? Thanks :slight_smile:

Oh, I overread your GPIO pin.

A quick solution might be to not create multiple i2c instances. So for example you could run:

vl53l5x start -X -b 1 R 25 -Q 0

If the GPIO pin is high, you publish the distance with 25 (R ) as orientation. Otherwise with 0 (Q). I cannot find any code regarding vl53l5x, but this seems easy to implement.

yes, my idea was the same. I implemented it like this: vl53l5x start -X -b 1 -R 24 -E but you need to create two instance: VL53L5X *instance0 and VL53L5X *instance1 and one implementation to module_start part:
if (iterator.instance()) {
PX4_WARN(“Already running on bus %i”, iterator.bus());
continue;
}
I implemented in this way but: when I start an instances: start -X -b 1 -R 24 -E , I read the same distance/or another measure from the sensor in both: range_finder1 and range_finder0 even if the id device is different and One sensor is off .