connect two VL6180X sensors with I2C communication

Hello,
for my project I try to retrieve two different distance measurements in order to compare them in real time, for that I use two VL6180X optical sensor using an I2C communication. I did my program and I can not display the values of the two sensors, only one sensor displays the variation of this distance. I have a problem with addressing and I can not find the error.
the code to associate is:

bonjour,
pour mon projet j'essais de récupéré deux mesures de distance différente afin de les comparés en temps réel, pour cela j'utilise deux capteur optique VL6180X utilisant une communication I2C. j'ai fait mon programme et je n'arrive pas à afficher les valeurs des deux capteurs, seulement un capteur affiche la variation de ca distance. j'ai un problème concernant l'adressage et je n'arrive pas as trouver l'erreur.
le code associer est:

#include <Wire.h>
#include <VL6180X.h>
#define ADRESSE1 0x29
#define ADRESSE2 0x52

VL6180X sensor1;
VL6180X sensor2;
void setup()
{
Serial.begin(9600);
Wire.begin();
sensor1.init();
sensor2.init();
sensor1.configureDefault();
sensor2.configureDefault();
sensor1.setAddress(ADRESSE1);
sensor2.setAddress(ADRESSE2);

//sensor1.setScaling(SCALING);
//sensor2.setScaling(SCALING);
sensor1.setTimeout(500);
sensor2.setTimeout(500);
}

void loop()
{
Serial.print(sensor1.readRangeSingle());
Serial.print(" mm\t\t");
Serial.print(sensor2.readRangeSingle());
Serial.print(" mm");
Serial.println();
}

Here is the datasheet, looks like the device wants pull up resistors: https://www.st.com/resource/en/datasheet/vl6180x.pdf

When you use an I2C scanner do both sensors show up or just one?


From reading this datasheet on the Sparkfun module:

Communication with the VL6180X is via the I²C bus. The default 7-bit address of the
VL6180X is 0x29. It can be changed by the user to any 7-bit addresses by writing to the
I2C_SLAVE__DEVICE_ADDRESS {0x212} register. The SCL and SDA lines should each
have a pull-up resistor on the I²C bus


So if you have 2 sensors in circuit with the same address, how can one talk to an individual sensor to change its address, would be an issue.

Hi,
If you have two I2C devices with the same address, this circuit will let you use them both.
The extra output pins 8 and 9 select which device you are using.

This was a project I did for my workplace using VCNL4010 sensors.


Tom... :slight_smile:

Idahowalker:
So if you have 2 sensors in circuit with the same address, how can one talk to an individual sensor to change its address, would be an issue.

Looks like you'd have to put only one device on the bus and set its address to other than default. Once that's done, connect the second device holding the default address.