APDS9960 Gesture Sensor difficulties

I have a Sparkfun APDS9960 Gesture Sensor that works great in a Feather ESP32-V2 project with a Charlieplex screen. I get great response for up, down, left, right. Trying to get the sensor to work with Argon, without the Charlieplex, just publishing the response as an event. So far, I’ve had very little luck moving this project into Particle after two days.

I’ve tried all the libraries available, with mixed results. I read through the past posts on this, but they were unhelpful, and are all closed, so I can’t continue those threads.

What is the proven library for this device? The way that the Particle libraries are organized is pretty sloppy. There are two labeled from Adafruit, with and without typos in the name. There appear to be two Sparkfun versions, but no real distinguishing documentation as to why.

9960

Code shown below does not work, yet I can’t see why it shouldn’t:


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

// Pins
#define APDS9960_INT D3 // Needs to be an interrupt pin JJD

// Constants

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

void setup() {

  // 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");
        Particle.publish("Gesture", "UP"); // Test gesture
        break;
      case DIR_DOWN:
        Serial.println("DOWN");
        Particle.publish("Gesture", "DOWN"); // Test gesture
        break;
      case DIR_LEFT:
        Serial.println("LEFT");
        Particle.publish("Gesture", "LEFT"); // Test gesture
        break;
      case DIR_RIGHT:
        Serial.println("RIGHT");
        Particle.publish("Gesture", "RIGHT"); // Test gesture
        break;
      case DIR_NEAR:
        Serial.println("NEAR");
        Particle.publish("Gesture", "NEAR"); // Test gesture
        break;
      case DIR_FAR:
        Serial.println("FAR");
        Particle.publish("Gesture", "FAR"); // Test gesture
        break;
      default:
        Serial.println("NONE");
    }
  }
}

When in doubt, go with the most used libraries. In this case either of the top two.

Thanks for pointing out the issue with the library organization. We are aware and are working on a library cleanup.

in setup() you miss this:

 pinMode(APDS9960_INT, INPUT);
 Wire.begin();

you can't run it without initiate communication

also this is wrong:

should be:

attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);

and finally in main loop():

 if( isr_flag == 1 ) {
    detachInterrupt(APDS9960_INT);
    handleGesture();
    isr_flag = 0;
    attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);
  }
2 Likes

Thank you so much. That worked. I am not sure how I missed these items - likely with all the editing I was doing, I got turned around.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.