APDS-9960 example not compiling

Hi, I get compiling error when using the APDS9960 gesturetest example on a nano every, I have installed the right board and library. When using the Arduino-APDS9960 it’s ok and I get data from the chip.

This is the error I get:

c:\Users\mike\Documents\Arduino\libraries\SparkFun_APDS9960_RGB_and_Gesture_Sensor\src\SparkFun_APDS9960.cpp: In member function ‘int SparkFun_APDS9960::wireReadDataBlock(uint8_t, uint8_t*, unsigned int)’:
c:\Users\mike\Documents\Arduino\libraries\SparkFun_APDS9960_RGB_and_Gesture_Sensor\src\SparkFun_APDS9960.cpp:2204:44: error: call of overloaded ‘requestFrom(int, unsigned int&)’ is ambiguous
Wire.requestFrom(APDS9960_I2C_ADDR, len);
^
In file included from c:\Users\mike\Documents\Arduino\libraries\SparkFun_APDS9960_RGB_and_Gesture_Sensor\src\SparkFun_APDS9960.cpp:20:0:
C:\Users\mike\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\libraries\Wire\src/Wire.h:61:12: note: candidate: virtual size_t TwoWire::requestFrom(uint8_t, size_t)
size_t requestFrom(uint8_t, size_t);
^~~~~~~~~~~
C:\Users\mike\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\libraries\Wire\src/Wire.h:63:12: note: candidate: size_t TwoWire::requestFrom(int, int)
size_t requestFrom(int, int);
^~~~~~~~~~~

exit status 1

Compilation error: exit status 1

It looks like an issue related to the Wire.requestFrom() function being called with an ambiguous argument type in your code due to a mismatch between the types expected by the Wire.requestFrom() function and what’s actually passed to it.

In the error message we see two versions of requestFrom():

  1. size_t requestFrom(uint8_t, size_t);
  2. size_t requestFrom(int, int);

suggesting that the compiler is unable to figure out which one to use due to the types being passed.

Steps to resolve this:

  1. Modify the Argument Types in requestFrom()
    In your code, the line causing the issue is:
Wire.requestFrom(APDS9960_I2C_ADDR, len);

The issue seems to be with APDS9960_I2C_ADDR and len types. Typically, Wire.requestFrom() expects a uint8_t address and a size_t for the number of bytes to read.

  • Check the type of APDS9960_I2C_ADDR. It should be uint8_t. If it’s defined as int, you can try casting it to uint8_t:
Wire.requestFrom((uint8_t)APDS9960_I2C_ADDR, (size_t)len);
  1. Update the Wire Library Version
    Since you’re using the Arduino Nano Every, it uses the megaavr core, and there may be some changes or updates needed for compatibility with the Wire library.
  • Make sure that your Wire library is up-to-date. You can try updating it via the Arduino Library Manager or directly download the latest version of the Wire library if necessary.
  1. Check the Library Versions
    It seems you are using the SparkFun APDS9960 library (SparkFun_APDS9960_RGB_and_Gesture_Sensor) along with the Wire library. Ensure both libraries are compatible with your specific board and core (megaavr for Arduino Nano Every). In some cases, the library may need adjustments to support newer cores like megaavr.

If updating and casting the types doesn’t resolve the issue, try using a different version of the APDS9960 library, or search for a version specifically supporting megaavr.

Final Code Example

Modify the line in your sketch as follows:

Wire.requestFrom((uint8_t)APDS9960_I2C_ADDR, (size_t)len);

This will resolve the ambiguity between the overloaded requestFrom() functions, and hopefully let it run on the nano every as well - give it a try, and let me know how it goes!