I have a design dilema dual sensors on an I2C bus

I'm trying to wire up 2 sensors to an I2C bus on an ESP32 based board.

  1. VL6180X
  2. VL530L0

Some of you already know the dilema here, which is these two sensors share the same address on the bus 0x29.

I could simply wire one sensor to the standard bus interface pins and the other to a different set of pins. From a hardware perspective, not an issue. However, the problem comes from the fact that the Adafruit library expects only a single I2C bus and that each device has a unique address.

OK, I underdstand there are shut down pins on both boards that can be used to disable each sensor.

I can't find any reference on how to wire these enable/disable pins up. Can I simply configure any GPIO as output and set it low?

It's frustrating because having to do this completely negates the whole reason to use a bus at all because I need to treat each sensor individually by enabling and disabling each sensor. And will these sensors work by enabling and disabling them in this way?

The other approach is to disable the VL6180X and re-program the VL530L0 address.

Any ideas here?

Thanks!

The data sheets have that information. VL6180X

The device data sheets are your best source of advice, and the first place you should look.
In this case, they also explain the advantages provided by the shutdown input.

@jgilmore11
Looks like the VL53x shutdown pin is low-active. The 6180 chip select is low-active. So it might be worth setting both pins with one Arduino DO, and then talking to whichever is activated by the level you set on the DO. HIGH should enable the VL53X, LOW should enable the 6180.
At least, that's what a quick flip through both data sheets gave me. Alternatively, drive each with a separate DO, and alternately enable each device and talk to it.

You've already been given a link to the 6180 datasheet, here's the other one you need:
https://www.st.com/resource/en/datasheet/vl53l0x.pdf
Page 14 of the latter seems to indicate you'll want to wait a bit after raising shutdown, as there's a boot process involved. Still, it's only 1.2 ms.

1 Like

After thinking about it for a while, I think that the easiest solution is to use Wire and Wire1. They are already defined for the ESP32, you only have to do a .begin for both.

void setup()
{
  Wire.begin();     // use default 21 (SDA) and 22 (SCL)
  Wire1.begin(18, 19);  // use your own numbers
  ...

Please don't use a "TwoWire" in the sketch, that is something from the past. Both Wire and Wire1 are available to use.

The Adafruit VL530L0 library can select Wire or Wire1 as you can see here.
The Adafruit VL6180X library can also select Wire or Wire1 as you can see here.

I have gone through the data sheets of the sensors and have discovered that their individul slave addresses are different. Therefore, the two sensors can be operated in parallel using I2C Bus.

Skave Address of VL6180X: 010 1001 (0x29, 7-bit)

Slave Address of VL530L0: 101 0010 (0x52, 7-bit)

If you think that 0x52 is an 8-bit number, then it is an I2C Bus address (0101 0010) for write operation. In that case, the I2C Bus address for read operation would be 0101 0011 (0x53).

I would suggest that you connect the sensors one-by-one, upload the scanner program, and then find the 7-bit slave addresses of the sensors.
Scanner Program for ESP32:

#include<Wire.h>
byte busStatus;

void setup()
{
  Serial.begin(9600);
  Wire.begin(21, 22);    //GPIO 21 = SDA, GPIO 22 = SCL
  for (int i2cAddress = 0x00; i2cAddress < 0x80; i2cAddress++)
  {
    Wire.beginTransmission(i2cAddress);
    busStatus = Wire.endTransmission();
    if (busStatus == 0x00)
    {
      Serial.print("I2C Device found at address: 0x");
      Serial.println(i2cAddress, HEX);
    }

    else
    {
      Serial.print("I2C Device not found at address: 0x");
      Serial.println(i2cAddress, HEX);
    }
  }
}

void loop()
{

}
1 Like

Thank you!

Reading the addressing info in detail, I see you are indeed correct, @GolamMostafa. Well done.

Interestingly, I found Adafruit docs that say 0x29 for the VL53l0X, and Sparkfun docs for the VL6180x that also say 0x29. So that may be the source. The OP should clarify.

Isn't that embarrassing. As is often the case, we can't even trust the most basic of information.

1 Like

Thank you! I'll give that a try.

Thank you! I'll try that.

Thank you! I appreciate the response.

The primary source of information is the manufacturer's data sheets; while, the informatiom provided by the makers of break-out boards are edited.

@jgilmore11 Please, if this resolves the issue, reply on this thread with a resolution, for the benefit of others who find this in future. Give @GolamMostafa the 'solution' tick, as he went the extra mile.

1 Like

Sure, but in the case of a company producing a product, it's embarrassing them, not us. Such misleading info will result in many assuming their newly-bought product is junk.
Had you or I been faced with this, we'd know to look deeper at the data sheet, but for the learners they are targeting, not so much. It's stupid.

2 Likes

Adafruit has fixed something here:

afbeelding

And use the "default" of 0x29 here:

afbeelding

It was the week before Christmas and two sensors lived at the same house at number 0x29. Since there was only one chimney, Santa Clause could only deliver the Christmas gifts to one of the sensors. One of the sensors had a rental contract for house number 0x52, but then Adafruit fixed that. What ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.