Skip to content

begin()

Arnd edited this page Jun 29, 2018 · 2 revisions

begin([address],[I2C Speed])

This function initializes the VCNL4010 device, defaulting to address 0x13 unless another address is specified and sets the default values for several attributes. It will return a boolean "true" or "false" depending on whether it can locate a device on the I2C pins. The optional "I2C_Speed" parameter specifies the I2C bus speed in Herz, it defaults to I2C_STANDARD_MODE (100KHz) but values of I2C_FAST_MODE (400KHz), I2C_FAST_MODE_PLUS_MODE (1MHz) and I2C_HIGH_SPEED_MODE (3.4MHz) are also accepted.

The defaults are as follow:

Type Value Description
Proximity Hertz 2 This is a the sampling rate in Hz for the proximity sensor. It can range from 2 to 250 and the values here are interpolated to the following valid internal ones:
000 1.95 measurements/s (DEFAULT)
001 3.90625 measurements/s
010 7.8125 measurements/s
011 16.625 measurements/s
100 31.25 measurements/s
101 62.5 measurements/s
110 125 measurements/s
111 250 measurements/s
LED Strength 20 The output power of the infrared proximity sensor ranges from 0 (off) to 200 milliamps (max) in steps of 20, the default is 20.
Ambient light Sample Rate 2 The ambient light can be sampled from 2 to 10 times per second.
Ambient light Averaging Rate 2 The ambient light readings are averaged, from 1 to 32 times per actual output reading.
Proximity frequency 0 The proximity sensor frequency uses a square IR signal with the following 4 possible values:
000 390.625 kHz (DEFAULT)
001 781.25 kHz
010 1.5625 MHz
011 3.125 MHz
Interrupt Settings false The device can trigger a "low" signal on an interrupt pin, for a new ambient reading, a new proximity reading, or if a given low/high threshold has been exceeded on either the ambient light or proximity sensor. This is turned off by default.

Example:

VCNL4010 Sensor();  // Instantiate class    
...    
while (!Sensor.begin()) {                                        // Loop until sensor found
  Serial.println("Error, unable to find or identify VCNL4010."); // Show error message
  delay(5000);                                                   // Wait 5 seconds before retrying
} // of if-then we can't initialize or find the device