add tsl lux sensor

master
ademant 2019-06-08 16:10:39 +02:00
parent 2d172f8a1a
commit 2fdb8e67ce
3 changed files with 58 additions and 1 deletions

6
itsl.py Normal file
View File

@ -0,0 +1,6 @@
import tsl2591
tsl = tsl2591.Tsl2591() # initialize
full, ir = tsl.get_full_luminosity() # read raw values (full spectrum and ir spectrum)
lux = tsl.calculate_lux(full, ir) # convert raw values to lux
print lux, full, ir

View File

@ -54,6 +54,28 @@ if "sqlserver" in log_conf:
sqlhost=log_conf['sqlserver']['host']
sqlport=log_conf['sqlserver']['port']
# config of lux sensor tls2591
btls=False
if "tsl2591" in log_conf:
btls=True
if "enable" in log_conf['tsl2591']:
if log_conf['tsl2591']['enable'] == 0:
btls=False
if btls:
import tsl2591
tsl_port=1
if "port" in log_conf['tsl2591']:
tsl_port=int(log_conf['tsl2591']['port'])
tsl_add=0x29
if "address" in log_conf['tsl2591']:
tsl_add=int(log_conf['tsl2591']['address'],16)
try:
tsl = tsl2591.Tsl2591(i2c_bus=tsl_port,sensor_address=tsl_add) # initialize
except:
btls=False
else:
channel_names.append("lux")
# config of bme280 sensor
# use pip install RPi.bme280 for library
bbme=False
@ -139,7 +161,24 @@ if "vedirect" in log_conf:
# declare adc
badc=False
if "ads1x15" in log_conf:
badc,adc = ads1x15.init(log_conf['ads1x15'])
badc,adc = ads1x15.init(log_conf['ads1x15'])
bmcp9808=False
if "mcp9808" in log_conf:
bmcp9808=True
if "enable" in log_conf['mcp9808']:
if log_conf['mcp9808']['enable'] == 0:
bmcp9808=False
if bmcp9808:
import Adafruit_MCP9808.MCP9808 as MCP9808
try:
sens_9808 = MCP9808.MCP9808()
except:
bmcp9808 = False
else:
sens_9808.begin()
channel_names.append("temp_9808")
ch_val=np.zeros(len(channel_names))
for i in range(len(channel_names)):
@ -159,6 +198,10 @@ while a > 1:
ch_val[channel_names.index("CPU_temp")] = float(tFile.read())
tFile.close()
# get mcp9808 temperatur
if bmcp9808:
ch_val[channel_names.index("temp_9808")] = int(1000*sens_9808.readTempC())
# read adc's
if badc:
for i in adc:
@ -277,3 +320,5 @@ client.close()
f1.close()
print("done")

6
tsl.py Normal file
View File

@ -0,0 +1,6 @@
import tsl2591
tsl = tsl2591.Tsl2591(i2c_bus=1,sensor_address=0x29) # initialize
full, ir = tsl.get_full_luminosity() # read raw values (full spectrum and ir spectrum)
lux = tsl.calculate_lux(full, ir) # convert raw values to lux
print lux, full, ir