Sparkfun APDS-9960 gesturetest on Avery: compile error

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
...

please post the line of the code failing.
It needs 2 casts for the parameters.

1 Like

...
#include <Wire.h>
#include <SparkFun_APDS9960.h>

// Pins
#define APDS9960_INT 2 // Needs to be an interrupt pin

// Constants

// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;

void setup() {

// Set interrupt pin as input
pinMode(APDS9960_INT, INPUT);

// Initialize Serial port
Serial.begin(9600);
Serial.println();
Serial.println(F("--------------------------------"));
Serial.println(F("SparkFun APDS-9960 - GestureTest"));
Serial.println(F("--------------------------------"));

// Initialize interrupt service routine
attachInterrupt(0, interruptRoutine, FALLING);

// Initialize APDS-9960 (configure I2C and initial values)
if ( apds.init() ) {
Serial.println(F("APDS-9960 initialization complete"));
} else {
Serial.println(F("Something went wrong during APDS-9960 init!"));
}

// Start running the APDS-9960 gesture sensor engine
if ( apds.enableGestureSensor(true) ) {
Serial.println(F("Gesture sensor is now running"));
} else {
Serial.println(F("Something went wrong during gesture sensor init!"));
}
}

void loop() {
if( isr_flag == 1 ) {
detachInterrupt(0);
handleGesture();
isr_flag = 0;
attachInterrupt(0, interruptRoutine, FALLING);
}
}

void interruptRoutine() {
isr_flag = 1;
}

void handleGesture() {
if ( apds.isGestureAvailable() ) {
switch ( apds.readGesture() ) {
case DIR_UP:
Serial.println("UP");
break;
case DIR_DOWN:
Serial.println("DOWN");
break;
case DIR_LEFT:
Serial.println("LEFT");
break;
case DIR_RIGHT:
Serial.println("RIGHT");
break;
case DIR_NEAR:
Serial.println("NEAR");
break;
case DIR_FAR:
Serial.println("FAR");
break;
default:
Serial.println("NONE");
}
}
}

...

According the errors it looks like the library is incompatible with a Nano Every.

In general, the Nano every is a rather non-standard board, many libraries for standard arduino ecosystem do not work on it

Nice, why do they sell it ? It is an original adafruit thingy, one would expect it is supported.
I have a nano ESP32, would this be more compatible ? Or should I order something else ?

It is supported. Since a Nano every based on different MCU than a classic one - the boards work with different libraries, it is an absolutely normal.

I can't say for this library, but in general the Nano esp32 has a microcontroller that is not compatible in commands with either the classic Nano or the Every.

thnx, so what board should I use ? I thought Arduino's where easy to use.

Why are you using a Sparkfun library for an Adafruit product?

If you using an arduino already, why to change the board?

In general, it is a good idea to make a google search like "APDS9960 + arduino nano every" to look if there are any feedback from someone who used the same setup.

I'm using a library of a 3th party that was made for Arduino. The other examples included in the library work. I can use the Arduino library for 9960 chip, but that doesn't support al gestures.

It is worth understanding that Arduino is not a kettle that you plug into a socket and it works.
This is a constructor that is designed for you to be able to create your own circuits and write code for the devices that you design.
If you do not know how to do this, it is better to buy a ready-made device

Neither Adafruit nor Sparkfun are "Arduino".

It is wise to use Adafruit libraries with Adafruit products, and Sparkfun libraries with Sparkfun products, as both companies support their own products, and host customer support forums.

It is also very wise to check which processors are compatible with a given library.

@domike

The problem is that one parameter is of type uint8_t and the other int

In the file SparkFun_APDS9960.cpp you need to look for the above line and change it to

Wire.requestFrom((int) APDS9960_I2C_ADDR, (int) len);

The (int) forces the compiler to use the specified datatype int for both parameters

1 Like

[
Reported problem at SParkfun