Getting a clone of APDS-9960 to work
A couple of years ago I received several of these beautiful sensors from e-bay that claimed to be both color sensors, proximity sensors, and gesture sensors, reportedly used in mobile phones and similar devices. I was very keen on trying them out. Unfortunately all my attempts failed that time and so I kept them in a bag for some future chance.
They were sold as GY-9960 and are supposed to contain the AVAGO Technologies APDS-9960 Digital Proximity, Ambient Light, RGB and Gesture Sensor (see datasheet at Sparkfun). Sparkfun is also making breakout boards with these chips and so one of those Arduino libraries is from Sparkfun.
When doing a regular yearly counting of the remaining parts in our lab, I already thought: now I throw them away, but let's give it a last try...
But only frustration followed. All examples reported that the sensor could not be initialized:
-------------------------------- SparkFun APDS-9960 - ColorSensor -------------------------------- Something went wrong during APDS-9960 init! Something went wrong during light sensor init! Error reading light values Error reading light values Error reading light values Error reading light values Error reading light values Error reading light values
Tried all the 5 different Arduino libraries for 9960, and nothing worked. Checked the documentation, and there is only one fixed I2C address 0x39. But let's search some more on the net... It looked like some others had more luck, but probably with a bit different boards. Finally, there was this fantastic post from ronin_boss from summer of 2019:
I solved the problem with the Chinese clones !!!!!!!!!!!!!! After about 2 months of torment. The ones that do not go to read the gestures but the other functionalities go .... those that receive the message "Something went wrong during APDS-9960 init!"... In the library, check if the sensor id is 0xAB .. but the id of the Chinese ones is 0xA8 . at least mine ... So ... you need to change in SpurkFun_APDS9960.h line #define APDS9960_ID_1 0xAB with 0xA8 .. and ready. if you use ESP8266 you still have to play with GAINE and BOOST on LEDs for more precise functionality .. other modules may have other ids. aa. and something else. you can use gestures without interrupting pin. In setup, at apds.enableGestureSensor (true) use (false) and modify the sketch. Anyone who wants more details can contact me at ronin_boss@yahoo.com
And indeed! Changing that single constant 0xAB to 0xA8 solved everything. Suddenly all Sparkfun library examples started to work as expected! Interesting! Oh, yes, "B" looks similar to "8". :-)
Here is a small report:
ColorSensor example shows a total ambient light level and RGB values. I tried with a regularly lit workplace at night:
1) white paper
Ambient: 227 Red: 80 Green: 84 Blue: 65
2) pointing flashlight of mobile phone directly on the sensor (very near):
Ambient: 37889 Red: 37889 Green: 37889 Blue: 37889 Ambient: 37889 Red: 37889 Green: 37889 Blue: 37889 Ambient: 37889 Red: 37889 Green: 37889 Blue: 37889
3) mobile phone flashlight, from about 15 cm:
Ambient: 11857 Red: 3995 Green: 4490 Blue: 4964 Ambient: 7872 Red: 2754 Green: 2972 Blue: 3092 Ambient: 8215 Red: 3056 Green: 3136 Blue: 3126 Ambient: 8281 Red: 3078 Green: 3183 Blue: 3241 Ambient: 8424 Red: 3055 Green: 3108 Blue: 2935 Ambient: 8749 Red: 3067 Green: 3238 Blue: 2945
4) red plastic cover of my multimeter
Ambient: 117 Red: 66 Green: 33 Blue: 26 Ambient: 115 Red: 65 Green: 32 Blue: 26 Ambient: 118 Red: 67 Green: 31 Blue: 27 Ambient: 118 Red: 67 Green: 31 Blue: 27 Ambient: 117 Red: 66 Green: 31 Blue: 27
5) green grass in magazine
Ambient: 180 Red: 60 Green: 77 Blue: 45 Ambient: 182 Red: 61 Green: 78 Blue: 46 Ambient: 172 Red: 57 Green: 74 Blue: 44 Ambient: 177 Red: 60 Green: 76 Blue: 45 Ambient: 173 Red: 58 Green: 75 Blue: 45
6) blue border in magazine
Ambient: 214 Red: 76 Green: 84 Blue: 73 Ambient: 210 Red: 74 Green: 83 Blue: 72 Ambient: 211 Red: 75 Green: 82 Blue: 72 Ambient: 214 Red: 77 Green: 84 Blue: 72
7) same with mobile flashlight lit
Ambient: 591 Red: 138 Green: 193 Blue: 258 Ambient: 587 Red: 136 Green: 191 Blue: 256 Ambient: 587 Red: 135 Green: 190 Blue: 256 Ambient: 587 Red: 137 Green: 192 Blue: 256 Ambient: 588 Red: 137 Green: 191 Blue: 256
This program waits and when the level of ambient light changes significantly, it produces output based on the received interrupt
------------------------------------- SparkFun APDS-9960 - Light Interrupts ------------------------------------- APDS-9960 initialization complete Light sensor is now running Low Threshold: 10 High Threshold: 1000 Interrupt! Ambient: 81 R: 32 G: 33 B: 22 Interrupt! Ambient: 1095 R: 448 G: 423 B: 312 Interrupt! Ambient: 1228 R: 517 G: 519 B: 379 Interrupt! Ambient: 1230 R: 516 G: 515 B: 375 Interrupt! Ambient: 1229 R: 515 G: 515 B: 373 Interrupt! Ambient: 1233 R: 517 G: 514 B: 373 Interrupt! Ambient: 1096 R: 459 G: 447 B: 307 Interrupt! Ambient: 1042 R: 388 G: 416 B: 303
The next example detects movements above the sensor in 4 horizontal and 2 vertical directions:
-------------------------------- SparkFun APDS-9960 - GestureTest -------------------------------- APDS-9960 initialization complete Gesture sensor is now running UP DOWN LEFT RIGHT NONE FAR FAR NEAR NEAR
Again, a version based on interrupts that reports an object in about 5 cm distance:
--------------------------------------- SparkFun APDS-9960 - ProximityInterrupt --------------------------------------- APDS-9960 initialization complete Proximity sensor is now running Proximity detected! Level: 51 Proximity detected! Level: 52 Proximity detected! Level: 53 Proximity detected! Level: 51 Proximity detected! Level: 52 Proximity detected! Level: 57 Proximity detected! Level: 57 Proximity detected! Level: 54 Proximity detected! Level: 52 Proximity detected! Level: 58
Finally, an example that permanently reports proximity - it starts rasing from values near 0 at around 15-20 cm,
and reaches maximum value of 255 at around 3-5 cm - depending on reflectivity of the object
------------------------------------ SparkFun APDS-9960 - ProximitySensor ------------------------------------ APDS-9960 initialization complete Proximity sensor is now running Proximity: 0 Proximity: 5 Proximity: 10 Proximity: 9 Proximity: 9 Proximity: 11 Proximity: 9 Proximity: 7 Proximity: 9 Proximity: 6 Proximity: 7 Proximity: 7 Proximity: 8 Proximity: 9 Proximity: 10 Proximity: 12 Proximity: 18 Proximity: 19 Proximity: 33 Proximity: 33 Proximity: 15 Proximity: 13 Proximity: 11 Proximity: 7 Proximity: 4 Proximity: 4 Proximity: 6 Proximity: 6 Proximity: 7 Proximity: 6 Proximity: 7 Proximity: 8 Proximity: 6 Proximity: 8 Proximity: 11 Proximity: 11 Proximity: 13 Proximity: 12 Proximity: 11 Proximity: 13 Proximity: 16 Proximity: 16 Proximity: 17 Proximity: 14 Proximity: 14 Proximity: 14 Proximity: 13 Proximity: 13 Proximity: 12 Proximity: 13 Proximity: 8 Proximity: 9 Proximity: 9 Proximity: 8 Proximity: 9 Proximity: 8 Proximity: 14 Proximity: 14 Proximity: 18 Proximity: 24 Proximity: 30 Proximity: 37 Proximity: 47 Proximity: 59 Proximity: 79 Proximity: 103 Proximity: 119 Proximity: 146 Proximity: 172 Proximity: 203 Proximity: 226 Proximity: 251 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 231 Proximity: 184 Proximity: 174 Proximity: 161 Proximity: 183 Proximity: 239 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 251 Proximity: 147 Proximity: 67 Proximity: 30 Proximity: 14 Proximity: 10 Proximity: 8 Proximity: 9 Proximity: 5 Proximity: 6 Proximity: 7 Proximity: 4 Proximity: 6 Proximity: 5 Proximity: 5 Proximity: 10 Proximity: 23 Proximity: 37 Proximity: 65 Proximity: 92 Proximity: 117 Proximity: 153 Proximity: 193 Proximity: 232 Proximity: 249 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 240 Proximity: 194 Proximity: 212 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 87 Proximity: 16 Proximity: 10 Proximity: 6 Proximity: 12 Proximity: 186 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 255 Proximity: 8 Proximity: 6 Proximity: 5 Proximity: 5 Proximity: 7
One more final perhaps important note: The sensor works at 3.3V logic, so to use with Arduino, I have used the level shifter. First I tried with this red one, which is a good one, bidirectional, suitable for I2C communication. But when getting no results, I tried this blue one, still having no results, however after making required change in the library, only the red one worked. The blue one has Tx and Rx pins and each pin seems to work only in the specified direction. In order to make the sensor work, I had to use the red bi-directional level shifter.
Thanks for visiting the page. :-)
Palo (pavel.petrovic@gmail.com), January 2022.