gpt4 book ai didi

c++ - 未找到 TCS34725 ... 检查您的连接

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:24 30 4
gpt4 key购买 nike

我的 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;
}
}

最佳答案

鉴于您的硬件和代码之前已经过测试和工作,这显然是由于编译器发生了变化。

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

关于c++ - 未找到 TCS34725 ... 检查您的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50728272/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com