Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 by Bryan Siepert, written for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4import time
5import board
6import adafruit_ltr390
7
8i2c = board.I2C()
9ltr = adafruit_ltr390.LTR390(i2c)
10
11while True:
12 print("UV:", ltr.uvs, "\t\tAmbient Light:", ltr.light)
13 print("UVI:", ltr.uvi, "\t\tLux:", ltr.lux)
14 time.sleep(1.0)
Configuration example¶
Adjust the configuration options for the sensor
1# SPDX-FileCopyrightText: 2020 by Bryan Siepert, written for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4# pylint:disable=unused-import,no-member
5
6import time
7import board
8from adafruit_ltr390 import LTR390, MeasurementDelay, Resolution, Gain
9
10i2c = board.I2C()
11ltr = LTR390(i2c)
12
13# ltr.resolution = Resolution.RESOLUTION_16BIT
14print("Measurement resolution is", Resolution.string[ltr.resolution])
15
16# ltr.gain = Gain.GAIN_1X
17print("Measurement gain is", Gain.string[ltr.gain])
18
19# ltr.measurement_delay = MeasurementDelay.DELAY_100MS
20print("Measurement delay is", MeasurementDelay.string[ltr.measurement_delay])
21print("")
22while True:
23 print("UV:", ltr.uvs, "\t\tAmbient Light:", ltr.light)
24
25 # for shorter measurement delays you may need to make this sleep shorter to see a change
26 time.sleep(1.0)
Measurement threshold example¶
Be alerted when the measured value passes a high or low threshold
1# SPDX-FileCopyrightText: 2020 by Bryan Siepert, written for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4# pylint:disable=unused-import
5import time
6import board
7from adafruit_ltr390 import LTR390, UV, ALS
8
9THRESHOLD_VALUE = 100
10
11i2c = board.I2C()
12ltr = LTR390(i2c)
13
14ltr.high_threshold = THRESHOLD_VALUE
15ltr.enable_alerts(True, UV, 1)
16
17while True:
18
19 if ltr.threshold_passed:
20 print("UV:", ltr.uvs)
21 print("threshold", THRESHOLD_VALUE, "passed!")
22 print("")
23 else:
24 print("threshold not passed yet")
25
26 time.sleep(1)