Interfacing TCS34725 with two VL53L0X issue

Hi all,
I'm trying to connect a TCS34725 colour sensor and a couple of Pololu VL53L0X distance sensors to my Arduino UNO board, using a Grove base shield V2.
I'm tring to get measurements but unfortunately I receive 65535 from both VL53L0X while TCS34725 seems to work fine.
I verified I2C addresses... They are ok.
Supply is 5V, the same for all sensors.
Without the TCS3472, VL53L0X sensors work fine.
I noticed the following:

  • disconnecting the only 5V and 0V wires from the TCS3472 ( before running the sketch) , VL53L0X sensors work fine.
  • if I connect the 5V and 0V wires to the TCS3472 while the sketch is running, VL53L0X sensors continue to work correctly.
  • Same behaviour disconnecting the only SDA and SCL wires from the TCS3472 and connecting them while the sketch is running.
    What am I doing wrong?
    Any idea about this strange behavior?

I attach my arduino test code.

#include <Wire.h>
#include <VL53L0X.h>
#include "Adafruit_TCS34725.h"

VL53L0X sensor1;
VL53L0X sensor2;

unsigned int dist1;
unsigned int dist2;
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_614MS, TCS34725_GAIN_1X);

void setup()
{

  Serial.begin (9600);
  tcs.begin();
  Wire.begin();
  Wire.setClock(100000);
 
  delay(100);
  pinMode(4, OUTPUT);//VL53L0x
  pinMode(6, OUTPUT);//VL53L0x

  digitalWrite(4, LOW);  delay(50);
  digitalWrite(6, LOW);  delay(50);


  pinMode(4, INPUT);
  delay(100);
  sensor1.init(true);
  sensor1.setAddress(0x31);
  sensor1.setTimeout(500);
  sensor1.startContinuous();
  delay(50);

  pinMode(6, INPUT);
  delay(100);
  sensor2.init(true);
  sensor2.setAddress(0x33);
  sensor2.setTimeout(500);
  sensor2.startContinuous();
  delay(50);

  tcs.enable();
  i2cScanner();
}

void loop() {
  getDist();
  delay(500);
  RGB();
  delay(500);
}
void getDist() {
  dist1 = sensor1.readRangeContinuousMillimeters();
  dist2 = sensor2.readRangeContinuousMillimeters();
  Serial.print("dist1= ");  Serial.print(dist1);
  Serial.print(" / ");
  Serial.print("dist2= "); Serial.println(dist2);
}

void RGB() {
  float red, green, blue;
  tcs.getRGB(&red, &green, &blue);
  Serial.print("R:\t"); Serial.print(int(red));
  Serial.print("\tG:\t"); Serial.print(int(green));
  Serial.print("\tB:\t"); Serial.print(int(blue));
  Serial.print("\n");
}

The TCS34725 requires a supply voltage from 2.7-3.6V. That can definitely cause strange behavior.

During the first test I used 3.3V to supply the TCS sensor. Unfortunately I got the same issue....I'll try to repeat test using 3.3V for all sensors ...

And the I2C bus at 3.3V as well?

Which one? Post a link to the exact sensor.

It is a 3.3V device and you must use logic level shifters with a 5V Arduino. If they are not included on the sensor module, you may have damaged or destroyed it.

Pololu's products usually (if not always) include the level shifters.

When starting to work with new I2C devices, always run the I2C address scanner program to test communications and look for address conflicts.

Hi,
Can we please have a circuit diagram?
An image of a hand draw schematic will be fine, include ALL power supplies, component names and pin labels.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Colour sensor is ZkeeShop TCS34725.

There aren't I2c conflicts. addresses are ok, tested running i2cscanner() inside setup().
All sensors are connected to a SeeedStudio Grove Base Shield V2.
There are 4 x I2C on-board Grove connectors: every connector has four wires, VCC,GND,SCL,SDA.
All sensors have their own Grove Universal 4 Pin 20cm cable. Nothing else.

