Simple test

Ensure your device works with this simple test.

examples/ltr390_simpletest.py
 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()  # uses board.SCL and board.SDA
 9# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
10ltr = adafruit_ltr390.LTR390(i2c)
11
12while True:
13    print("UV:", ltr.uvs, "\t\tAmbient Light:", ltr.light)
14    print("UVI:", ltr.uvi, "\t\tLux:", ltr.lux)
15    time.sleep(1.0)

Configuration example

Adjust the configuration options for the sensor

examples/ltr390_configuration_example.py
 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()  # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
12ltr = LTR390(i2c)
13
14# ltr.resolution = Resolution.RESOLUTION_16BIT
15print("Measurement resolution is", Resolution.string[ltr.resolution])
16
17# ltr.gain = Gain.GAIN_1X
18print("Measurement gain is", Gain.string[ltr.gain])
19
20# ltr.measurement_delay = MeasurementDelay.DELAY_100MS
21print("Measurement delay is", MeasurementDelay.string[ltr.measurement_delay])
22print("")
23while True:
24    print("UV:", ltr.uvs, "\t\tAmbient Light:", ltr.light)
25
26    # for shorter measurement delays you may need to make this sleep shorter to see a change
27    time.sleep(1.0)

Measurement threshold example

Be alerted when the measured value passes a high or low threshold

examples/ltr390_alert_test.py
 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()  # uses board.SCL and board.SDA
12# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
13ltr = LTR390(i2c)
14
15ltr.high_threshold = THRESHOLD_VALUE
16ltr.enable_alerts(True, UV, 1)
17
18while True:
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)