没有找到TCS34725 ...检查你的连接

时间:2018-06-06 19:37:32

标签: c++ arduino arduino-esp8266

我的TCS34725插在ESP8266上。当ESP启动时,我得到了这条消息,因为它无法检测到TCS。

这是ESP中的完整代码,如果有帮助的话!

连接和电线很好,因为它们已经工作了,但是现在,无论是新的传感器,ESP还是电线它都不能识别它(我已经测试了所有的组合,我可以用4个ESP和5个传感器)

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include "Adafruit_TCS34725.h"


const char* ssid = "Karting";
const char* password = "";
char i = 0;
char color; 
WiFiUDP Udp;
unsigned int localUdpPort = 4444;  // local port to listen on
char incomingPacket[255];  // buffer for incoming packets
//char  replyPacket[] = "1";  // a reply string to send back

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);


void setup()
{
  pinMode(14,OUTPUT);
  Serial.begin(115200);
  Serial.println();
  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin("SSID", "PASS");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" connected");

  if (tcs.begin()) {
   Serial.println("Found sensor");
  } else {
   Serial.println("No TCS34725 found ... check your connections");
   while(1);
  }

  Udp.begin(4444);
    Wire.begin(); // join i2c bus (address optional for master)

  Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
  digitalWrite(14,LOW);

}


void loop()
{

  uint16_t r, g, b, c, colorTemp, lux;
  int packetSize = Udp.parsePacket();

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

  Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
  Serial.print("Lux: "); Serial.print(lux); 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(" ");

  if ((r > g) && (r > b) && (colorTemp > 7300) && (colorTemp < 7600))
  {
    i = 1;
    color = 'R';
    digitalWrite(14,LOW);
  }

  if ((g > r) && (g > b) && (colorTemp > 7300) && (colorTemp < 7600))
  {
    i = 1;
    color = 'G';
    digitalWrite(14,LOW);
  }

  if ((b > r) && (b > g) && (colorTemp > 9500) && (colorTemp < 9800))
  {
    i = 1;
    color = 'B';
    digitalWrite(14,LOW);
  }
  else {
    if ((lux >2000 ) && (lux <2500) && (colorTemp > 5800) && (colorTemp < 6400))
    {
    i = 1;
    color = 'W';
    digitalWrite(14,LOW);
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(color);
    Udp.endPacket();
    Serial.println("pupupupute");
    Serial.println(Udp.remotePort());
    }

  if (packetSize!=0)
  {
    digitalWrite(14,HIGH);
    Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
    int len = Udp.read(incomingPacket, 255);
    if (len > 0)
    {
      Wire.beginTransmission(8); // transmit to device #8
      Wire.write("x is ");        // sends five bytes
      Wire.write(incomingPacket);              // sends one byte
      Wire.endTransmission();    // stop transmitting
      Serial.printf("UDP packet contents: %s\n", incomingPacket);
      incomingPacket[len] = 0;
    }

  }

}
}
void requestEvent() {
  if ( i = 1 )
  {
    Wire.beginTransmission(8);
    Wire.write( color );
    Wire.endTransmission();    // stop transmitting
    i = 0;
  }
}

1 个答案:

答案 0 :(得分:0)

鉴于您的硬件和代码已经过测试并且工作较早,这显然是由于编译器的更改。

转到Arduino IDE板卡管理器,检查您使用的是哪个版本的Esp8266核心。尝试切换到旧版本,其中一个肯定适合你。