#!/usr/bin/python3 # -*- coding: UTF-8 -*- # my previous attempts at measuring outdoor light levels have kinda sucked # this is attempt #2 using the veml7700 breakout board as provided by adafruit # thanks adafruit! # # more here: # https://www.adafruit.com/product/4162 # https://learn.adafruit.com/adafruit-veml7700?view=all # https://circuitpython.readthedocs.io/projects/veml7700/en/latest/api.html import time, sys, busio, board, adafruit_veml7700 sys.path.append('/home/ghz/wxlib') import wxlib as wx wx_dir = "/home/ghz/light_wx" dat_fname='v2_light.dat' i2c = busio.I2C(board.SCL, board.SDA) vis = adafruit_veml7700.VEML7700(i2c) # given our experience with the v1 light sensor, just set the # gain and integration time to be as numb as possible. accuratley # measuring light levels under one or two lux doesn't help us # when it all looks like 0 on a graph that goes between 0-30klux. # # ALS_25MS, ALS_50MS, ALS_100MS, ALS_200MS, ALS_400MS, ALS_800MS vis.light_integration_time = vis.ALS_25MS # ALS_GAIN_2, ALS_GAIN_1, ALS_GAIN_1_4, ALS_GAIN_1_8 vis.light_gain = vis.ALS_GAIN_1_8 if __name__ == "__main__": vis_counts_total = 0 vis_lux_total = 0 count = 0 while True: # viscount! haha! vis_counts = vis.light vis_lux = vis.lux if isinstance(vis_lux, float) and isinstance(vis_counts, int): vis_lux_total += vis_lux vis_counts_total += vis_counts count += 1 if count >= 160: ts = time.strftime("%Y%m%d%H%M%S", time.gmtime()) dat = "%s\tvis_lux: %.2f\tvis_counts: %d\tpi_temp_C: %.2f\n" % \ (ts, vis_lux_total / count, vis_counts_total / count, float(wx.pi_temp_read()) / 1000) wx.write_out_dat_stamp(ts, dat_fname, dat, wx_dir) vis_counts_total = 0 vis_lux_total = 0 count = 0 time.sleep(0.1)