two Adafruit APDS9960 Proximity Sensors in tandem

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
LEDLIT1
 
Posts: 115
Joined: Mon Oct 17, 2016 11:14 am

two Adafruit APDS9960 Proximity Sensors in tandem

Post by LEDLIT1 »

Dear Adafruit support,

I purchased 2 Adafruit APDS9960 today and they worked instantly with your sketches on my Arduino Nano. Thank you for that. I used the Adafruit APDS-9960 to detect a basketball through the hoop. That works easily.

Next I want to confirm the direction the basketball traveled through the hoop as to avoid the false trigger scenario of the basketball entering from below the hoop. The gesture sensor responds much too slow with the Arduino (as Lady Ada pointed out in the youtube demo) so using that in the my application isn't feasible. So, I would like to use two APDS-9960's in tandem. One at the hoop level, and the other 10 inches below the hoop. This way, they both have to be triggered to confirm a basket was made (using AND logic) but, which sensor saw the basketball first would determine the direction it traveled. Getting a time stamp from each of them I think I will be able o figure out, but I only have one SCL and one SDA pin on my Arduino Nano.

The question I have is This:
How do I use two Adafruit APDS-9960's in tandem if there is only one SCL pin and one SDA pin on my Arduino Nano?

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by adafruit_support_bill »

The APDS-9960 has an "INT" pin that can be configured to generate an active LOW interrupt on proximity detection. You can connect this to one of the external or pin-change interrupt pins on your Nano. https://learn.adafruit.com/adafruit-apd ... ut/pinouts

User avatar
LEDLIT1
 
Posts: 115
Joined: Mon Oct 17, 2016 11:14 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by LEDLIT1 »

Thank you for your answer, but I sill don't understand how to use two Adafruit APDS9960 in tandom with there being only one SCL and one SDA pin on my Arduino Nano.

I started using a IR receiver TSOP38238 sensor and a IR LED transmitting a 38k pulse as a beam break scenario. Then I changed to a reflection scenario but I could get it to detect the basketball beyond 5 or 6 inches away. I needed to detect up to 12 inches away. I tried the 9960 and it just barely made it to 12 inches detection, but it still is not as reliable at the longer distance. Then there also was the direction the ball traveled.

Now I am trying the Adafruit Stretch sensor attached to the basketball net itself. I can sense the basketball passing through the net, but only 70% of the time. I am guessing that's because the margin of the voltage change I am monitoring is less than half a volt. Also, temperature will be a factor. When it's outside I think the heat and cold will cause the threshold to drift.

I am not sure what to do. I need to figure out a precise way of detecting a basket has been made.

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by adafruit_support_bill »

but I sill don't understand how to use two Adafruit APDS9960 in tandom with there being only one SCL and one SDA pin on my Arduino Nano.
You can use an i2c multiplexer to talk to multiple devices with the same address: https://learn.adafruit.com/adafruit-tca ... r-breakout

User avatar
LEDLIT1
 
Posts: 115
Joined: Mon Oct 17, 2016 11:14 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by LEDLIT1 »

Thank you very much.

User avatar
LEDLIT1
 
Posts: 115
Joined: Mon Oct 17, 2016 11:14 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by LEDLIT1 »

Dear Adafruit,

I am running tests with the Adafruit APDS9960 Proximity Sensor code utilizing the interrupt provided by Adadfruit. It seems like the readings vary after powering on and off.
Does the code run a calibration with every power up in the Adafruit_APDS9960.cpp or Adafruit_APDS9960.h?
Also, Is there a way to increase the gain so I can see 1 or 2 more centemeters?

Thank you

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by adafruit_support_bill »

There is no power-up calibration. You can adjust the proximity interrupt threshold between 0 and 255. The example code defaults to a threshold value of 175: https://github.com/adafruit/Adafruit_AP ... sensor.ino

User avatar
LEDLIT1
 
Posts: 115
Joined: Mon Oct 17, 2016 11:14 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by LEDLIT1 »

Thanks for the fast reply. I set it to trigger the interrupt at 1 to get the most coverage of the basketball hoop. I had figured that out before. Thank you.

User avatar
LEDLIT1
 
Posts: 115
Joined: Mon Oct 17, 2016 11:14 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by LEDLIT1 »

Hi Again,

I switched from the Nano to my new Adafruit HUZZAH32 – ESP32 . Which pins are the interrupt pins on the Adafruit HUZZAH32 – ESP32 ?

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by adafruit_support_bill »

The ESP32 can assign interrupt handlers to any pin. See this tutorial for details:
https://lastminuteengineers.com/handlin ... -tutorial/

User avatar
LEDLIT1
 
Posts: 115
Joined: Mon Oct 17, 2016 11:14 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by LEDLIT1 »

