Simple test
Ensure your device works with this simple test.
examples/bh1750_simpletest.py
1# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
2
3# SPDX-License-Identifier: Unlicense
4import time
5import board
6import adafruit_bh1750
7
8i2c = board.I2C() # uses board.SCL and board.SDA
9# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
10sensor = adafruit_bh1750.BH1750(i2c)
11
12while True:
13 print("%.2f Lux" % sensor.lux)
14 time.sleep(1)
DisplayIO Simpletest
This is a simple test for boards with built-in display.
examples/bh1750_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
7import board
8from adafruit_display_text.bitmap_label import Label
9from terminalio import FONT
10from displayio import Group
11import adafruit_bh1750
12
13# Simple demo of using the built-in display.
14# create a main_group to hold anything we want to show on the display.
15main_group = Group()
16# Initialize I2C bus and sensor.
17i2c = board.I2C() # uses board.SCL and board.SDA
18sensor = adafruit_bh1750.BH1750(i2c)
19
20# Create Label(s) to show the readings. If you have a very small
21# display you may need to change to scale=1.
22display_output_label = Label(FONT, text="", scale=2)
23
24# place the label(s) in the middle of the screen with anchored positioning
25display_output_label.anchor_point = (0, 0)
26display_output_label.anchored_position = (
27 4,
28 board.DISPLAY.height // 2 - 60,
29)
30
31# add the label(s) to the main_group
32main_group.append(display_output_label)
33
34# set the main_group as the root_group of the built-in DISPLAY
35board.DISPLAY.root_group = main_group
36
37# begin main loop
38while True:
39 # update the text of the label(s) to show the sensor readings
40 display_output_label.text = f"Lux: {sensor.lux:.2f}"
41 # wait for a bit
42 time.sleep(0.5)