MicroPython VCNL4010 Library

vcnl4010

9

  • Author(s): Jose D. Montoya

class micropython_vcnl4010.vcnl4010.VCNL4010(i2c, address: int = 0x13)[source]

Driver for the VCNL4010 Sensor connected over I2C.

Parameters:
i2c : I2C

The I2C bus the VCNL4010 is connected to.

address : int

The I2C device address. Defaults to 0x13

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

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

from machine import Pin, I2C
from micropython_vcnl4010 import vcnl4010

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

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
vcnl4010 = vcnl4010.VCNL4010(i2c)

Now you have access to the attributes


property ambient : int

Ambient light in lux

property ambient_light_average : str

Sensor ambient_light_average

Mode

Value

vcnl4010.AL_AVERAGE1

0b000

vcnl4010.AL_AVERAGE2

0b001

vcnl4010.AL_AVERAGE4

0b010

vcnl4010.AL_AVERAGE8

0b011

vcnl4010.AL_AVERAGE16

0b100

vcnl4010.AL_AVERAGE32

0b101

vcnl4010.AL_AVERAGE64

0b110

vcnl4010.AL_AVERAGE128

0b111

property ambient_light_rate : str

Sensor ambient_light_rate

Mode

Value

vcnl4010.AMBIENT_LIGHT_RATE1

0b000

vcnl4010.AMBIENT_LIGHT_RATE2

0b001

vcnl4010.AMBIENT_LIGHT_RATE3

0b010

vcnl4010.AMBIENT_LIGHT_RATE4

0b011

vcnl4010.AMBIENT_LIGHT_RATE5

0b100

vcnl4010.AMBIENT_LIGHT_RATE6

0b101

vcnl4010.AMBIENT_LIGHT_RATE8

0b110

vcnl4010.AMBIENT_LIGHT_RATE10

0b111

property irl_led_current : int

IR LED current = Value (dec.) x 10 mA. Valid Range = 0 to 20d. e.g. 0 = 0 mA , 1 = 10 mA, …., 20 = 200 mA (2 = 20 mA = DEFAULT) LED Current is limited to 200 mA for values higher as 20d.

property proximity : int

Proximity of an object in front of the sensor

property proximity_rate : str

Sensor proximity_rate

Mode

Value

vcnl4010.SAMPLERATE_1_95

0b000

vcnl4010.SAMPLERATE_3_90625

0b001

vcnl4010.SAMPLERATE_7_8125

0b010

vcnl4010.SAMPLERATE_16_625

0b011

vcnl4010.SAMPLERATE_31_25

0b100

vcnl4010.SAMPLERATE_62_5

0b101

vcnl4010.SAMPLERATE_125

0b110

vcnl4010.SAMPLERATE_250

0b111