I’m using this sensor in a project involving an AI model run on a Raspberry Pi. The data is read first on an Arduino UNO R3. This is the error I’m getting now:
Sensor does not appear to be connected. Please check wiring. Freezing...
I’ve checked all the wiring. I’ve made sure everything is up to date. I’ve also tried using both internal and external pullups. I tried using an I2C scanner, and the sensor did show up correctly with the address of 0x49. It just never shows up when I use my code. Very, very rarely, it does work. Can you please help? I had a fully working project, but it stopped working correctly recently. I need to have this wrapped up as soon as possible. I have a couple of images attached of the setup, sorry they aren’t the clearest. I appreciate any help you can provide.
Here is my code:
#include "SparkFun_AS7265X.h" //Click here to get the library: http://librarymanager/All#SparkFun_AS7265X
AS7265X sensor;
const int btn = 7;
void serialFlush(){
while(Serial.available() > 0) {
char t = Serial.read();
}
}
void setup()
{
Serial.begin(115200);
pinMode(btn, INPUT);
pinMode(20, INPUT);
pinMode(21, INPUT);
if (sensor.begin() == false)
{
Serial.println("Sensor does not appear to be connected. Please check wiring. Freezing...");
while (1)
;
}
sensor.disableIndicator();
}
bool wait = true;
bool pressed = false;
int bState = 0;
void loop(){
while (pressed == false) {
bState = digitalRead(btn);
if ((bState == HIGH) && (pressed == false)){
Serial.println('b');
pressed = true;
}
}
while (wait) {
if (Serial.available() > 0) {
wait = false;
}
}
sensor.takeMeasurementsWithBulb(); //This is a hard wait while all 18 channels are measured
Serial.print(sensor.getCalibratedA()); //410nm
Serial.print(",");
Serial.print(sensor.getCalibratedB()); //435nm
Serial.print(",");
Serial.print(sensor.getCalibratedC()); //460nm
Serial.print(",");
Serial.print(sensor.getCalibratedD()); //485nm
Serial.print(",");
Serial.print(sensor.getCalibratedE()); //510nm
Serial.print(",");
Serial.print(sensor.getCalibratedF()); //535nm
Serial.print(",");
Serial.print(sensor.getCalibratedG()); //560nm
Serial.print(",");
Serial.print(sensor.getCalibratedH()); //585nm
Serial.print(",");
Serial.print(sensor.getCalibratedR()); //610nm
Serial.print(",");
Serial.print(sensor.getCalibratedI()); //645nm
Serial.print(",");
Serial.print(sensor.getCalibratedS()); //680nm
Serial.print(",");
Serial.print(sensor.getCalibratedJ()); //705nm
Serial.print(",");
Serial.print(sensor.getCalibratedT()); //730nm
Serial.print(",");
Serial.print(sensor.getCalibratedU()); //760nm
Serial.print(",");
Serial.print(sensor.getCalibratedV()); //810nm
Serial.print(",");
Serial.print(sensor.getCalibratedW()); //860nm
Serial.print(",");
Serial.print(sensor.getCalibratedK()); //900nm
Serial.print(",");
Serial.print(sensor.getCalibratedL()); //940nm
Serial.println();
wait = true;
pressed = false;
serialFlush();
}
I added voltage dividers to shift the logic levels down to 3.3v, and this still isn’t working. I mean, the logic levels are correct, and my multimeter is reading 3.19 volts on SDA and the same on SCL. This is while running the I2C scanner script. The power and status lights are both on. Now, however, the I2C scanner is not detecting the board. Is it more likely an Arduino-side issue, or something with the sensor itself?
You said Ear it was working with the I2C scanner sketch, what changed since then?
Resistor dividers are slow but might be fast enough for the scanner and might fail with the app sketch. I recommend getting a logic level shifer board, that will be able to handle higher speeds.
Sensor does not appear to be connected. Please check wiring. Freezing…
I added the print value of value in the SparkFun_AS7265X.cpp file as shown in the figure below, where the arrow points. The small probability of value is 48 or 50, and the high probability is 0.
And if I press the reset button multiple times, there is a small probability that the sensor data can be obtained, but there is a high probability that the data cannot be obtained and the above error will be reported.
If your problem is solved, I hope you can share your solution with me.
hello, I need some more help: I bought a fresh sensor from the website as the old one didn’t even work with serial. I am trying to test with the example code. Now, it just prints
“AS7265x Spectral Triad Example”
and stops. I have switched to a logic level shifter as well.
After encountering the same problem using the ESP32-C6-MINI, I implemented a for loop to give the sensor some additional chances to initialize. This has solved the problem for me:
Serial.println("AS7265x Spectral Triad Example");
for (int j=0; j<15;)
{
sensor.begin();
delay (50);
if (sensor.begin()==true)
j=50
;
else
{
Serial.print("Sensor failed to initialize, retrying... ");
Serial.print(j+1);
Serial.println("/15");
j++;
}
}