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?
Code:
#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) {
Serial.begin(9600);
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(" ");
}
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.
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:
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?
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.