APDS-9960_RGB_and_Gesture_Sensor icon indicating copy to clipboard operation
APDS-9960_RGB_and_Gesture_Sensor copied to clipboard

APDS 9960 clone initialization problem

Open Queequack opened this issue 10 months ago • 0 comments

First of all: The (cloned) sensor works perfectly. My question mainly relates to a method for implementing my workaround generically and reliably.

With some clones, apds.init() (with SparkFun_APDS9960 apds = SparkFun_APDS9960();) can return false. The initialization therefore fails. A clever guy has found a solution for this: In SparkFun_APDS9960.h, change the line #define APDS9960_ID_1 from 0xAB to 0xA8 (not b but 8 [eight]).

As I work with several boards and environments, I am now trying to overwrite the library value in platformio.ini with build_flags = -D APDS9960_ID_1=0xA8. This also works... Halfway there. Without changing the value in the library itself (separately for each environment), my main problem is: I am processing the status of the sensor. Because then, the initialization (init()) returns always false and the sensor is classified as non-functional in my application. Related and expected warning during the build process:

In file included from include/APDS9960.h:5,
                 from src/main.cpp:32:
.pio/libdeps/RoomPanel_esp32-s3-devkitc-1-n16r8v_OTA/SparkFun APDS9960 RGB and Gesture Sensor/src/SparkFun_APDS9960.h:34: warning: "APDS9960_ID_1" redefined
#define APDS9960_ID_1           0xAB

I'm not sure if the warning means that a) the library value is being overwritten or b) the build_flag value in my config is being overwritten Apparently overwriting the library value does not work properly.

Two scenarios with changes in the two files:

First and it works platformio.ini: No content that affects the sensor (no build flag) SparkFun_APDS9960.h: #define APDS9960_ID_1 0xAB CHANGED from 0xAB to 0xA8. The sensor and the init() work error-free without exception.

But I would like to implement this variant: Second and that does not work reliably platformio.ini: build_flags = -D APDS9960_ID_1=0xA8 SparkFun_APDS9960.h: Not changed (still #define APDS9960_ID_1 0xAB) The following initializations work (setProximityIntLowThreshold(...), setProximityIntHighThreshold(...), enableProximitySensor(...), setProximityGain(...), enableLightSensor(...)). However, the behavior is not reproducible. I noticed differences when I flashed via different environments (e.g. via USB or via OTA): Case 1, init() returns false, but sensor returns correct values:

  • Light sensor delivers correct values (e.g. around 1000 in daylight, somewhat in the shade)
  • Proximity sensor and Itnerrupt work as expected

Case 2 init() returns false, sensor returns incorrect values:

  • Light sensor provides correct values between 10 and 20 (instead of around 1000 in comparison)
  • Proximity sensor repeatedly triggers at values between approx. 3 and 6

Regards

Queequack avatar Jan 10 '25 10:01 Queequack