VEML7700 Lux Sensor

The Vishay VEML7700 light sensor [1] measures light in lux, with a 16-bit dynamic range for ambient light detection from 0 lux to about 120 klux, with resolution down to 0.0036 lx/ct.

It operates from 2.5 V to 3.6 V so if you want to use it on a 5 V board you'll need a regulator and logic-level conversion. It's available on a breakout from Adafruit [2]:

VEML7700.jpg

The I2C address is #x10 or 16.

Setting the gain

By default the sensor is shut down, so you need to write to write to the configuration register at address 0 to enable the sensor, and specify the gain, by calling set:

(defun set (g)
  (with-i2c (str #x10)
    (write-byte 0 str)
    (write-byte 0 str)
    (write-byte (ash g 3) str)))

The following table gives the values of the parameter g for the different available gain settings:

Parameter g Gain
0 1
1 2
2 1/8
3 1/4

The values read by the following routines should be scaled to take account of the currently selected gain.

Reading the white channel

The following routine lux returns the white channel value:

(defun lux ()
  (with-i2c (str #x10)
    (write-byte 5 str)
    (restart-i2c str 2)
    (logior (read-byte str) (ash (read-byte str) 8))))

Reading the Ambient Light Signal

The following routine als returns the ALS channel value:

(defun als ()
  (with-i2c (str #x10)
    (write-byte 4 str)
    (restart-i2c str 2)
    (logior (read-byte str) (ash (read-byte str) 8))))

  1. ^ VEML7700 Datasheet on Vishay.
  2. ^ Adafruit VEML7700 Lux Sensor on Adafruit.