adafruit/VCNL4000 — Issue #1: Arduino Freezing at High VCNL4000 LED Drive Currents
Author: tangiertigers
Created: 2012-02-09 18:30:35+00:00
State: open

*Issue:*

The Arduino freezes when attempting high LED drive currents (> ~60 mA) using this code with the VCNL4000.

*Solution:*

Add a short 170 us delay in the **read8()** procedure, as shown below. With this line added, I can run at up to 200 mA indefinitely.

uint8_t read8(uint8_t address)
{
uint8_t data;

Wire.beginTransmission(VCNL4000_ADDRESS);
#if ARDUINO >= 100
Wire.write(address);
#else
Wire.send(address);
#endif
Wire.endTransmission();
delayMicroseconds(170); // ADD THIS LINE

Wire.requestFrom(VCNL4000_ADDRESS, 1);
while(!Wire.available());

#if ARDUINO >= 100
return Wire.read();
#else
return Wire.receive();
#endif
}