APDS 9960 problems with gesture sensor example sketch

Discussion in 'Digital Circuit Design' started by Big Sammy, Apr 4, 2017.

  1. Big Sammy

    Thread Starter Active Member

    Jan 28, 2012
    40
    1
    Hi...I had posted this, but with an incorrect title....I'm trying to use a APDS 9960 sensor. I have it connected to both an Arduino Uno and Nano. I have two different sensors...a sparkfun one and another one...not sure of brand name, but it is purple.
    When connecting the purple one, everything works...all the example sketches work flawlessly, except the gesture sensor example. The sensor initializes correctly, begins to work, but will not recognize any gestures.
    The Sparkfun sensor reports an initialization error.
    Anybody have similar experience with these sensors? Any suggestions to getting the gesture sensor example sketch to work?
    Thanks!
     
  2. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    3,519
    1,282
    Hi! I have a couple of questions.

    The APDS 9960 is a 3.3V module. The Uno and Nano are 5V boards. Are you powering the sensor with the correct voltage? Are you level shifting the IO?

    What libraries are you using for the two sensors and where did you get them? For example, the Sparkfun sensor has A download link for their library. Please note that the Sparkfun sensor requires the Sparkfun library.

    Secondly, are you using sample sketches for both sensors? Can you post the two example sketches for me to examine?
     
  3. Big Sammy

    Thread Starter Active Member

    Jan 28, 2012
    40
    1
    Hi...on both boards the sensor is connected to the 3.3v pin. I'm using the Sparkfun library from Github. I'm using the same sketches for both sensors....
    This is the gesture test example sketch from the Sparkfun library that I'm using for both sensors....
    Code (Text):
    1. /****************************************************************
    2. GestureTest.ino
    3. APDS-9960 RGB and Gesture Sensor
    4. Shawn Hymel @ SparkFun Electronics
    5. May 30, 2014
    6. [URL]https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor[/URL]
    7.  
    8. Tests the gesture sensing abilities of the APDS-9960. Configures
    9. APDS-9960 over I2C and waits for gesture events. Calculates the
    10. direction of the swipe (up, down, left, right) and displays it
    11. on a serial console.
    12.  
    13. To perform a NEAR gesture, hold your hand
    14. far above the sensor and move it close to the sensor (within 2
    15. inches). Hold your hand there for at least 1 second and move it
    16. away.
    17.  
    18. To perform a FAR gesture, hold your hand within 2 inches of the
    19. sensor for at least 1 second and then move it above (out of
    20. range) of the sensor.
    21.  
    22. Hardware Connections:
    23.  
    24. IMPORTANT: The APDS-9960 can only accept 3.3V!
    25.  
    26. Arduino Pin  APDS-9960 Board  Function
    27.  
    28. 3.3V  VCC  Power
    29. GND  GND  Ground
    30. A4  SDA  I2C Data
    31. A5  SCL  I2C Clock
    32. 2  INT  Interrupt
    33.  
    34. Resources:
    35. Include Wire.h and SparkFun_APDS-9960.h
    36.  
    37. Development environment specifics:
    38. Written in Arduino 1.0.5
    39. Tested with SparkFun Arduino Pro Mini 3.3V
    40.  
    41. This code is beerware; if you see me (or any other SparkFun
    42. employee) at the local, and you've found our code helpful, please
    43. buy us a round!
    44.  
    45. Distributed as-is; no warranty is given.
    46. ****************************************************************/
    47.  
    48. #include <Wire.h>
    49. #include <SparkFun_APDS9960.h>
    50.  
    51. // Pins
    52. #define APDS9960_INT  2 // Needs to be an interrupt pin
    53.  
    54. // Constants
    55.  
    56. // Global Variables
    57. SparkFun_APDS9960 apds = SparkFun_APDS9960();
    58. int isr_flag = 0;
    59.  
    60. void setup() {
    61.  
    62.   // Set interrupt pin as input
    63.   pinMode(APDS9960_INT, INPUT);
    64.  
    65.   // Initialize Serial port
    66.   Serial.begin(9600);
    67.   Serial.println();
    68.   Serial.println(F("--------------------------------"));
    69.   Serial.println(F("SparkFun APDS-9960 - GestureTest"));
    70.   Serial.println(F("--------------------------------"));
    71.  
    72.   // Initialize interrupt service routine
    73.   attachInterrupt(0, interruptRoutine, FALLING);
    74.  
    75.   // Initialize APDS-9960 (configure I2C and initial values)
    76.   if ( apds.init() ) {
    77.   Serial.println(F("APDS-9960 initialization complete"));
    78.   } else {
    79.   Serial.println(F("Something went wrong during APDS-9960 init!"));
    80.   }
    81.  
    82.   // Start running the APDS-9960 gesture sensor engine
    83.   if ( apds.enableGestureSensor(true) ) {
    84.   Serial.println(F("Gesture sensor is now running"));
    85.   } else {
    86.   Serial.println(F("Something went wrong during gesture sensor init!"));
    87.   }
    88. }
    89.  
    90. void loop() {
    91.   if( isr_flag == 1 ) {
    92.   detachInterrupt(0);
    93.   handleGesture();
    94.   isr_flag = 0;
    95.   attachInterrupt(0, interruptRoutine, FALLING);
    96.   }
    97. }
    98.  
    99. void interruptRoutine() {
    100.   isr_flag = 1;
    101. }
    102.  
    103. void handleGesture() {
    104.   if ( apds.isGestureAvailable() ) {
    105.   switch ( apds.readGesture() ) {
    106.   case DIR_UP:
    107.   Serial.println("UP");
    108.   break;
    109.   case DIR_DOWN:
    110.   Serial.println("DOWN");
    111.   break;
    112.   case DIR_LEFT:
    113.   Serial.println("LEFT");
    114.   break;
    115.   case DIR_RIGHT:
    116.   Serial.println("RIGHT");
    117.   break;
    118.   case DIR_NEAR:
    119.   Serial.println("NEAR");
    120.   break;
    121.   case DIR_FAR:
    122.   Serial.println("FAR");
    123.   break;
    124.   default:
    125.   Serial.println("NONE");
    126.   }
    127.   }
    128. }
    Moderators note : used code tags
     
  4. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    3,519
    1,282
    But what about your I2C pins? Since you are using the Uno and Nano, they will produce a 5V signal. The sensor is a 3.3V module, so I would expect that 5V I2C signals may not work.

    Even the example sketch on the Sparkfun site says
    Note that the example sketch uses a 3.3V Arduino Pro Mini, which is a 3.3V board.
     
Loading...