I am working on a project to read from several Lux sensors, but I am having an issues that I cannot figure out.
after running fro somewhere between 15 seconds to 3 min the system will lock up and stop working. using indicator LEDs I have found that it hangs on the Line:
I’ve recreated the issue with this small modification of the Example code
#include <Wire.h>
#include "SparkFun_VEML6030_Ambient_Light_Sensor.h"
#define AL_ADDR 0x48
#define AL_ADDR2 0x10
SparkFun_Ambient_Light light(AL_ADDR);
SparkFun_Ambient_Light light2(AL_ADDR2);
// Possible values: .125, .25, 1, 2
// Both .125 and .25 should be used in most cases except darker rooms.
// A gain of 2 should only be used if the sensor will be covered by a dark
// glass.
float gain = .125;
// Possible integration times in milliseconds: 800, 400, 200, 100, 50, 25
// Higher times give higher resolutions and should be used in darker light.
int time = 50;
long luxVal = 0;
long luxVal2 = 0;
long loopcount = 0;
void setup(){
Wire.begin();
Serial.begin(115200);
if(light.begin())
Serial.println("Ready to sense some light!");
else
Serial.println("Could not communicate with the sensor!");
if(light2.begin())
Serial.println("Ready to sense some light!");
else
Serial.println("Could not communicate with the sensor!");
// Again the gain and integration times determine the resolution of the lux
// value, and give different ranges of possible light readings. Check out
// hoookup guide for more info.
light.setGain(gain);
light.setIntegTime(time);
light2.setGain(gain);
light2.setIntegTime(time);
Serial.println("Reading settings...");
Serial.print("Gain: ");
float gainVal = light.readGain();
Serial.print(gainVal, 3);
Serial.print(" Integration Time: ");
int timeVal = light.readIntegTime();
Serial.println(timeVal);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){
luxVal = light.readLight();
luxVal2 = light2.readLight();
Serial.print("Ambient Light Reading: ");
Serial.print(luxVal);
Serial.println(" Lux");
Serial.print("Ambient Light 2 Reading: ");
Serial.print(luxVal2);
Serial.println(" Lux");
if((loopcount%2) == 1){
digitalWrite(LED_BUILTIN, HIGH);
} else {
digitalWrite(LED_BUILTIN, LOW);
}
loopcount ++;
Serial.print("Iteration: ");
Serial.println(loopcount);
delay(200);
}
Did you close the ADR jumper on one of the two boards? If you have multiple boards at the same address, that can cause lockups. If it’s not that, you might have a code issue. Another thing to check is how long your I2C (Qwiic) bus is. The shorter it is the more reliable it will be. For testing purposes, use the shortest Qwiic cables we have and see if that helps.