def __init__(self, parent=None): self.tsl = tsl2591() tk.Label.__init__(self, parent) self.lux = self.read_data() self.str_lux = str(round(self.lux, 2)) text = "Current light intensity: " + self.str_lux + " Lux" self.config(text=text) self.after(1, self.update_light)
def __init__(self, data, matrix): self._observer = ephem.Observer() self._observer.pressure = 0 self._observer.horizon = '-6' # Use geocoder library to get lat/lon g = geocoder.ip('me') debug.info("location for sunrise/sunset is: " + str(g.latlng)) self._observer.lat = str(g.lat) self._observer.lon = str(g.lng) self.brightness = 1 self.matrix = matrix self.data = data if data.config.dimmer_mode == "always": self.mode = True else: self.mode = False #If selected hardware, attempt to initialize sensor self.luxsensor = False # Make sure brightness values are not less than 0 or higher than 100 if data.config.dimmer_sunset_brightness < 0: data.config.dimmer_sunset_brightness = 0 if data.config.dimmer_sunset_brightness > 100: data.config.dimmer_sunset_brightness = 100 if data.config.dimmer_sunrise_brightness <0: data.config.dimmer_sunrise_brightness = 0 if data.config.dimmer_sunrise_brightness > 100: data.config.dimmer_sunrise_brightness = 100 if data.config.dimmer_source == "hardware": try: self.tsl = tsl2591() # initialize self.luxsensor = True except: debug.error("Light sensor not found or not connected, falling back to software mode") self.luxsensor = False # Fall back to using software mode self.data.config.dimmer_source = "software" # Light level in lux from config file self.lux = self.data.config.dimmer_light_level_lux
def main(): tsl = tsl2591() # initialize sample_interval = 5 # in second batch_duration = 2 # in hour second_in_hour = 3600 v_time = [] v_lux = [] v_full = [] v_ir = [] count = 0 batch = 0 while True: result = tsl.get_current() if count == 0: now = datetime.now() start = now.strftime("%Y-%m-%d_%H-%M") count += 1 now = datetime.now() dt_string = now.strftime("%d/%m/%Y %H:%M:%S") v_time.append(dt_string) v_lux.append(round(result['lux'], 2)) v_full.append(result['full']) v_ir.append(result['ir']) print(result) time.sleep(sample_interval) if count >= batch_duration * second_in_hour // sample_interval: print('Save one batch...') now = datetime.now() end = now.strftime("%Y-%M-%d_%H-%M") batch += 1 df = pd.DataFrame({ 'Time': v_time, 'Lux': v_lux, 'Full': v_full, 'IR': v_ir }) df.to_csv('Batch_' + str(batch) + '_' + start + ' to ' + end + '.csv', index=False) count = 0
def __init__(self, address=0x70): rospy.init_node("light_sensors", anonymous=True) self.sensor_publisher = rospy.Publisher("sensor_readings", Int32MultiArray, queue_size=10) self.rate = rospy.Rate(1) self.sensor_readings = Int32MultiArray() self.sensor_readings.data = [0, 0, 0, 0, 0, 0, 0, 0] # Get I2C bus self.bus = smbus.SMBus(1) # The TSL2561 default address is 0x70 self.address = address self.bus.write_byte_data(self.address, SWITCH, 0xff) # Start with Channel 0 self.tsl2591 = python_tsl2591.tsl2591() time.sleep(0.5)
def run_app(): tsl = tsl2591() tsl.enable() with DWM() as dwm: old_time = time.time() - 1.0 enabled = False while True: pos = dwm.locate() if pos: epoch_time = time.time() lux = {} # polling quickly is important for the UWB module to # locate, but the lux sensor can't poll too fast. if epoch_time - old_time > 1.0: if enabled: lux = tsl.get_current() enabled = False else: tsl.enable() enabled = True wait_time = time.time() json = {'location': pos, 'lux': lux, 'epoch_time': epoch_time} res = requests.post(ENDPOINT, json=json)
def __init__(self, data, matrix, scheduler): self._observer = ephem.Observer() self._observer.pressure = 0 self._observer.horizon = '-6' self.brightness = 1 self.matrix = matrix self.data = data self._observer.lat = str(self.data.latlng[0]) self._observer.lon = str(self.data.latlng[1]) if data.config.dimmer_mode == "always": self.mode = True else: self.mode = False #If selected hardware, attempt to initialize sensor self.luxsensor = False # Make sure brightness values are not less than 0 or higher than 100 if data.config.dimmer_sunset_brightness < 0: data.config.dimmer_sunset_brightness = 0 if data.config.dimmer_sunset_brightness > 100: data.config.dimmer_sunset_brightness = 100 if data.config.dimmer_sunrise_brightness < 0: data.config.dimmer_sunrise_brightness = 0 if data.config.dimmer_sunrise_brightness > 100: data.config.dimmer_sunrise_brightness = 100 if data.config.dimmer_source == "hardware": try: self.tsl = tsl2591() # initialize self.luxsensor = True except: debug.error( "Light sensor not found or not connected, falling back to software mode" ) self.luxsensor = False # Fall back to using software mode self.data.config.dimmer_source = "software" # Light level in lux from config file self.lux = self.data.config.dimmer_light_level_lux self.daytime = None self.nighttime = None #User set times to start and end dimmer at, comes from the config.json if len(data.config.dimmer_daytime) > 0: timeCheck = timeValidator(data.config.dimmer_daytime) if timeCheck == "12h": self.daytime = datetime.strptime(data.config.dimmer_daytime, '%I:%M %p').time() elif timeCheck == "24h": self.daytime = datetime.strptime(data.config.dimmer_daytime, '%H:%M').time() else: debug.error( "Daytime setting ({}) for dimmer is not a valid 12h or 24h format. Will use location for sunrise" .format(data.config.dimmer_daytime)) if len(data.config.dimmer_nighttime) > 0: timeCheck = timeValidator(data.config.dimmer_nighttime) if timeCheck == "12h": self.nighttime = datetime.strptime( data.config.dimmer_nighttime, '%I:%M %p').time() elif timeCheck == "24h": self.nighttime = datetime.strptime( data.config.dimmer_nighttime, '%H:%M').time() else: debug.error( "Night time setting ({}) for dimmer is not a valid 12h or 24h format. Will use location for sunset" .format(data.config.dimmer_nighttime)) scheduler.add_job(self.checkDimmer, 'interval', minutes=self.data.config.dimmer_frequency, jitter=60, id='Dimmer') #Check every 5 mins for testing only #scheduler.add_job(self.CheckForUpdate, 'cron', minute='*/5') #Set initial brightness self.checkDimmer()
GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) TRIG = 16 ECHO = 12 LED = 21 GPIO.setup(TRIG, GPIO.OUT) GPIO.setup(ECHO, GPIO.IN) GPIO.setup(LED, GPIO.OUT) StartTime = time.time() StopTime = time.time() ## SETUP i2c = busio.I2C(board.SCL, board.SDA) tsl2591_sensor = tsl2591.tsl2591() bme280_sensor = bme280.Adafruit_BME280_I2C(i2c) bme280_sensor.sea_level_pressure = 1013.7 nonBoard.average_and_send() while True: with nonBoard.lock: GPIO.output(TRIG, False) time.sleep(0.5) GPIO.output(TRIG, True) time.sleep(0.0001) GPIO.output(TRIG, False) GPIO.output(LED, GPIO.LOW) while GPIO.input(ECHO) == 0: #print ('NOT DETECTED!!') StartTime = time.time()
def get_LUX_TSL2591(TSL_I2C_BUS, TSL_ADDR): # Initialize the connector tsl = tsl2591(i2c_bus=TSL_I2C_BUS, sensor_address=TSL_ADDR) full, ir = tsl.get_full_luminosity() Lux = tsl.calculate_lux(full, ir) return round(Lux, 1)
def __init__(self, name): from python_tsl2591 import tsl2591 self._tsl = tsl2591() self._name = name
from python_tsl2591 import tsl2591 import time if __name__ == '__main__': tsl = tsl2591() # initialize while True: print(tsl.get_current()) time.sleep(2)
# Gain # The gain can be set to one of the following values # (though the last value, MAX, has limited use in the # real world given the extreme amount of gain applied): # GAIN_LOW: Sets the gain to 1x (bright light) # GAIN_MEDIUM: Sets the gain to 25x (general purpose) # GAIN_HIGH: Sets the gain to 428x (low light) # GAIN_MAX: Sets the gain to 9876x (extremely low light) GAIN_LOW = 0x00 GAIN_MED = 0x10 GAIN_HIGH = 0x20 GAIN_MAX = 0x30 #light sensor configuration lightSensor = tsl2591() lightSensor.set_timing(INTEGRATIONTIME_100MS) lightSensor.set_gain(GAIN_MED) #####Name for the Files that are save as CSV###### name = [ "EC", "Full", "Humidity", "Humidity_Outside", "IR", "Lux", "Temp", "Temp_Outside", "UV", "pH" ] #####Constants##### #Firebase url that we will send the data to firebase_url = 'https://seniordesign-e59ca.firebaseio.com/' #resistance in ohms for the EC Sensor rKnown = 965 #how many times the data is collected timeCollected = 0
p = subprocess.Popen(CMD, stdout=subprocess.PIPE, shell=True, executable='/bin/bash') return int(p.stdout.readlines()[0].strip()) # --------------------------------- BUS = 1 TSL2591_ADDR = 0x29 daynight_gpio = get_var('DAYNIGHT_PIN') # --------------------------------- lastvalue = 0 tsl = tsl2591(i2c_bus=BUS, sensor_address=TSL2591_ADDR) # Initialize the connector while True: full, ir = tsl.get_full_luminosity() lux = tsl.calculate_lux(full, ir) Luxrounded = round(lux, 1) print(Luxrounded) if lastvalue != Luxrounded: #print ("Lux = {}\n".format(Luxrounded)) os.system("echo {} > /tmp/tsl2561".format(Luxrounded)) lastvalue = Luxrounded #Set display brigthness if Luxrounded <= get_var('LUX_LEVEL_1'): os.system("crankshaft brightness set " + str(get_var('DISP_BRIGHTNESS_1')) + " &") step = 1
from datetime import datetime from python_tsl2591 import tsl2591 max_data = [] lux_data = [] CHUNK = 1024 * 2 # マイクによって変わる。上手くいかない場合色々試してください RATE = 48000 # 事前に確認したサンプリング周波数 save_name = "/home/pi/Desktop/user_env_data.csv" if not os.path.exists(save_name): cmd = 'echo datetime,temperature,humidity,sound,lux >> ' + save_name res = subprocess.check_call(cmd, shell=True) p = pyaudio.PyAudio() tsl = tsl2591() stream = p.open(format=pyaudio.paInt16, channels=1, rate=RATE, frames_per_buffer=CHUNK, input=True, output=True) def audio_trans(input): frames = (np.frombuffer(input, dtype="int16")) max_data.append(max(frames)) return