ESP32 I2C randomly stops working
Posted: Sat Jan 18, 2025 7:28 pm
I've been trying to get 2 TCS34725 Color sensors to work, these pcb to be exact: https://www.az-delivery.de/en/products/ ... d_source=1
I use a ESP32 Node MCU I bought here: https://www.berrybase.de/esp32-nodemcu- ... d_source=1
My problem is, that the I2C connection is very unreliable. I'm using 4.7k ohm PullUps on both SDA and SCL. I also use the Adafruit TCS34725 library. Because I can't change the sensor I2C adress, I use two i2c buses on the ESP32. But my problem is that it doesn't recognise the sensors when I initialise both of them at the same time. It also only works sometimes when I use only one sensor, and don't initialise the second. I checked all the sensors and connections multiple times, but can't find the issue. The SDA and SCL cables are ~15cm each.
Here is part of my code:
I use a ESP32 Node MCU I bought here: https://www.berrybase.de/esp32-nodemcu- ... d_source=1
My problem is, that the I2C connection is very unreliable. I'm using 4.7k ohm PullUps on both SDA and SCL. I also use the Adafruit TCS34725 library. Because I can't change the sensor I2C adress, I use two i2c buses on the ESP32. But my problem is that it doesn't recognise the sensors when I initialise both of them at the same time. It also only works sometimes when I use only one sensor, and don't initialise the second. I checked all the sensors and connections multiple times, but can't find the issue. The SDA and SCL cables are ~15cm each.
Here is part of my code:
- Adafruit_TCS34725 leftColorSensor = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_180MS, TCS34725_GAIN_16X);
- TwoWire i2c_left = TwoWire(0);
- Adafruit_TCS34725 rightColorSensor = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_180MS, TCS34725_GAIN_16X);
- TwoWire i2c_right = TwoWire(1);
- int blackThreshold = 300;
- void setup() {
- Serial.begin(115200);
- pinMode(15, INPUT);
- pinMode(14, INPUT);
- pinMode(34, INPUT);
- pinMode(33, INPUT);
- pinMode(27, INPUT);
- i2c_left.begin(21, 22, 100000);
- i2c_right.begin(25, 13, 100000);
- delay(500);
- if (leftColorSensor.begin(0x29, &i2c_left)) {
- Serial.println("Found sensor");
- } else {
- Serial.println("No TCS34725 found ... check your connections");
- while (1);
- }
- if (rightColorSensor.begin(0x29, &i2c_right)) {
- Serial.println("Found sensor");
- } else {
- Serial.println("No TCS34725 found ... check your connections");
- while (1);
- }