API Reference

adafruit_veml7700

CircuitPython driver for VEML7700 high precision I2C ambient light sensor.

  • Author(s): Kattni Rembor

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_veml7700.VEML7700(i2c_bus: I2C, address: int = 16)

Driver for the VEML7700 ambient light sensor.

Parameters:
  • i2c_bus (I2C) – The I2C bus the device is connected to

  • address (int) – The I2C device address. Defaults to 0x10

property autolux: float

Light value in lux using auto checks and correction.

This property uses auto gain and auto integration time adjustments as well as a non-linear correction if necessary.

import time
import board
import adafruit_veml7700

i2c = board.I2C()  # uses board.SCL and board.SDA
veml7700 = adafruit_veml7700.VEML7700(i2c)

while True:
    print("Lux:", veml7700.autolux)
    veml7700.wait_autolux(0.1)
compute_lux(als: int, use_correction: bool) float

Compute lux, possibly using non-linear correction.

Parameters:
  • als (int) – The ambient light level.

  • use_correction (bool) – Flag for applying the non-linear correction.

Returns:

The calculated lux.

Return type:

float

gain_value() float

Gain value in integer form. Used for calculating resolution().

integration_time_value() int

Integration time value in integer form. Used for calculating resolution().

light = 4

Ambient light data.

This example prints the ambient light data. Cover the sensor to see the values change.

import time
import board
import adafruit_veml7700

i2c = board.I2C()  # uses board.SCL and board.SDA
veml7700 = adafruit_veml7700.VEML7700(i2c)

while True:
    print("Ambient light:", veml7700.light)
    time.sleep(0.1)
light_gain = 2

Ambient light gain setting. Gain settings are 2, 1, 1/4 and 1/8. Settings options are: ALS_GAIN_2, ALS_GAIN_1, ALS_GAIN_1_4, ALS_GAIN_1_8.

This example sets the ambient light gain to 2 and prints the ambient light sensor data.

import time
import board
import adafruit_veml7700

i2c = board.I2C()  # uses board.SCL and board.SDA
veml7700 = adafruit_veml7700.VEML7700(i2c)

veml7700.light_gain = veml7700.ALS_GAIN_2

while True:
    print("Ambient light:", veml7700.light)
    time.sleep(0.1)
light_integration_time = 4

Ambient light integration time setting. Longer time has higher sensitivity. Can be: ALS_25MS, ALS_50MS, ALS_100MS, ALS_200MS, ALS_400MS, ALS_800MS.

This example sets the ambient light integration time to 400ms and prints the ambient light sensor data.

import time
import board
import adafruit_veml7700

i2c = board.I2C()  # uses board.SCL and board.SDA
veml7700 = adafruit_veml7700.VEML7700(i2c)

veml7700.light_integration_time = veml7700.ALS_400MS

while True:
    print("Ambient light:", veml7700.light)
    time.sleep(0.1)
light_shutdown = 0

Ambient light sensor shutdown. When True, ambient light sensor is disabled.

property lux: float

Light value in lux.

This example prints the light data in lux. Cover the sensor to see the values change.

import time
import board
import adafruit_veml7700

i2c = board.I2C()  # uses board.SCL and board.SDA
veml7700 = adafruit_veml7700.VEML7700(i2c)

while True:
    print("Lux:", veml7700.lux)
    time.sleep(0.1)
static milliseconds() float

The time in milliseconds.

Returns:

The current time.

Return type:

float

resolution() float

Calculate the resolution`() necessary to calculate lux. Based on integration time and gain settings.

wait_autolux(wait_time: float) None

Wait minimum time between autolux measurements.

Ensure that the shortest wait time cannot be below the current integration time setting.

Parameters:

wait_time (float) – The requested time between measurements (seconds).

white = 5

White light data.

This example prints the white light data. Cover the sensor to see the values change.

import time
import board
import adafruit_veml7700

i2c = board.I2C()  # uses board.SCL and board.SDA
veml7700 = adafruit_veml7700.VEML7700(i2c)

while True:
    print("White light:", veml7700.white)
    time.sleep(0.1)