CircuitPython module for the VCNL4010 proximity and light sensor. See examples/ for an example of the usage.

  • Author(s): Tony DiCola

Implementation Notes


Software and Dependencies:

class adafruit_vcnl4010.VCNL4010(i2c, address=19)[source]

Vishay VCNL4010 proximity and ambient light sensor.

  • i2c (I2C) – The I2C bus the VCNL4010 is connected to

  • address (int) – (optional) The I2C address of the device. Defaults to 0x13

Quickstart: Importing and using the VCNL4010

Here is an example of using the VCNL4010 class. First you will need to import the libraries to use the sensor

import board
import adafruit_vcnl4010

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()   # uses board.SCL and board.SDA
sensor = adafruit_vcnl4010.VCNL4010(i2c)

Now you have access to the sensor.proximity and ambient_lux attributes

proximity = sensor.proximity
ambient_lux = sensor.ambient_lux
property ambient

The detected ambient light in front of the sensor. This is a unit-less unsigned 16-bit value (0-65535) with higher values for more detected light. See the ambient_lux property for a value in lux.

property ambient_lux

The detected ambient light in front of the sensor as a value in lux.

property frequency

Proximity modulator timimg. This is the frequency of the IR square wave used for the proximity measurement.

Must be a value of:

  • FREQUENCY_3M125: 3.125 Mhz

  • FREQUENCY_1M5625: 1.5625 Mhz

  • FREQUENCY_781K25: 781.25 Khz

  • FREQUENCY_390K625: 390.625 Khz (default)

The datasheet recommended leaving this at the default.

property led_current

The current of the LED. The value is in units of 10mA and can only be set to 0 (0mA/off) to 20 (200mA). See the datasheet for how LED current impacts proximity measurements. The default is 200mA.

property led_current_mA

The current of the LED in milliamps. The value here is specified in milliamps from 0-200. Note that this value will be quantized down to a smaller less-accurate value as the chip only supports current changes in 10mA increments, i.e. a value of 123 mA will actually use 120 mA. See the datasheet for how the LED current impacts proximity measurements, and the led_current property to explicitly set values without quantization or unit conversion.

property proximity

The detected proximity of an object in front of the sensor. This is a unit-less unsigned 16-bit value (0-65535) INVERSELY proportional to the distance of an object in front of the sensor (up to a max of ~200mm). For example a value of 10 is an object farther away than a value of 1000. Note there is no conversion from this value to absolute distance possible, you can only make relative comparisons.

property samplerate

The frequency of proximity measurements per second. Must be a value of:

  • SAMPLERATE_1_95: 1.95 measurements/sec (default)

  • SAMPLERATE_3_90625: 3.90625 measurements/sec

  • SAMPLERATE_7_8125: 7.8125 measurements/sec

  • SAMPLERATE_16_625: 16.625 measurements/sec

  • SAMPLERATE_31_25: 31.25 measurements/sec

  • SAMPLERATE_62_5: 62.5 measurements/sec

  • SAMPLERATE_125: 125 measurements/sec

  • SAMPLERATE_250: 250 measurements/sec

See the datasheet for how frequency changes the power consumption and proximity detection accuracy.