Open-source weather station for astronomy
at main 992 B view raw
1from machine import I2C, Pin 2import tsl2591 3import time 4 5# ESP8266 sous MicroPython 6i2c = I2C(0, sda=Pin(22), scl=Pin(23), freq=400_000) 7 8tsl = tsl2591.TSL2591(i2c = i2c) 9 10# To test saturation without auto-gain 11# GAIN_LOW (1x ->115000lux) 12# GAIN_MED (25x ->4600lux) 13# GAIN_HIGH (428x ->270lux) 14# GAIN_MAX (9876x ->6lux) 15# tsl.gain = tsl2591.GAIN_LOW 16# 100MS 17# 200MS 18# 300MS 19# 400MS 20# 500MS 21# 600MS 22# tsl.integration_time = tsl2591.INTEGRATIONTIME_100MS 23 24while True: 25 # To test saturation without auto-gain 26# try: 27# tsl_lux = tsl.lux 28# except RuntimeError: # Luminosity saturation 29# tsl_lux = -1 30 31 tsl_lux = tsl.lux_auto_gain 32 tsl_ir = tsl.infrared 33 tsl_vis = tsl.visible 34 tsl_full = tsl.full_spectrum 35 print(f"{tsl_lux:.5f} lux | Gain: {tsl.gain}") 36# print(f" Infrared (0-65535) : {tsl_ir:.5f}") 37# print(f" Visible (0-2147483647) : {tsl_vis:.5f}") 38# print(f" Full spectrum (0-2147483647): {tsl_full:.5f}") 39 time.sleep(1)