APDS-9960 gesture sensor, SKU SEN-12787

Hello,

I recently ordered the APDS-9960 gesture sensor, SKU SEN-12787. It appears that it is not working properly.

I modified the GestureTest.ino sketch provided by sparkfun as an example to troubleshoot, and the apds.readGesture() command seems to cause a very long delay or is non responsive. Sometimes so long that it fails to read the gesture. In the video posted on the product page, the response from the sensor was close to immediate. Delay with my sensor ranges between 30 seconds and 2 minutes. I provided a sample of the serial output below.

Tried both the 3.3V Pro Micro I purchased on the same order, and also with an Arduino Uno with the same results. Tried different breadboards and soldered onto an adafruit perma proto board to rule out any connection issues. Tried removing serial comms as well.

The other sample sketches I tried (such as proximity detection) seem to work fine. Only gesture detection seemed to be an issue.

followed the hookup guide here:

https://learn.sparkfun.com/tutorials/ap … okup-guide

Any idea what could be causing this? Is the sensor defective?

I also bought a ZX Distance and Gesture Sensor for comparison, and that one works great!

sample serial output w/ comments. notice the time between readGesture and the response in capital letters:

13:17:27.539 ->
13:17:27.539 -> --------------------------------
13:17:27.573 -> SparkFun APDS-9960 - GestureTest
13:17:27.607 -> --------------------------------
13:17:27.641 -> APDS-9960 initialization complete
13:17:27.674 -> Gesture sensor is now running
13:17:27.707 -> isGestureAvailable (no gesture performed, but there's still caused a delay during bootup)
13:17:27.741 -> readGesture
13:17:38.462 -> NONE
13:17:38.496 -> readGesture... done
13:17:38.496 -> isGestureAvailable... done
13:17:38.530 -> isGestureAvailable
13:17:38.564 -> isGestureAvailable... done
13:17:46.823 -> isGestureAvailable (swipe left, no delay in interrupt or isGestureAvailable, but reading the gesture took 1 min 45 sec)
13:17:46.823 -> readGesture
13:19:31.260 -> NONE
13:19:31.260 -> readGesture... done
13:19:31.294 -> isGestureAvailable... done
13:19:31.328 -> isGestureAvailable
13:19:31.328 -> isGestureAvailable... done
13:19:50.490 -> isGestureAvailable (swipe left)
13:19:50.523 -> readGesture
13:20:20.286 -> NONE
13:20:20.319 -> readGesture... done
13:20:20.319 -> isGestureAvailable... done
13:20:20.353 -> isGestureAvailable
13:20:20.386 -> isGestureAvailable... done
13:20:29.354 -> isGestureAvailable (swipe left)
13:20:29.354 -> readGesture
13:21:06.629 -> LEFT
13:21:06.629 -> readGesture... done
13:21:06.663 -> isGestureAvailable... done
13:21:06.697 -> isGestureAvailable
13:21:06.697 -> isGestureAvailable... done

code used for the above, from the sample sketch:

/****************************************************************
GestureTest.ino
APDS-9960 RGB and Gesture Sensor
Shawn Hymel @ SparkFun Electronics
May 30, 2014
https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor

Tests the gesture sensing abilities of the APDS-9960. Configures
APDS-9960 over I2C and waits for gesture events. Calculates the
direction of the swipe (up, down, left, right) and displays it
on a serial console.

To perform a NEAR gesture, hold your hand
far above the sensor and move it close to the sensor (within 2
inches). Hold your hand there for at least 1 second and move it
away.

To perform a FAR gesture, hold your hand within 2 inches of the
sensor for at least 1 second and then move it above (out of
range) of the sensor.

Hardware Connections:

IMPORTANT: The APDS-9960 can only accept 3.3V!

Arduino Pin APDS-9960 Board Function

3.3V VCC Power
GND GND Ground
A4 SDA I2C Data
A5 SCL I2C Clock
2 INT Interrupt

Resources:
Include Wire.h and SparkFun_APDS-9960.h

Development environment specifics:
Written in Arduino 1.0.5
Tested with SparkFun Arduino Pro Mini 3.3V

This code is beerware; if you see me (or any other SparkFun
employee) at the local, and you've found our code helpful, please
buy us a round!

Distributed as-is; no warranty is given.
****************************************************************/

#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() {
Serial.println("isGestureAvailable");
if ( apds.isGestureAvailable() ) {
Serial.println("readGesture");
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");
}
Serial.println("readGesture... done");
}
Serial.println("isGestureAvailable... done");
}

Hi spaceriqui,

This is a weird one. I am not entirely sure what would cause that type of delay. Are you attaching the interrupt pin to D2? Can you take a few photos of your circuit and your APDS-9960 Breakout and attach them to your reply? That may help us identify a possible hardware issue.

Thanks for the reply Mark. Yes, I initially thought the interrupt may be the issue. I double checked that I had selected an interrupt pin on the Arduino pro mini and uno, and that it was being called correctly. But that doesn’t seem to be the issue.

I followed the hookup guide, so I am using pin 2 on the Uno.

When i swipe left I immediately see the serial output:

13:20:29.354 → isGestureAvailable (swiped left)

13:20:29.354 → readGesture

So the interrupt is working, but then it hangs at the readGesture() command. 37 seconds later, I get a response:

13:21:06.629 → LEFT

There’s no response from the Arduino during this 37 sec.

I’ll send some pics tomorrow. Thanks.

Ah, also tried removing the readGesture from the switch to serial print…

switch ( apds.readGesture() ) {

to…

Serial.println(apds.readGesture());

to check the output directly, and it printed digits but the delay was still there.

First batch of pictures, closeup of sensor.

3.jpg

2.jpg

1.jpg

second, closeup.

6.jpg

5.jpg

4.jpg

This is current state.

I stated above, I originally tried the Pro Micro (with slightly modified demo code), then an Arduino Uno (unmodified code per the hookup guide to troubleshoot), then went back to the pro micro on a perma proto board with soldered connections.

Note that I modified the demo code so it would work on the Pro Micro:

  1. changed interrupt pin to 0:

#define APDS9960_INT 0 // Needs to be an interrupt pin

  1. changed hard coded interrupts to use digitalPinToInterrupt(APDS9960_INT). Pin 0 is interrupt 2 (INT2), but that’s not needed when using this function. Example:

attachInterrupt(digitalPinToInterrupt(APDS9960_INT), interruptRoutine, FALLING);

instead of:

attachInterrupt(0, interruptRoutine, FALLING); // original code for pin 2 on Uno.

If you think going back to the Uno is necessary to troubleshoot, let me know. I don’t see a need as it behaved exactly the same with all the above configurations.

Thank you very much for taking those photos. They are very helpful. Everything in your setup with the Pro Micro looks great so it is not necessary to switch back to the Uno. I think at this point it is safe to conclude there is something wrong with your APDS-9960 Breakout. Assuming you purchased the board directly from SparkFun, please fill out the form on [this page and in the “Why do you want an RMA?” box, fill in a brief description of the issue and a link to this topic and we will follow up with further instructions.](Return Policy - SparkFun Electronics)

Hi Mark. I got the replacement sensor and it works exactly as expected. Thanks!