WOW! That's amazing! I have some reading to do now. Thank you for the quick reply.

User avatar
LEDLIT1
 
Posts: 115
Joined: Mon Oct 17, 2016 11:14 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by LEDLIT1 »

I am trying the VCNL4040 to get a little more range coverage. I got it to work like the APDS9960 proximity readings, but I can't figure out how to engage its interrupt pin. So my questions are:

What line of code tells the VCNL4040 to make its interrupt pin go LOW?
And inversely, What line of code tells the VCNL to make its interrupt pin reset back to HIGH?

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by adafruit_support_bill »

Not sure what library you are using. But proximity interrupts are configured in the PSCONF registers.
(Page 10 of the data sheet: https://www.vishay.com/docs/84274/vcnl4040.pdf )

Proximity threshold levels are configured in the PS_THDL and PS_THDH registers (page 11)

Reading the INT_Flag register will tell you what type of interrupt has been triggered. (Table 13, page 11)
It will also reset the interrupt. (see description on page 8)

User avatar
LEDLIT1
 
Posts: 115
Joined: Mon Oct 17, 2016 11:14 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by LEDLIT1 »

The library I tried using is from Sparkfun VCNL Example2_IsSomethingThere.ino . It does exactly what I need it to do, except for one thing. I doesn't trigger the interrupt. That's all I need to figure out, but I am at a loss. I wish it worked like the Adafruit APDS9960 proximity_sensor.ino example code does, but it doesn't. i have been trying to cross pollinate the two or reverse engineer, but there are too many layers for me understand.

I figured out the interrupt with the Example: Simple Interrupt code from the link you sent me. thank you for that. Now I have the VCNL4040 wired to my Adafruit HUZZAH32 – ESP32.

Here is the code below. I know it's a lot to ask. I am just trying to add the interrupt function but can't figure it out.

Code: Select all

/*
  Proximity Sensing with the VCNL4040 IR based sensor
  By: Nathan Seidle
  SparkFun Electronics
  Date: April 17th, 2018
  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware License).

  This example takes an initial reading at power on. If the reading changes
  by a significant amount the sensor reports that something is present.

  Point the sensor up and start the sketch. Then bring your hand infront of the sensor.

  Hardware Connections:
  Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
  Plug the sensor onto the shield
  Serial.print it out at 9600 baud to serial monitor.
*/

#include <Wire.h>

//Click here to get the library: http://librarymanager/All#SparkFun_VCNL4040
#include "SparkFun_VCNL4040_Arduino_Library.h"
VCNL4040 proximitySensor;

long startingProxValue = 0;
long deltaNeeded = 0;
boolean nothingThere = false;

void setup()
{
  Serial.begin(9600);
  Serial.println("SparkFun VCNL4040 Example");

  Wire.begin(); //Join i2c bus

  if (proximitySensor.begin() == false)
  {
    Serial.println("Device not found. Please check wiring.");
    while (1); //Freeze!
  }

  //Set the current used to drive the IR LED - 50mA to 200mA is allowed.
  proximitySensor.setLEDCurrent(200); //For this example, let's do max.

  //The sensor will average readings together by default 8 times.
  //Reduce this to one so we can take readings as fast as possible
  proximitySensor.setProxIntegrationTime(8); //1 to 8 is valid

  //Take 8 readings and average them
  for(byte x = 0 ; x < 8 ; x++)
  {
    startingProxValue += proximitySensor.getProximity();
  }
  startingProxValue /= 8;

  deltaNeeded = (float)startingProxValue * 0.05; //Look for 5% change
  if(deltaNeeded < 5) deltaNeeded = 5; //Set a minimum
}

void loop()
{
  unsigned int proxValue = proximitySensor.getProximity(); 

  Serial.print("Prox: ");
  Serial.print(proxValue);
  Serial.print(" ");

  //Let's only trigger if we detect a 5% change from the starting value
  //Otherwise, values at the edge of the read range can cause false triggers
  if(proxValue > (startingProxValue + deltaNeeded))
  {
    Serial.print("Something is there!");
    nothingThere = false;
  }
  else
  {
    if(nothingThere == false) Serial.print("I don't see anything");
    nothingThere = true;
  }

  Serial.println();
  delay(10);
}
Last edited by adafruit_support_bill on Thu Apr 11, 2019 12:58 pm, edited 1 time in total.
Reason: Please use [code] tags when submitting code to the forums

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: two Adafruit APDS9960 Proximity Sensors in tandem

Post by adafruit_support_bill »

We don't carry a VCNL4040, so I don't have any working code to pass along.

It looks like the Sparkfun lib has a function to enable the proximity interrupts and set the thresholds here: https://github.com/sparkfun/SparkFun_VC ... _Library.h

Sparkfun tech support should be able to assist you with their usage.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”