Esp32 + tcs34725

Hello everybody. I am developing a test with the TCS34725 color sensor with the ESP32. I inserted the Adafruit_TCS34725.h library but the system does not work using PlatformIO, but it works normally using the Arduino IDE. Any tips on what it could be? Incorrect library insertion?


#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_TCS34725.h"
#include  <SPI.h>

Exemplo de codigo de interacao entre a ESP32 e o
sensor de cor TCS34725. Este programa usa a biblioteca
da Adafruit. O esquema de ligacao eh:

ESP32 ====  TCS34725
Vin   ====  Vin
GND   ====  GND
22    ====  SCL
21    ====  SDA

/* Inicializar bib com valores padrao (int time = 2.4ms, ganho = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();

/* Inicalizar bib com valores especificos de tempo e ganho */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_614MS, TCS34725_GAIN_1X);

void setup(void) {

  if (tcs.begin()) {
    Serial.println("Sensor encontrado");
  } else {
    Serial.println("Sensor nao encontrado ... verifique as conexoes");
    while (1);

void loop(void) {
  uint16_t r, g, b, c, tempCor, lux;

  tcs.getRawData(&r, &g, &b, &c);
  // tempCor = tcs.calculateColorTemperature(r, g, b);
  tempCor = tcs.calculateColorTemperature_dn40(r, g, b, c);
  lux = tcs.calculateLux(r, g, b);

  Serial.print("Temp. da cor: "); Serial.print(tempCor, DEC); Serial.print(" K - ");
  Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
  Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
  Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
  Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
  Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
  Serial.println(" ");

Can you specify what exactly is not working?
Please also show the content of your platformio.ini

Use the preformatted-text when posting code, ini or logs (see How to post logs and code in PlatformIO Community Forum).

I can upload to the ESP32 normally, but I always receive the message: “No TCS34725 found … check your connections”. However, using the Arduino IDE, color detection works normally.


Yes, that’s the wrong one.


lib_deps = 
  adafruit/Adafruit TCS34725@^1.4.4

See PlatformIO Registry

Thank you very much for your feedback, sir. But the problem remains. With the code presented, I accessed Quick Access → Libraries and added it as shown in the figure:

Furthermore, the platfomio.ini file is as follows:

platform = espressif32
board = fm-devkit
framework = arduino
lib_deps = adafruit/Adafruit TCS34725@^1.4.4

Finally, although the code is normally transferred to ESP, the program gets stuck at the instruction: “No TCS34725 found … check your connections

Unfortunately, I do not have such a sensor and therefore cannot test it.

If it works with the ArduinoIDE and not with PlatformIO you have to find out the differences.

I would start with the Arduino core version. Which Arduino core version are you using with the ArduinoIDE and which Espressif32 version are you using with PlatformIO?

Arduino IDE v 1.8.19

On PlatformIO:

Please show the installed espressif32 platform version. And the Arduino Core Version you use in Arduino IDE!

Just as general notes: PlatformIO and the Arduino IDE should behave the same if you,

  1. Use the same Arduino-ESP32 core between them (Arduino IDE: Tools → Boards → Board Manager → esp32, PlatformIO: releases)
  2. Use the same board configuration (Arduino IDE: Tools → Board and general tools menu, PlatformIO: boards and configuration)
  3. Use the same library versions (Arduino IDE: Used library versions in verbose output)

Thank you very much @sivar2311 and @maxgerhardt , I really made a basic mistake. The platform chosen in PlatformIO was incorrect. I am using ESP32 Dev Module. I changed it to the correct option in PlatformIO and everything worked correctly. Thanks for the support.