APDS-9960 with teensy

Status
Not open for further replies.
I'm having issues with this break out as well, but on the Teensy LC

I have the Sparkfun proximity and color examples working, the the gesture example won't work (nothing coming over serial on Arduino IDE). The problem is almost certianly the interupt pin, but I'm not sure whats wrong or how to fix it

Sparkfun code:

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

*******************Modify the description**********************
3.3V-5V VCC Power
Void loop () to increase serial port statement causes the wave, will not stop
Library function will be waved in recognition of the changed
****************************************************************/

#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() {

// 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 ) {
handleGesture();
if(digitalRead(APDS9960_INT) == 0){
apds.init();
apds.enableGestureSensor(true);
}

isr_flag = 0;
}
}

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");
}
}
}
 
SUCCESS I'VE GOT IT WORKING NOW, ALL YOU NEED TO DO IS TO REPLACE ALL 0 IN THE PARAMETER OF attachInterrupt with digitalPinToInterrupt(PIN) like this one
attachInterrupt(0, interruptRoutine, FALLING); TO THIS ONE
attachInterrupt(digitalPinToInterrupt(APDS9960_INT), interruptRoutine, FALLING);
 
SUCCESS I'VE GOT IT WORKING NOW, ALL YOU NEED TO DO IS TO REPLACE ALL 0 IN THE PARAMETER OF attachInterrupt with digitalPinToInterrupt(PIN) like this one
attachInterrupt(0, interruptRoutine, FALLING); TO THIS ONE
attachInterrupt(digitalPinToInterrupt(APDS9960_INT), interruptRoutine, FALLING);
also dont forget the detachInterrupt ;)
detachInterrupt(0); to this one
detachInterrupt(digitalPinToInterrupt(APDS9960_INT));
 
Nice!

SUCCESS I'VE GOT IT WORKING NOW, ALL YOU NEED TO DO IS TO REPLACE ALL 0 IN THE PARAMETER OF attachInterrupt with digitalPinToInterrupt(PIN) like this one
attachInterrupt(0, interruptRoutine, FALLING); TO THIS ONE
attachInterrupt(digitalPinToInterrupt(APDS9960_INT), interruptRoutine, FALLING);
also dont forget the detachInterrupt ;)
detachInterrupt(0); to this one
detachInterrupt(digitalPinToInterrupt(APDS9960_INT));

Excellent!
 
Was really glad to find this post as I am having *exactly* the same issue with the Sparkfun APDS-9960 RGB and Gesture Sensor. And I've had the issue on three platforms so far (Sparkfun's ESP Thing, Pro Mini and Teensy 3.2). I tried the suggestion above in a sketch where I am successfully using the Proximity capability, but I can not get Gesture to work at all yet. Does anyone know if Proximity and Gesture functions can even be used together?

Also, I saw elsewhere that Teensy has a specific interrupt configuration, but I don't see any of that code noted in the suggestions above. So is it correct to say you really do not need the two libraries?

#include <avr/io.h>
#include <avr/interrupt.h>

I am starting to wonder if my sensor is bad on the Gesture side, but before I buy a new one I want to rule everything else out.
 
The Teensy is not an AVR but an ARM processor. Thus, special AVR hardware libraries are not needed. The Teensyduino Core files create compatibility with most libraries which are written for these old and slow AVR based Arduinos. Thus, everything will really work when you leave io.h and interrupt.h away because their better substitutes are in the Teensy core.
 
I am still having some issues trying to connect this sensor to a teensy 3.5 - previously tried to connect to an arduino uno using a level shifter board.
library from here.
Link for the sensor i am using

Wiring INT to pin 0, and replacing attach / detachInterrupt commands with the digitalPinToInterrupt conversion.
Wiring pin 3.3V (between pin 12 and 24) as VIN on sensor. I am not sure if this is ok. Also tried external 3.7V 1600mAh battery (with common ground).

I can run the ColorSensor example where colors Blue and sometimes Green display only ZEROS.

Proximity example only display ZEROS

GestureTest example doesn't print anything.

Already tested two sensors, same results. I am not sure how to proceed from here. Any suggestion would be appreciated. Thank you
 
Status
Not open for further replies.
Back
Top