Simple test
Ensure your device works with this simple test.
examples/veml7700_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5
6import board
7
8import adafruit_veml7700
9
10i2c = board.I2C() # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
12veml7700 = adafruit_veml7700.VEML7700(i2c)
13
14while True:
15 print("Ambient light:", veml7700.light)
16 time.sleep(0.1)
DisplayIO Simpletest
This is a simple test for boards with built-in display.
examples/veml7700_displayio_simpletest.py
1# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2# SPDX-FileCopyrightText: 2024 Jose D. Montoya
3#
4# SPDX-License-Identifier: MIT
5
6import time
7
8import board
9from adafruit_display_text.bitmap_label import Label
10from displayio import Group
11from terminalio import FONT
12
13import adafruit_veml7700
14
15# Simple demo of the VEML7700 light sensor.
16# create a main_group to hold anything we want to show on the display.
17main_group = Group()
18# Initialize I2C bus and sensor.
19i2c = board.I2C() # uses board.SCL and board.SDA
20veml7700 = adafruit_veml7700.VEML7700(i2c)
21
22# Create two Labels to show the readings. If you have a very small
23# display you may need to change to scale=1.
24light_lux_output_label = Label(FONT, text="", scale=2)
25
26# place the label in the middle of the screen with anchored positioning
27light_lux_output_label.anchor_point = (0, 0)
28light_lux_output_label.anchored_position = (
29 4,
30 board.DISPLAY.height // 2,
31)
32
33# add the label to the main_group
34main_group.append(light_lux_output_label)
35
36# set the main_group as the root_group of the built-in DISPLAY
37board.DISPLAY.root_group = main_group
38
39# begin main loop
40while True:
41 # Update the label.text property to change the text on the display
42 light_lux_output_label.text = f"Ambient light:{veml7700.light}"
43 # wait for a bit
44 time.sleep(0.5)