SparkFun VCNL4040 Proximity Sensor not working with Arduino GIGA R1 Wifi

There are a number of settings in begin(), once it has passed Isconnected() and Get_id().

Indeed powerOnProximity() is one of them. There is NO check on any of the set-calls and I just wonder why Isconnected() and / or Get_id() fails.

Once that is known.. I expect the other stuff will be working


The code & the serial output…
Below the code is a snippet of the VCNL4040 data table showing the ID and below that is the portion of the CPP file (SparkFun_VCNL4040_Arduino_Library.cpp) that checks the ID in the .begin check…
As can be seen in the serial monitor output:
ID is correct at 390 (=01=186 maybe we can get another format in there to mess with non-sparky’s?)
isConnected is true
begin still fails even though both the checks are valid.

Note: there is a .begin and .powerOnProximity prior to this block to get the sensor working even though .begin returns false/0.

Just for test, use the standard example .begin() but insert 4 x Serial.println() in .begin in the CPP file.

boolean VCNL4040::begin(TwoWire &wirePort) {
  _i2cPort = &wirePort; //Grab which port the user wants us to use

  //We expect caller to begin their I2C port, with the speed of their choice external to the library
  //But if they forget, we start the hardware here.
  _i2cPort->begin();
Serial.println("After wire begin");

  //Check connection
  if (isConnected() == false) return (false); //I2C comm failure
Serial.println("After is connected"); 
  
  if (getID() != 0x0186) return (false); //Check default ID value
Serial.println("After getID");

  //Configure the various parts of the sensor
  setLEDCurrent(200); //Max IR LED current

  setIRDutyCycle(40); //Set to highest duty cycle

  setProxIntegrationTime(8); //Set to max integration

  setProxResolution(16); //Set to 16-bit output
  
  enableSmartPersistance(); //Turn on smart presistance

  powerOnProximity(); //Turn on prox sensing

  //setAmbientIntegrationTime(VCNL4040_ALS_IT_80MS); //Keep it short
  //powerOnAmbient(); //Turn on ambient sensing
Serial.println("Before returning true");

  return (true);
}

If isConnected() fails try to set a delay(200) after _i2cPort->begin();

if getID() fails just comment out the line : if (isConnected() == false) return (false);

this test is redundant anyway as getID() will fail if the sensor is not connected anyway..

First, I would like to say, thanks for giving this beginner the confidence to edit the .cpp file and helping out on this frustrating issue. Honestly surprised others haven’t had this come up or maybe they solved it themselves…?

Will have to play some more, because I am pretty sure I had a 1 second delay in the same spot before, but maybe first query is always returning ‘0’ on the GIGA? Had other issues, but never this on the UNO. Will try different times vs. number of queries later…

After trying the Serial.print’s suggested above, finding that indeed it was .getID that was giving a zero in the .CPP even though it showed ‘390’ in IDE Serial, this added to .CPP proved fruitful:

Thanks Paul!!

I was too excited to wait to find the result!

First read on the GIGA is always returning ‘0’…!

It does not appear to be a timing issue…?

Here’s two runs without and with delays:

For anyone trying to get the Sparkfun VCNL4040 Proximity sensor working on an Arduino GIGA, code and hardware is performing great with the addition of an empty if statement in the SparkFun_VCNL4040_Arduino_Library.CPP
This allows the setup to read the correct ID as it seems the GIGA always gets a zero on the first read. Burn that first read and everything works! Example code for .CPP:

//request a getID to grab the first read which seems to be zero instead of actual ID
if (getID()!=0){
}

Add it here:

Congratulations with finding a solution and get it working. It has taken longer than you expected to get it going, but you also learned more than you expected !

I wonder whether just commenting out isConnected() call in .begin(), would also have solved the issue. The isConnected() is only sending the address (NO data) and checks that an ACK has been received from the sensor. There are different I2C/Wire modules in the different processors and maybe the module in the GIGA is out-of-sync as it expected data. The first getID() call brings it back in sync, but you did not get any data.

That said: your solution works and that is the most important.

As I am understanding the results of the test, isConnected passes every time and the first getID always returns a zero value…And those two calls back to back in IDE always return correct results (since the first call happens in the setup of the .CPP file)…

As for longer than expected, yes, absolutely. Also a little disappointed with Sparkfun’s response for their “plug and play” component stating that it was my setup and not owning that there may be an issue and at least trying to replicate it. Cost me many hours. Although, of course, fun to solve puzzles…

I am not a software or electrical engineer, this is a hobby item for me. IDE and C++ are new to me (degrees in EME & EMS and our software was Fortran 77 and EE was 101 - Electrical engineering for mechanical engineers…! )…In summary, fun to learn but also want stuff to work as advertised and getting to the working system is the ultimate goal, like most of us, I only have certain amount of time to play!

Thanks again for your help! TR