def activate(self): assert self.params['address'] assert self.params['bus'] if 'name' in self.params: self.name = self.params['name'] + ' %i:%s' % ( self.params['bus'], hex(self.params['address'])) if not 'driver' in self.params.keys(): self.params['driver'] = None self.params['n_channels'] = 4 if not 'channel_names' in self.config: self.config['channel_names'] = [ 'Lux', 'IR', 'Visible', 'Full Spectrum' ] self.params['VIS_RANGE'] = float(2**32) self.params['IR_RANGE'] = float(2**16) self.params['raw_units'] = ['lux', '', '', ''] self.config['eng_units'] = ['lux', '', '', ''] self.config['scale'] = np.ones(self.params['n_channels'], ) self.config['offset'] = np.zeros(self.params['n_channels'], ) if ('untitled' in self.name.lower()) or (self.name == ''): self.name = 'TSL2591 Light Sensor I2C %i:%s' % ( self.params['bus'], self.params['address']) self.i2c = busio.I2C(board.SCL, board.SDA) self.dev = adafruit_tsl2591.TSL2591(self.i2c) return
def __init__(self) -> None: i2c = I2C(SCL, SDA) tsl = adafruit_tsl2591.TSL2591(i2c) # set gain and integration time; gain 0 = 1x & 1 = 16x. Integration time of 1 = 101ms tsl.gain = 0 tsl.integration_time = 1 # 101 ms intergration time. self.tsl = tsl
def __init__(self, gain=adafruit_tsl2591.GAIN_MED, integration_time=adafruit_tsl2591.INTEGRATIONTIME_200MS): # Initialize sensor self.i2c = busio.I2C(board.SCL, board.SDA) self.sensor = adafruit_tsl2591.TSL2591(self.i2c) self.sensor.gain = gain self.sensor.integration_time = integration_time
def __init__(self, i2c_bus, name="sns_hdlt", interval=SENSOR_UPDATE_INTERVAL, *args, **kwargs): Device.__init__(self, name=name, interval=interval, *args, **kwargs) import adafruit_tsl2591 self.sensor = adafruit_tsl2591.TSL2591(i2c_bus)
def tsl(): print(colored("TSL2591 started. . .", 'green')) tsl = adafruit_tsl2591.TSL2591(i2c) while True: lux = round(tsl.lux, 2) with lock: database.create_record(conn, "Measurements", ("lux", lux)) # client.publish("greenhouse/lux", lux) # print(lux, " lux") time.sleep(measurement_interval)
def read_all_sensors(tca): sensor_reading = [] for i in range(8): try: tsl=adafruit_tsl2591.TSL2591(tca[i]) sensor_reading.append(tsl.lux) except ValueError: pass # ValueError arises normally the sensor is missing at that position. return sensor_reading
def plugin_init(config): """ Initialise the plugin. Args: config: JSON configuration document for the plugin configuration category Returns: handle: JSON object to be used in future calls to the plugin Raises: """ i2c = busio.I2C(board.SCL, board.SDA) handle = copy.deepcopy(config) handle['sensor']=adafruit_tsl2591.TSL2591(i2c) return handle
def init(): i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_tsl2591.TSL2591(i2c) #sensor.gain = adafruit_tsl2591.GAIN_LOW GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(ready_led, GPIO.OUT) GPIO.setup(running_led, GPIO.OUT) GPIO.setup(complete_led, GPIO.OUT) GPIO.output(ready_led, GPIO.HIGH) GPIO.output(running_led, GPIO.LOW) GPIO.output(complete_led, GPIO.LOW) return sensor
def init(): """Initialize TSL2591 Lux Sensor Returns: int: 0 = OK | -1 = ERR """ global sensor try: sensor = adafruit_tsl2591.TSL2591(i2c) return 0 except: print("Failed to Initialize Sensor") return -1
def __init__(self, time_idx, prev_turbulences=None): # Read in light data # Initialize the I2C bus. i2c = busio.I2C(board.SCL, board.SDA) # Initialize the sensor. sensor = adafruit_tsl2591.TSL2591(i2c) self.light = int(sensor.lux) self.prev_turbulences = prev_turbulences # Facial Expression facial_expr = main_predict() if facial_expr == None: self.emotion = neutral else: self.emotion = facial_expr self.emotion = self.emotion[0].upper() + self.emotion[1:] # Pressure (from verify.py) #take a reading input = GPIO.input(GPIO_pin) if input: self.pressure = True print("Under Pressure") else: self.pressure = False # Turbulence with open('Daher_Turbulence_data.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=',') row = [line for idx, line in enumerate(readCSV) if idx == time_idx] row = row[0] row[1] = int(row[1]) row[2] = float(row[2]) row[3] = float(row[3]) # row = readCSV[time_idx] if self.prev_turbulences: if len(self.prev_turbulences ) == 5: # TODO could edit for more effects self.prev_turbulences.pop(0) self.prev_turbulences.append(abs(row[1])) self.turbulence = sum(self.prev_turbulences) / len( self.prev_turbulences) >= 1000 else: self.prev_turbulences = [row[1]] self.turbulence = abs(row[1]) > 1000 self.prev_turbulences = prev_turbulences
def read_all_sensors(): # Create I2C bus as normal i2c = busio.I2C(board.SCL, board.SDA) # Create the TCA9548A object and give it the I2C bus tca = adafruit_tca9548a.TCA9548A(i2c) # For each sensor, create it using the TCA9548A channel instead of the I2C object tsl0 = adafruit_tsl2591.TSL2591(tca[0]) tsl1 = adafruit_tsl2591.TSL2591(tca[1]) tsl2 = adafruit_tsl2591.TSL2591(tca[2]) tsl3 = adafruit_tsl2591.TSL2591(tca[3]) tsl4 = adafruit_tsl2591.TSL2591(tca[4]) tsl5 = adafruit_tsl2591.TSL2591(tca[5]) tsl6 = adafruit_tsl2591.TSL2591(tca[6]) tsl7 = adafruit_tsl2591.TSL2591(tca[7]) sensor_reading = [tsl0.lux, tsl1.lux, tsl2.lux, tsl3.lux, tsl4.lux, tsl5.lux, tsl6.lux, tsl7.lux] return sensor_reading
def __init__(self, logger, gain="med", integration_time=100): self.emulation_mode = module_fail self.logger = logger self.logger.debug("Setting up light sensor object") if self.emulation_mode: self.emulation_values = { "lux": 50, "visible": 50, "infrared": 50, "full_spectrum": 50, "raw_luminosity": 50 } self.logger.debug("Running in emulation mode") else: self.i2c = busio.I2C(board.SCL, board.SDA) self.sensor = adafruit_tsl2591.TSL2591(self.i2c) self.set_gain(gain) self.set_integration_time(integration_time)
def __init__(self): # Initialize the I2C bus. self.i2c = busio.I2C(board.SCL, board.SDA) # Initialize the sensor. self.sensor = adafruit_tsl2591.TSL2591(self.i2c) self.sensor.enable() self.integrationTimes = [[600, adafruit_tsl2591.INTEGRATIONTIME_600MS], [500, adafruit_tsl2591.INTEGRATIONTIME_500MS], [400, adafruit_tsl2591.INTEGRATIONTIME_400MS], [300, adafruit_tsl2591.INTEGRATIONTIME_300MS], [200, adafruit_tsl2591.INTEGRATIONTIME_200MS], [100, adafruit_tsl2591.INTEGRATIONTIME_100MS]] self.gains = [[1, adafruit_tsl2591.GAIN_LOW], [16, adafruit_tsl2591.GAIN_MED], [428, adafruit_tsl2591.GAIN_HIGH], [9876, adafruit_tsl2591.GAIN_MAX]] self.reps = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [3, 2], [4, 0], [4, 1], [4, 2], [5, 0], [5, 1], [5, 2]]
def get_light(): try: i2c = busio.I2C(SCL, SDA) sensor = adafruit_tsl2591.TSL2591(i2c) # print('Light: {0}lux'.format(sensor.lux)) # print('Visible: {0}'.format(sensor.visible)) # print('Infrared: {0}'.format(sensor.infrared)) result = {} result["light"] = sensor.lux result["visible"] = sensor.visible result["infrared"] = sensor.infrared result["full_spectrum"] = sensor.full_spectrum result["raw_luminosity"] = sensor.raw_luminosity print(result) return result except Exception as e: result = {} result["light"] = 0 result["visible"] = 0 result["infrared"] = 0 result["full_spectrum"] = 0 result["raw_luminosity"] = 0 return result
import busio from PIL import Image, ImageDraw, ImageFont import adafruit_ssd1306 # Soild Sensor Imports from board import SCL, SDA import busio from adafruit_seesaw.seesaw import Seesaw # Light Sensor Imports (TSL2591) import board import adafruit_tsl2591 # Setup for Light sensor i2c_light = busio.I2C(board.SCL, board.SDA) sensor = adafruit_tsl2591.TSL2591(i2c_light) # Setup for STEMMA sensor i2c_bus = busio.I2C(SCL, SDA) ss = Seesaw(i2c_bus, addr=0x36) # Setup for OLED # Create the I2C interface. i2c = busio.I2C(SCL, SDA) # Create the SSD1306 OLED class. # The first two parameters are the pixel width and pixel height. Change these # to the right size for your display! disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
if not 0x29 in tslI2C.scan(): tslI2C = busio.I2C(board.D1, board.D0) if not 0x29 in tslI2C.scan(): _log.info("Didn't find TSL2591") tslI2C = None else: _log.info("Found TSL2591 on I2C-0") else: _log.info("Found TSL2591 on I2C-1") except: _log.critical("Can't find I2C device 29 should be the Light sensor") tslI2C = None try: # Initialize the sensor. if (tslI2C is not None): tsl = adafruit_tsl2591.TSL2591(tslI2C) # You can optionally change the gain and integration time: tsl.gain = adafruit_tsl2591.GAIN_LOW tsl.integration_time = adafruit_tsl2591.INTEGRATIONTIME_100MS else: tsl = None except: _log.critical("Failed to create object for Light sensor") tsl = None try: bmeI2C = busio.I2C(board.SCL, board.SDA) if not 0x77 in bmeI2C.scan(): bmeI2C = busio.I2C(board.D1, board.D0) if not 0x77 in bmeI2C.scan(): _log.error(
import os import picamera import picamera.array import shutil import subprocess import sys from fractions import Fraction import adafruit_tsl2591 import busio import psutil import board # Create object to reference the TSL2591 (Lux Sensor) i2c = busio.I2C(board.SCL, board.SDA) tsl = adafruit_tsl2591.TSL2591(i2c) # Verify that the images/temp/videos folders exist rootFolder = "/home/pi/Desktop/" imageFolder = rootFolder + 'images' tempFolder = rootFolder + 'temp' videoFolder = rootFolder + 'videos' if not os.path.isdir(imageFolder): os.makedirs(imageFolder) if not os.path.isdir(videoFolder): os.makedirs(videoFolder) # Clear out tempFolder if os.path.isdir(tempFolder):
def run(self): #time a11 = 0 acd = [] m = 0 h = 0 def time_f(sec, minute, hour): sec += 1 if (sec > 59): minute = minute + 1 sec = 0 if (minute > 59): hour = hour + 1 minute = 0 aaa = [sec, minute, hour] print(hour, " ", minute, " ", sec) return aaa book = openpyxl.load_workbook('appending.xlsx') sheet = book.active #define lux sensor i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_tsl2591.TSL2591(i2c) adc_value = [] c = [] adc = Adafruit_ADS1x15.ADS1115() GAIN = 1 def teraadc(): global w global x global y GAIN = 1 a = [] temp = round( (adc.read_adc(0, gain=GAIN) - adc.read_adc(3, gain=GAIN)) * 5.0 / (32767 * .0065), 4) print("Temp", temp) lcd.write_string('Temp: ' + str(temp)) temperature.put(temp) w = list(temperature.queue) if (temperature.full()): temperature.get() time.sleep(1) lcd.clear() volt = round(adc.read_adc(1, gain=GAIN) * 4.8 * 72.2 / 32767, 4) print("Voltage", volt) lcd.write_string(u'Volt: ' + str(volt)) voltage.put(volt) x = list(voltage.queue) if (voltage.full()): voltage.get() time.sleep(1) lcd.clear() curr = round(adc.read_adc(2, gain=GAIN) * 4.6 * 0.95 / 32767, 4) print("Current", curr) lcd.write_string(u'Current: ' + str(curr)) current.put(curr) y = list(current.queue) if (current.full()): current.get() time.sleep(1) lcd.clear() a = [temp, volt, curr] return a def luxsensor(): global z lux = round(sensor.lux * 2, 4) print("Lux", lux) lcd.write_string(u'Lux: ' + str(lux)) luxxx.put(lux) if (luxxx.full()): luxxx.get() z = list(luxxx.queue) time.sleep(1) lcd.clear() return lux dim = sheet.dimensions c = list(dim) k = c[-1] t = int(k) while (True): print("\n") #time acd = time_f(a11, m, h) a11 = acd[0] m = acd[1] h = acd[2] adc_value = teraadc() adc_value.append(luxsensor()) j = 1 for i in adc_value: sheet.cell(row=t + 1, column=j).value = i j = j + 1 if (j > 4): t = t + 1 break book.save('appending.xlsx')
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT # This example shows using two TSL2491 light sensors attached to TCA9548A channels 0 and 1. # Use with other I2C sensors would be similar. import time import board import busio import adafruit_tsl2591 import adafruit_tca9548a # Create I2C bus as normal i2c = busio.I2C(board.SCL, board.SDA) # Create the TCA9548A object and give it the I2C bus tca = adafruit_tca9548a.TCA9548A(i2c) # For each sensor, create it using the TCA9548A channel instead of the I2C object tsl1 = adafruit_tsl2591.TSL2591(tca[0]) tsl2 = adafruit_tsl2591.TSL2591(tca[1]) # After initial setup, can just use sensors as normal. while True: print(tsl1.lux, tsl2.lux) time.sleep(0.1)
from prometheus_client import start_http_server, Gauge from gpiozero import DiskUsage, LoadAverage, CPUTemperature import time import board import busio import adafruit_sht31d import adafruit_tsl2591 if __name__ == '__main__': # Start up the server to expose the metrics. start_http_server(8000) # Connect to I2C sensors i2c = busio.I2C(board.SCL, board.SDA) sht31dSensor = adafruit_sht31d.SHT31D(i2c) #Humidity / Temperature Sensor tsl12591Sensor = adafruit_tsl2591.TSL2591(i2c) #Light Sensor # Define guages humidity = Gauge('grow_relative_humidity_percentage', 'Grow Tent Relative Humidity Percentage') temp = Gauge('grow_temperature', 'Grow Tent Temperature', ['units']) light = Gauge('grow_light', 'Grow Tent Light', ['spectrum']) pi = Gauge('rpi', 'Raspberry Pi', ['internal_device']) # Capture Metrics while True: currentTemp = sht31dSensor.temperature temp.labels('fahrenheit').set((currentTemp * (9 / 5)) + 32) temp.labels('celsius').set(currentTemp) humidity.set(sht31dSensor.relative_humidity)
continue #no change drip if countStemma >= 5: noData("Stemma Soil Moisture Sensor") time.sleep(30) if __name__ == "__main__": conn = mariadb.connect( user="******", password="******", host="localhost", database="greenhouse" ) cur = conn.cursor() I2C = busio.I2C(board.SCL,board.SDA) light = adafruit_tsl2591.TSL2591(I2C) servo = Maestro.Controller() dataPasser = data(70,0,0,0,0,0,0,0,[0,0,0,0,0,0]) format="%(asctime)s: %(message)s" logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S") w = threading.Thread(target=Interior,args=(1,)) x = threading.Thread(target=temperatureControl,args=(2,)) y = threading.Thread(target=Exterior,args=(3,)) z = threading.Thread(target=soil,args=(4,)) GPIO.setup(12,GPIO.OUT)#irrigation system GPIO.setup(23,GPIO.OUT)#lighting system GPIO.setup(17,GPIO.OUT)#heating system GPIO.setup(27,GPIO.OUT)#cooling SOLENOID GPIO.setup(22,GPIO.OUT)#cooling FAN GPIO.setup(19,GPIO.OUT)#Vent servo GPIO.setup(13,GPIO.OUT)#Shade servo
def __init__(self, deviceType="BME280"): #deviceType BME280 or BME680 self.deviceType = deviceType tslI2C = None try: tslI2C = busio.I2C(board.SCL, board.SDA) if not 0x29 in tslI2C.scan(): tslI2C = busio.I2C(board.D1, board.D0) if not 0x29 in tslI2C.scan(): print("Didn't find TSL2591") tslI2C = None else: print("Found TSL2591 on I2C-0") else: print("Found TSL2591 on I2C-1") except: print("Can't find I2C device 29 should be the Light sensor") tslI2C = None try: # Initialize the sensor. if (tslI2C is not None): self.tsl = adafruit_tsl2591.TSL2591(tslI2C) # You can optionally change the gain and integration time: self.tsl.gain = adafruit_tsl2591.GAIN_LOW self.tsl.integration_time = adafruit_tsl2591.INTEGRATIONTIME_100MS else: self.tsl = None except: print("Failed to create object for Light sensor") self.tsl = None try: bmeI2C = busio.I2C(board.SCL, board.SDA) if not 0x77 in bmeI2C.scan(): bmeI2C = busio.I2C(board.D1, board.D0) if not 0x77 in bmeI2C.scan(): print( "Can't find I2C device 77 should be the BME280/680 sensor" ) blynk.virtual_write(250, "no BMEx80") bmeI2C = None else: print( "Found I2C device 77 should be the BME280/680 sensor on I2C-0" ) else: print( "Found I2C device 77 should be the BME280/680 sensor on I2C-1" ) except: print("Can't find I2C device 77 should be the BME280/680 sensor") bmeI2C = None self.bme680 = None self.bme280 = None try: # Initialize the sensor. if (bmeI2C is not None): if (self.deviceType == "BME680"): print( "Creating BME680 object for device 77 should be the BME680 sensor" ) # self.bmex80 = adafruit_bme680.Adafruit_BME680_I2C(bmeI2C) self.bme680 = adafruit_bme680.Adafruit_BME680_I2C(bmeI2C) print( "Created BME680 object for device 77 should be the BME680 sensor" ) try: test = self.bme680.temperature print( "BME680 object for device 77 tested and working OK" ) except: self.bme680 = None self.bme280 = None print( "Failed to test object for device 77 should be the BME680 sensor" ) else: print( "Creating BME280 object for device 77 should be the BME280 sensor" ) self.bme280 = adafruit_bme280.Adafruit_BME280_I2C(bmeI2C) print( "Created BME280 object for device 77 should be the BME280 sensor" ) test = self.bme280.temperature print("BME280 object for device 77 tested and working OK") else: self.bme680 = None self.bme280 = None except: print( "Failed to create and test object for device 77 should be the BME280/680 sensor" ) self.bme680 = None self.bme280 = None
def __init__(self): self._sensor = adafruit_tsl2591.TSL2591(i2c=busio.I2C(24, 23)) self._sensor.gain = adafruit_tsl2591.GAIN_LOW
pass try: gyroscope = init_gyro(busio.I2C(board.SCL, board.SDA)) sensors.append('gyroscope') except: pass try: temphum = adafruit_sht31d.SHT31D(i2c) sensors.append('temphum') except: pass try: tsl = adafruit_tsl2591.TSL2591(i2c) # initialize sensors.append('tsl') except Exception as e: print('Error initializing TSL2591') print(e) pass print(sensors) while True: if 'accelerometer' in sensors: data_values.append(read_accelerometer(accelerometer)) if first_pass == True: headings.append(('accel_x', 'accel_y', 'accel_z', 'mag_x', 'mag_y', 'mag_z'))
# Sensor modules from board import SCL, SDA from busio import I2C import dgs import scd30 import sps30 import adafruit_sgp30 as sgp30 import adafruit_tsl2591 as tsl2591 import time # creating i2c bus i2c = I2C(SCL, SDA) # getting the adafruit sensors sgp = sgp30.Adafruit_SGP30(i2c) tsl = tsl2591.TSL2591(i2c) # getting DGS sensors no2, _, _ = dgs.takeMeasurement("/dev/ttyUSB0") co, _, _ = dgs.takeMeasurement("/dev/ttyUSB1") # getting sensirion sensors _, _, co2 = scd30.takeMasurement() n, m = sps30.takeMasurement()
import adafruit_tsl2591 from adafruit_seesaw.seesaw import Seesaw import RPi.GPIO as GPIO watered = False #SENSOR INTIALIZATION #intit i2c i2c_bus = busio.I2C(SCL, SDA) #init humidity sensor dht22 DHT_SENSOR = Adafruit_DHT.DHT22 DHT_PIN = 4 #init soil sensor ss = Seesaw(i2c_bus, addr=0x36) #init light sensor lightsensor = adafruit_tsl2591.TSL2591(i2c_bus) #FIREBASE CONNECTION firebase = firebase.FirebaseApplication( 'https://iot-garden-87415.firebaseio.com/', None) print(firebase) initTime = time.time() #PLANTS WELL-BEING CONSTANT TEMP_LOW = 12 TEMP_HIGH = 23 MOIST_LOW = 30 MOIST_HIGH = 60 LIGHT_TIME_LOW = 4 LIGHT_TIME_HIGH = 8 LUX_HIGH = 20000
# Simple demo of the TSL2591 sensor. Will print the detected light value # every second. import time import board import busio import adafruit_tsl2591 # Initialize the I2C bus. i2c = busio.I2C(board.SCL, board.SDA) # Initialize the sensor. sensor = adafruit_tsl2591.TSL2591(i2c) # You can optionally change the gain and integration time: # sensor.gain = adafruit_tsl2591.GAIN_LOW (1x gain) # sensor.gain = adafruit_tsl2591.GAIN_MED (25x gain, the default) # sensor.gain = adafruit_tsl2591.GAIN_HIGH (428x gain) # sensor.gain = adafruit_tsl2591.GAIN_MAX (9876x gain) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_100MS (100ms, default) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_200MS (200ms) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_300MS (300ms) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_400MS (400ms) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_500MS (500ms) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_600MS (600ms) # Read the total lux, IR, and visible light levels and print it every second. while True: # Read and calculate the light level in lux. lux = sensor.lux
# plexer = Multiplex(bus) # plexer.channel(address, 2) from time import sleep import board import busio import adafruit_tsl2591 import adafruit_tcs34725 import adafruit_tca9548a # print(board.SCL) i2c = busio.I2C(board.SCL, board.SDA) tca = adafruit_tca9548a.TCA9548A(i2c) # print(tca[0].tca.__dict__.values) tcs = adafruit_tcs34725.TCS34725(tca[0]) tcs.gain = 60 tcs.integration_time = 100 tsl = adafruit_tsl2591.TSL2591(tca[1]) tsl.gain = adafruit_tsl2591.GAIN_LOW tsl.integration_time = adafruit_tsl2591.INTEGRATIONTIME_100MS while True: print('lux: ', round(tsl.lux, 1)) print('color_raw: ', tcs.color_raw) print('color_rgb_bytes: ', tcs.color_rgb_bytes) # print('color_temperature:', round(tcs.color_temperature, 1)) print() sleep(2)