This is a really bad idea. You should never connect Arduino I/O pins to an unpowered device, as the unpowered device will draw power via the I/O pins. Normally the I2C bus would not work at all under these conditions, but that depends on the circuitry of the mystery boards you have.

Same behaviour disconnecting the only SDA and SCL wires from the TCS3472 and connecting them while the sketch is running.

I don't understand this either. The TCS3472 should be completely invisible to the rest of the system if the I2C bus is disconnected.

If you buy sensors from a reputable manufacturer like Adafruit, Sparkfun or Pololu, you can expect support with such problems.

After several tests, I finally found a quite satisfactory workaround.
I connected the TCS3472 Vin pin to an Arduino digital pin (pin 7 in my sketch).
Within the setup () this pin is set as OUTPUT and forced to LOW (0V) before the VL53L0X sensors initialization process (in this way the TCS3472 cannot interfere with the VL53L0X sensors initialization).
Once the initialization phase has been completed, the TCS3472 is activated by setting pin 7 to HIGH (5V) level.
Now it works!!!

#include <Wire.h>
#include <VL53L0X.h>
#include "Adafruit_TCS34725.h"

VL53L0X sensor1;
VL53L0X sensor2;

unsigned int dist1;
unsigned int dist2;
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_614MS, TCS34725_GAIN_1X);

void setup()
{

  Serial.begin (9600);
  Wire.begin();
  pinMode(5, OUTPUT);//-> VL53L0x XSHUT pin (sensor1)
  pinMode(6, OUTPUT);//-> VL53L0x XSHUT pin (sensor2)
  pinMode(7, OUTPUT);//-> TCS34725 Vin pin
  digitalWrite(5, LOW);  delay(50);
  digitalWrite(6, LOW);  delay(50);
  digitalWrite(7, LOW);  delay(50);
  delay(10);
  pinMode(5, INPUT);
  delay(10);
  sensor1.init(true);
  sensor1.setAddress(0x31);
  sensor1.setTimeout(500);
  sensor1.startContinuous();
  delay(10);
  pinMode(6, INPUT);
  delay(10);
  sensor2.init(true);
  sensor2.setAddress(0x33);
  sensor2.setTimeout(500);
  sensor2.startContinuous();
  delay(10);
  digitalWrite(7, HIGH);
  delay(10);
  tcs.begin();
  i2cScanner();
}

void loop() {
  getDist();
  delay(500);
  RGB();
  delay(500);
}
void getDist() {
  dist1 = sensor1.readRangeContinuousMillimeters();
  dist2 = sensor2.readRangeContinuousMillimeters();
  Serial.print("dist1= ");  Serial.print(dist1);
  Serial.print(" / ");
  Serial.print("dist2= "); Serial.println(dist2); Serial.print("\n");
}

void RGB() {
  float red, green, blue;
  //tcs.enable();
  tcs.getRGB(&red, &green, &blue);
  Serial.print("R:\t"); Serial.print(int(red));
  Serial.print("\tG:\t"); Serial.print(int(green));
  Serial.print("\tB:\t"); Serial.print(int(blue));
  Serial.print("\n");
  Serial.print("\n");
}

Serial Monitor
Scanning...
I2C device found at address 0x29 !
I2C device found at address 0x31 !
I2C device found at address 0x33 !
done

dist1= 156 / dist2= 176

R: 80 G: 88 B: 61

dist1= 134 / dist2= 149

R: 80 G: 88 B: 61

dist1= 89 / dist2= 125

R: 80 G: 88 B: 61

dist1= 77 / dist2= 118

R: 80 G: 88 B: 61

dist1= 46 / dist2= 123

R: 80 G: 88 B: 61

dist1= 46 / dist2= 121

R: 80 G: 88 B: 61

dist1= 139 / dist2= 155

R: 80 G: 88 B: 61

dist1= 139 / dist2= 157

R: 80 G: 88 B: 61

dist1= 138 / dist2= 151

R: 79 G: 88 B: 61

dist1= 137 / dist2= 153

R: 79 G: 88 B: 61

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