Skip to content

Python Examples

Example 1 - Basic Readings

The first example initializes the VEML7700 with default settings and prints out light data in lux every second.

Example 2 - Settings

Example 2 shows how to adjust the gain and integration time for the VEML7700, prints out the values for the two settings and then prints out light data in lux in intervals set by the integration time. The example sets the gain to 1 and integration time to 200ms. Adjust the values for these in the following lines:

gain = 1

integ_time = 200

Allowed values for gain are 1, 2, 4 and 8. Allowed values for integration time are 25ms, 50ms, 100ms, 200ms, 400ms and 800ms.

Example 3 - Threshold Interrupts

Example 3 shows how to set thresholds for both high and low lux values and triggers an interrupt when measurements exceed either of the values set. The HIGH and LOW thresholds are set to 20 and 100, respectively, and can be adjusted in these lines:

low_thresh = 20
high_thresh = 200

The thresholds can be set anywhere between 0 and 120k lux. For reference, ambient lighting in a room typically is ~100lux and direct sunlight can be over 100k lux.

Example 4 - Power Saving

The fourth example sets the VEML7700 into power save mode with settings to drop power consumption to a minimum (roughly 2µA) and then prints out lux data roughly every 4 seconds (as set by the longest refresh time period):

gain = 2
integ_time = 100
power_mode = 4