Exemple #1
0
def output():

    # Get Temperature, pressure and humidity
    bus = SMBus(1)
    bme280 = BME280(i2c_dev=bus)

    cpu_temps = [get_cpu_temperature()] * 5
    factor = 0.8

    raw_temp = bme280.get_temperature()
    cpu_temp = get_cpu_temperature()
    cpu_temps = cpu_temps[1:] + [cpu_temp]
    avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
    compTemp = raw_temp - ((avg_cpu_temp - raw_temp) / factor)

    pressure = bme280.get_pressure()
    humidity = bme280.get_humidity()

    # Get gases
    gases = gas.read_all()
    nh3 = gases.nh3
    no2 = gases.oxidising

    # Get light and proximity
    light = ltr559.get_lux()
    proxim = ltr559.get_proximity()

    # Calculate current time as string
    curTime = time.strftime("%d/%m/%y,%H:%M", time.localtime())

    return compTemp, humidity, nh3, no2, light, proxim, pressure, curTime
Exemple #2
0
def get_light():
    """Get all light readings"""
    lux = ltr559.get_lux()
    prox = ltr559.get_proximity()

    LUX.set(lux)
    PROXIMITY.set(prox)
def get_data():
    # get scd30 data
    data_raw_scd30 = sensor_scd30.readMeasurement()
    if (data_raw_scd30 == False):
        exit(1)

    [float_co2, float_T, float_rH] = data_raw_scd30
    scd30_data["co2"] = float_co2
    scd30_data["Temp"] = float_T
    scd30_data["Hum"] = float_rH

    # get enviro data

    enviro_data["proximity"] = ltr559.get_proximity()
    enviro_data["raw_temp"] = bme280.get_temperature()
    enviro_data["pressure"] = bme280.get_pressure()
    enviro_data["humidity"] = bme280.get_humidity()
    enviro_data["light"] = ltr559.get_lux()
    enviro_gas = gas.read_all()
    enviro_data["ox"] = enviro_gas.oxidising / 1000
    enviro_data["red"] = enviro_gas.reducing / 1000
    enviro_data["nh3"] = enviro_gas.nh3 / 1000

    # Outputs
    # print(scd30_data)
    # print(enviro_data)
    # time.sleep(10)
    data["enviro"] = enviro_data
    data["scd30"] = scd30_data
    return data
def main():
    i = 0
    # First data from enviro sensor is flawed.
    # This gets data after 3 cycles each with 1 second waiting time
    while i <= 2:
        try:
            temperature = bme280.get_temperature()
            temperature_compensated = get_compensated_temperature()
            pressure = bme280.get_pressure()
            humidity = bme280.get_humidity()
            lux = ltr559.get_lux()
            prox = ltr559.get_proximity()
            i += 1
            time.sleep(1)
        except:
            print(traceback.format_exc())
    sensor_id = "raspi-" + get_serial_number()
    sensor_type = "Enviro-plus"
    # mymeasurement,tag1=tag1,tag2=tag2 fieldA="aaa",fieldB="bbb
    print("sensor_temperature,sensor_id={},sensor_type={} temperature={:.2f},temperature_compensated={:.2f}".format(
        sensor_id, sensor_type, temperature, temperature_compensated))
    print("sensor_pressure,sensor_id={},sensor_type={} pressure={:.2f}".format(sensor_id, sensor_type, pressure))
    print("sensor_humidity,sensor_id={},sensor_type={} humidity={:.2f}".format(sensor_id, sensor_type, humidity))
    print("sensor_light,sensor_id={},sensor_type={} light={:.2f},proximity={:.2f}".format(
        sensor_id, sensor_type, lux, prox))
Exemple #5
0
def displayData():

    proximity = ltr559.get_proximity()

    # If the proximity crosses the threshold, toggle the mode
    if proximity > 1500 and time.time() - last_page > delay:
        mode += 1
        mode %= len(variables)
        last_page = time.time()

    # datetime for timestamp
    now = datetime.now()
    dt_string = now.strftime("%d/%m/%y %H:%M:%S")

    # variable = "temperatureF"
    unit = "F"
    cpu_temp = get_cpu_temperature()
    # Smooth out with some averaging to decrease jitter
    global cpu_temps
    cpu_temps = cpu_temps[1:] + [cpu_temp]
    avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
    raw_temp = bme280.get_temperature()
    dataTemp = raw_temp - ((avg_cpu_temp - raw_temp) / factor)
    dataTemp = (dataTemp * 1.8) + 32

    # variable = "pressure"
    # unit = "hPa"
    dataPressure = bme280.get_pressure()

    # variable = "humidity"
    #unit = "%"
    dataHumidity = bme280.get_humidity()

    # variable = "light"
    #unit = "Lux"
    if proximity < 10:
        dataLight = ltr559.get_lux()
    else:
        dataLight = 1

    # Format the variable name and value
    messageTemp = "{:.1f}{} {:.1f}{}".format(dataTemp, "F", dataPressure,
                                             "hPa")
    #messagePressure = "{}: {:.1f} {}".format("pressure"[:4], dataPressure, "hPa")
    messageHumidity = "{}: {:.1f} {}".format("humidity", dataHumidity, "%")
    #messageLight = "{}: {:.1f} {}".format("light"[:4], dataLight, "Lux")
    logging.info("Update")
    draw.rectangle((0, 0, WIDTH, HEIGHT), (13, 13, 13))
    draw.rectangle((0, 25, WIDTH, HEIGHT), (13, 13, 13))
    draw.rectangle((0, 50, WIDTH, HEIGHT), (13, 13, 13))
    #draw.rectangle((0, 75, WIDTH, HEIGHT), (13, 13, 13))
    # Write the text at the top in black
    draw.text((0, 0), messageTemp, font=font, fill=(217, 217, 217))
    #draw.text((0, 25), messagePressure, font=font, fill=(217, 217, 217))
    draw.text((0, 25), messageHumidity, font=font, fill=(217, 217, 217))
    #draw.text((0, 75), messageLight, font=font, fill=(0, 0, 0))
    draw.text((0, 50), dt_string, font=font, fill=(217, 217, 217))
    st7735.display(img)
Exemple #6
0
def get_light():
    """Get all light readings"""
    try:
        lux = ltr559.get_lux()
        prox = ltr559.get_proximity()
    except OSError as exception:
        logging.warning(
            "Failed to read light sensor with error: {}".format(exception))
    else:
        LUX.set(lux)
        PROXIMITY.set(prox)
def get_light():
    """Get all light readings"""
    try:
        lux = ltr559.get_lux()
        prox = ltr559.get_proximity()

        LUX.set(lux)
        PROXIMITY.set(prox)
    except IOError:
        logging.error(
            "Could not get lux and proximity readings. Resetting i2c.")
        reset_i2c()
Exemple #8
0
def get_light(log=False):
    # variable = "light"
    unit = "Lux"
    proximity = ltr559.get_proximity()
    if proximity < 10:
        data = ltr559.get_lux()
    else:
        data = 1
    if log == True:
        logging.info("light {} {}".format(data, unit))
    # display_text("light", data, unit)
    return (data, unit)
Exemple #9
0
    def take_readings(self):
        gas_data = gas.read_all()
        readings = {
            "proximity": ltr559.get_proximity(),
            "lux": ltr559.get_lux(),
            "temperature": self.bme280.get_temperature(),
            "pressure": self.bme280.get_pressure(),
            "humidity": self.bme280.get_humidity(),
            "gas/oxidising": gas_data.oxidising,
            "gas/reducing": gas_data.reducing,
            "gas/nh3": gas_data.nh3,
        }

        readings.update(self.latest_pms_readings)
        
        return readings
Exemple #10
0
    def get_measurement(self):
        """
        :returns: dict. Example::

            output = {
                "light": 109.3543,     # Lux
                "proximity": 103       # The higher the value, the nearest the object, within a ~5cm range
            }

        """

        import ltr559
        ltr559.set_proximity_active()

        return {
            'light': ltr559.get_lux(),
            'proximity': ltr559.get_proximity(),
        }
def read_values():
    values = {}
    cpu_temp = get_cpu_temperature()
    raw_temp = bme280.get_temperature()
    comp_temp = raw_temp - ((cpu_temp - raw_temp) / comp_factor)
    lux = ltr559.get_lux()
    proximity = ltr559.get_proximity()
    readings = gas.read_all()
    oxidising = readings.oxidising
    nh3 = readings.nh3
    reducing = readings.reducing
    adc = readings.adc
    noise = Noise()
    amps = noise.get_amplitudes_at_frequency_ranges([(100, 200), (500, 600),
                                                     (1000, 1200)])
    amps = [n * 32 for n in amps]

    values["temperature"] = "{:.2f}".format(comp_temp)
    values["cpu_temp"] = "{:.2f}".format(cpu_temp)
    values["pressure"] = "{:.2f}".format(bme280.get_pressure() * 100)
    values["humidity"] = "{:.2f}".format(bme280.get_humidity())
    values["lux"] = "{:05.02f}".format(lux)
    values["proximity"] = "{:05.02f}".format(proximity)
    values["nh3"] = "{:05.02f}".format(nh3)
    values["oxidising"] = "{:05.02f}".format(oxidising)
    values["reducing"] = "{:05.02f}".format(reducing)
    values["adc"] = "{:05.02f}".format(adc)
    values["amp_100_200"] = "{:05.02f}".format(amps[0])
    values["amp_500_600"] = "{:05.02f}".format(amps[1])
    values["amp_1000_1200"] = "{:05.02f}".format(amps[2])
    try:
        pm_values = pms5003.read()
        values["P2"] = str(pm_values.pm_ug_per_m3(2.5))
        values["P1"] = str(pm_values.pm_ug_per_m3(10))
    except ReadTimeoutError:
        pms5003.reset()
        pm_values = pms5003.read()
        values["P2"] = str(pm_values.pm_ug_per_m3(2.5))
        values["P1"] = str(pm_values.pm_ug_per_m3(10))
    return values
 def generate_output(self):
     self.output_dict['timestamp'] = time.time()
     if self.__variables['temp']: 
         self.output_dict['temp_value'] = self.bme280.get_temperature()
         self.output_dict['temp_unit'] = 'C'
     if self.__variables['pressure']:
         self.output_dict['pressure_value'] = self.bme280.get_pressure()
         self.output_dict['pressure_unit'] = 'hPa'
     if self.__variables['humidity']:
         self.output_dict['humidity_value'] = self.bme280.get_humidity()
         self.output_dict['humidity_unit'] = '%'
     if self.__variables['light']:
         proximity = ltr559.get_proximity()
         if proximity < 10:
             light_value = self.ltr559.get_lux()
         else:
             light_value = 1
         self.output_dict['light_value'] = light_value
         self.output_dict['light_unit'] = 'Lux'
     if self.__variables['oxidised']:
         self.output_dict['oxidised_value'] = gas.read_all().oxidising / 1000
         self.output_dict['oxidised_unit'] = 'kO'
     if self.__variables['reduced']:
         self.output_dict['reduced_value'] = gas.read_all().reducing / 1000
         self.output_dict['reduced_unit'] = 'kO'
     if self.__variables['nh3']:
         self.output_dict['nh3_value'] = gas.read_all().nh3 / 1000
         self.output_dict['nh3_unit'] = 'kO'
     if self.__variables['pm1']:
         self.output_dict['pm1_value'] = float(self.pms5003.read().pm_ug_per_m3(1.0))
         self.output_dict['pm1_unit'] = 'ug/m3'
     if self.__variables['pm25']:
         self.output_dict['pm25_value'] = float(self.pms5003.read().pm_ug_per_m3(2.5))
         self.output_dict['pm25_unit'] = 'ug/m3'
     if self.__variables['pm10']:
         self.output_dict['pm10_value'] = float(self.pms5003.read().pm_ug_per_m3(10))
         self.output_dict['pm10_unit'] = 'ug/m3'
     return self.output_dict
Exemple #13
0
    def start(self, callback):
        while True:
            # Climate
            self.temperature = self.bme280.get_temperature()
            self.pressure = self.bme280.get_pressure()
            self.humidity = self.bme280.get_humidity()
            time.sleep(1)

            # Light
            self.lux = ltr559.get_lux()
            self.prox = ltr559.get_proximity()
            time.sleep(1)

            # Gas
            gases = gas.read_all()
            self.oxidising = (gases.oxidising / 1000)
            self.nh3 = (gases.nh3 / 1000)
            self.reducing = (gases.reducing / 1000)
            time.sleep(1)

            # Callback all data in json format
            callback(self.get_all_data())
            time.sleep(1)
def take_reading(reading_number):

    BME280.update_sensor()
    gas = enviroplus.gas.read_all()

    pm_ok = False
    pm_tries = 0

    while not pm_ok and pm_tries < 10:
        try:
            pm = PMS5003.read()
            pm_ok = True
        except:
            pm_tries += 1

    if not pm_ok:
        pm1_0 = pm2_5 = pm10_0 = "NULL"
    else:
        (pm1_0, pm2_5, pm10_0) = [pm.pm_ug_per_m3(n) for n in [1.0, 2.5, 10.0]]

    reading = READING(
        timestamp=datetime.datetime.now().isoformat(),
        reading_number=reading_number,
        temperature=BME280.temperature,
        humidity=BME280.humidity,
        pressure=BME280.pressure,
        light=ltr559.get_lux(),
        proximity=ltr559.get_proximity(),
        gas_reducing=gas.reducing,
        gas_oxidising=gas.oxidising,
        gas_NH3=gas.nh3,
        PM1_0=pm1_0,
        PM2_5=pm2_5,
        PM10_0=pm10_0,
    )

    return reading
Exemple #15
0
def get_proximity():
    return ltr559.get_proximity()
bh1745.setup()
bh1745.set_leds(1)
r, g, b, c = bh1745.get_rgbc_raw()
bh1745.set_leds(0)

# VL53L1X
tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
tof.open() # Initialise the i2c bus and configure the sensor
tof.start_ranging(2) # Start ranging, 1 = Short Range, 2 = Medium Range, 3 = Long Range
tof.stop_ranging() # Stop ranging
distance_in_mm = tof.get_distance() # Grab the range in mm
distance_in_mm = min(MAX_DISTANCE_MM, distance_in_mm) # Cap at our MAX_DISTANCE

# ltr559
lux = ltr559.get_lux()
prox = ltr559.get_proximity()

# bme680
try:
    sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY)
except IOError:
    sensor = bme680.BME680(bme680.I2C_ADDR_SECONDARY)

sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)

sensor.set_gas_heater_temperature(320)
sensor.set_gas_heater_duration(150)
Exemple #17
0
def get_prox():
    pr1 = ltr559.get_proximity()
    pr1_format = "Proximity: " + str(pr1)
    return (pr1,pr1_format)
Exemple #18
0
def main():
    # Tuning factor for compensation. Decrease this number to adjust the
    # temperature down, and increase to adjust up
    factor = 2.25

    cpu_temps = [get_cpu_temperature()] * 5

    delay = 0.5  # Debounce the proximity tap
    mode = 10  # The starting mode
    last_page = 0

    for v in variables:
        values[v] = [1] * WIDTH

    # The main loop
    try:
        while True:
            proximity = ltr559.get_proximity()

            # If the proximity crosses the threshold, toggle the mode
            if proximity > 1500 and time.time() - last_page > delay:
                mode += 1
                mode %= (len(variables) + 1)
                last_page = time.time()

            # One mode for each variable
            if mode == 0:
                # variable = "temperature"
                unit = "C"
                cpu_temp = get_cpu_temperature()
                # Smooth out with some averaging to decrease jitter
                cpu_temps = cpu_temps[1:] + [cpu_temp]
                avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
                raw_temp = bme280.get_temperature()
                data = raw_temp - ((avg_cpu_temp - raw_temp) / factor)
                display_text(variables[mode], data, unit)

            if mode == 1:
                # variable = "pressure"
                unit = "hPa"
                data = bme280.get_pressure()
                display_text(variables[mode], data, unit)

            if mode == 2:
                # variable = "humidity"
                unit = "%"
                data = bme280.get_humidity()
                display_text(variables[mode], data, unit)

            if mode == 3:
                # variable = "light"
                unit = "Lux"
                if proximity < 10:
                    data = ltr559.get_lux()
                else:
                    data = 1
                display_text(variables[mode], data, unit)

            if mode == 4:
                # variable = "oxidised"
                unit = "kO"
                data = gas.read_all()
                data = data.oxidising / 1000
                display_text(variables[mode], data, unit)

            if mode == 5:
                # variable = "reduced"
                unit = "kO"
                data = gas.read_all()
                data = data.reducing / 1000
                display_text(variables[mode], data, unit)

            if mode == 6:
                # variable = "nh3"
                unit = "kO"
                data = gas.read_all()
                data = data.nh3 / 1000
                display_text(variables[mode], data, unit)

            if mode == 7:
                # variable = "pm1"
                unit = "ug/m3"
                try:
                    data = pms5003.read()
                except pmsReadTimeoutError:
                    logging.warning("Failed to read PMS5003")
                else:
                    data = float(data.pm_ug_per_m3(1.0))
                    display_text(variables[mode], data, unit)

            if mode == 8:
                # variable = "pm25"
                unit = "ug/m3"
                try:
                    data = pms5003.read()
                except pmsReadTimeoutError:
                    logging.warning("Failed to read PMS5003")
                else:
                    data = float(data.pm_ug_per_m3(2.5))
                    display_text(variables[mode], data, unit)

            if mode == 9:
                # variable = "pm10"
                unit = "ug/m3"
                try:
                    data = pms5003.read()
                except pmsReadTimeoutError:
                    logging.warning("Failed to read PMS5003")
                else:
                    data = float(data.pm_ug_per_m3(10))
                    display_text(variables[mode], data, unit)
            if mode == 10:
                # Everything on one screen
                cpu_temp = get_cpu_temperature()
                # Smooth out with some averaging to decrease jitter
                cpu_temps = cpu_temps[1:] + [cpu_temp]
                avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
                raw_temp = bme280.get_temperature()
                raw_data = raw_temp - ((avg_cpu_temp - raw_temp) / factor)
                save_data(0, raw_data)
                display_everything()
                raw_data = bme280.get_pressure()
                save_data(1, raw_data)
                display_everything()
                raw_data = bme280.get_humidity()
                save_data(2, raw_data)
                if proximity < 10:
                    raw_data = ltr559.get_lux()
                else:
                    raw_data = 1
                save_data(3, raw_data)
                display_everything()
                gas_data = gas.read_all()
                save_data(4, gas_data.oxidising / 1000)
                save_data(5, gas_data.reducing / 1000)
                save_data(6, gas_data.nh3 / 1000)
                display_everything()
                pms_data = None
                try:
                    pms_data = pms5003.read()
                except (SerialTimeoutError, pmsReadTimeoutError):
                    logging.warning("Failed to read PMS5003")
                else:
                    save_data(7, float(pms_data.pm_ug_per_m3(1.0)))
                    save_data(8, float(pms_data.pm_ug_per_m3(2.5)))
                    save_data(9, float(pms_data.pm_ug_per_m3(10)))
                    display_everything()

    # Exit cleanly
    except KeyboardInterrupt:
        sys.exit(0)
Exemple #19
0
def main(argv):
    valuename = ''
    try:
        opts, args = getopt.getopt(argv, "hi:o:", ["valuename="])
    except getopt.GetoptError:
        print("poll_enviro.py --valuename=<valuename to poll>")
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print("poll_enviro.py --valuename=<valuename to poll>")
            print("where valuename can be ONE of the following:")
            print(
                "temp , pressure , humidity , lux , air-oxidised , air-reduced , air-nh3 , air-pm1 , air-pm10 , air-pm25"
            )
            sys.exit()
        elif opt in ("-v", "--valuename"):
            valuename = arg

    if valuename == '':
        print("poll_enviro.py --valuename=<valuename to poll>")
        sys.exit(2)

    logging.basicConfig(
        format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
        level=logging.INFO,
        datefmt='%Y-%m-%d %H:%M:%S')

    logging.info("""poll_enviro.py - output enviro %s sensor value\n""",
                 valuename)

    # Tuning factor for compensation. Decrease this number to adjust the
    # temperature down, and increase to adjust up
    factor = 2.25

    cpu_temps = [get_cpu_temperature()] * 5

    delay = 0.5  # Debounce the proximity tap
    mode = 0  # The starting mode
    last_page = 0
    light = 1

    # One mode for each variable
    if valuename == "temp":
        # variable = "temperature"
        unit = "C"
        cpu_temp = get_cpu_temperature()
        # Smooth out with some averaging to decrease jitter
        cpu_temps = cpu_temps[1:] + [cpu_temp]
        avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
        try:
            raw_temp = bme280.get_temperature()
            data = raw_temp - ((avg_cpu_temp - raw_temp) / factor)
        except:
            logging.warning("Failed to read PMS5003")
            data = -1
        print(data)

    if valuename == "pressure":
        # variable = "pressure"
        unit = "hPa"
        try:
            data = bme280.get_pressure()
        except:
            logging.warning("Failed to read BME280")
            data = -1
        print(data)

    if valuename == "humidity":
        # variable = "humidity"
        unit = "%"
        try:
            data = bme280.get_humidity()
        except:
            logging.warning("Failed to read BME280")
            data = -1
        print(data)

    if valuename == "lux":
        proximity = -1
        try:
            proximity = ltr559.get_proximity()
        except:
            logging.warning("Failed to read LTR559 (proximity)")

        # variable = "light"
        unit = "Lux"
        if proximity < 10:
            try:
                data = ltr559.get_lux()
                logging.warning("Failed to read LTR559 (light-level)")
            except:
                data = -1
        else:
            data = 1
        print(data)

    if valuename == "air-oxdised":
        # variable = "oxidised"
        unit = "kO"
        data = gas.read_all()
        data = data.oxidising / 1000
        print(data)

    if valuename == "air-reduced":
        # variable = "reduced"
        unit = "kO"
        data = gas.read_all()
        data = data.reducing / 1000
        print(data)

    if valuename == "air-nh3":
        # variable = "nh3"
        unit = "kO"
        data = gas.read_all()
        data = data.nh3 / 1000
        print(data)

    if valuename == "air-pm1":
        # variable = "pm1"
        unit = "ug/m3"
        try:
            data = pms5003.read()
        except pmsReadTimeoutError:
            logging.warning("Failed to read PMS5003")
            data = -1
        else:
            data = float(data.pm_ug_per_m3(1.0))
        print(data)

    if valuename == "air-pm25":
        # variable = "pm25"
        unit = "ug/m3"
        try:
            data = pms5003.read()
        except pmsReadTimeoutError:
            logging.warning("Failed to read PMS5003")
            data = -1
        else:
            data = float(data.pm_ug_per_m3(2.5))
        print(data)

    if valuename == "air-pm10":
        # variable = "pm10"
        unit = "ug/m3"
        try:
            data = pms5003.read()
        except pmsReadTimeoutError:
            logging.warning("Failed to read PMS5003")
            data = -1
        else:
            data = float(data.pm_ug_per_m3(10))
        print(data)

    sys.exit(0)
Exemple #20
0
def get_proximity():
    data = {}
    data["proximity"] = ltr559.get_proximity()
    return data
Exemple #21
0
 now = datetime.now() 
 data['datetime'] = now.strftime("%d/%m/%Y %H:%M:%S")
 data['temperature'] = bme280.get_temperature()
 cpu_temp = get_cpu_temperature()
 # Smooth out with some averaging to decrease jitter
 cpu_temps = cpu_temps[1:] + [cpu_temp]
 data['avg_cpu_temp'] = sum(cpu_temps) / float(len(cpu_temps))
 raw_temp = data['temperature']
 data['comp_temp'] = raw_temp - ((data['avg_cpu_temp'] - data['temperature']) / data['cpu_factor'])
 data['pressure'] = bme280.get_pressure()
 data['humidity'] = bme280.get_humidity()        
 data['gas_nh3'] = gas.read_nh3()
 data['gas_oxidising'] = gas.read_oxidising()
 data['gas_reducing'] = gas.read_reducing()
 data['lux'] = ltr559.get_lux()
 data['prox'] = ltr559.get_proximity()            
 try:
     pms = pms5003.read()
     data['pms1_0'] = pms.data[0]
     data['pms2_5'] = pms.data[1]
     data['pms10'] = pms.data[2]
     data['pms1_0_atmenv'] = pms.data[3]
     data['pms2_5_atmenv'] = pms.data[4]
     data['pms10_atmenv'] = pms.data[5]
     data['pms_03_in_01'] = pms.data[6]
     data['pms_05_in_01'] = pms.data[7]
     data['pms_1_in_01'] = pms.data[8]
     data['pms_2_5_in_01'] = pms.data[9]
     data['pms_5_in_01'] = pms.data[10]
     data['pms_10_in_01'] = pms.data[11]
 except ReadTimeoutError:
Exemple #22
0
def main():
    t_logger = threading.Thread(target=retardar_logger)
    t_logger.start()

    #t_circle = threading.Thread(target=circle)
    #t_circle.start()

    # Tuning factor for compensation. Decrease this number to adjust the
    # temperature down, and increase to adjust up
    factor = 2.15

    cpu_temps = [get_cpu_temperature()] * 5

    delay = 0.5  # Debounce the proximity tap
    mode = 10     # The starting mode
    last_page = 0

    for v in variables:
        values[v] = [1] * WIDTH

    # The main loop
    try:
        while True:
            proximity = ltr559.get_proximity()

            # If the proximity crosses the threshold, toggle the mode
            if proximity > 1500 and time.time() - last_page > delay:
                mode += 1
                mode %= (len(variables) + 1)
                last_page = time.time()

            # One mode for each variable
            if mode == 0:
                # variable = "temperature"
                unit = "C"
                cpu_temp = get_cpu_temperature()
                # Smooth out with some averaging to decrease jitter
                cpu_temps = cpu_temps[1:] + [cpu_temp]
                avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
                print(avg_cpu_temp)
                raw_temp = bme280.get_temperature()
                data = raw_temp - ((avg_cpu_temp - raw_temp) / factor)
                display_text(variables[mode], data, unit)

            if mode == 1:
                # variable = "pressure"
                unit = "hPa"
                data = bme280.get_pressure()
                display_text(variables[mode], data, unit)

            if mode == 2:
                # variable = "humidity"
                unit = "%"
                data = bme280.get_humidity()
                display_text(variables[mode], data, unit)

            if mode == 3:
                # variable = "light"
                unit = "Lux"
                if proximity < 10:
                    data = ltr559.get_lux()
                else:
                    data = 1
                display_text(variables[mode], data, unit)

            if mode == 10:
                # Everything on one screen
                cpu_temp = get_cpu_temperature()
                # Smooth out with some averaging to decrease jitter
                cpu_temps = cpu_temps[1:] + [cpu_temp]
                avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
                print(avg_cpu_temp)
                raw_temp = bme280.get_temperature()
                raw_data = raw_temp - ((avg_cpu_temp - raw_temp) / factor)
                save_data(0, raw_data)
                display_everything()
                raw_data = bme280.get_pressure()
                save_data(1, raw_data)
                display_everything()
                if LOG:
                    log()
                raw_data = bme280.get_humidity()
                save_data(2, raw_data)
                if proximity < 10:
                    raw_data = ltr559.get_lux()
                else:
                    raw_data = 1
                save_data(3, raw_data)
                display_everything()

    # Exit cleanly
    except KeyboardInterrupt:
        sys.exit(0)
def get_proximity():
    proximity = ltr559.get_proximity()
    return proximity
Exemple #24
0
# Create a values dict to store the data
variables = [
    "temperature", "pressure", "humidity", "light", "oxidised", "reduced",
    "nh3", "pm1", "pm25", "pm10"
]

values = {}

for v in variables:
    values[v] = [1] * WIDTH

# The main loop
try:
    while True:
        proximity = ltr559.get_proximity()

        # If the proximity crosses the threshold, toggle the mode
        if proximity > 1500 and time.time() - last_page > delay:
            mode += 1
            mode %= len(variables)
            last_page = time.time()

        # One mode for each variable
        if mode == 0:
            # variable = "temperature"
            unit = "C"
            cpu_temp = get_cpu_temperature()
            # Smooth out with some averaging to decrease jitter

            avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
def main():
    # Tuning factor for compensation. Decrease this number to adjust the
    # temperature down, and increase to adjust up
    factor = 2.25

    cpu_temps = [get_cpu_temperature()] * 5

    delay = 0.5  # Debounce the proximity tap
    mode = 10  # The starting mode
    last_page = 0

    for v in variables:
        values[v] = [1] * WIDTH

    filename = time.strftime("%Y%m%d_%H%M%S")
    route = "/home/pi/Proyectos/enviroplus_localfiles/output_data/salida_" + filename
    print(route)
    # The main loop
    try:
        for muestra in range(3599):
            if muestra == 1:
                with open(route, 'w') as f:
                    f.write(variables.__str__()[1:-1])
                    f.write(", 'time'\n")

            proximity = ltr559.get_proximity()

            # Everything on one screen
            cpu_temp = get_cpu_temperature()
            # Smooth out with some averaging to decrease jitter
            cpu_temps = cpu_temps[1:] + [cpu_temp]
            avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
            raw_temp = bme280.get_temperature()
            temp = raw_temp - ((avg_cpu_temp - raw_temp) / factor)
            save_data(0, temp)
            display_everything()
            pressure = bme280.get_pressure()
            save_data(1, pressure)
            display_everything()
            humidity = bme280.get_humidity()
            save_data(2, humidity)
            if proximity < 10:
                lux = ltr559.get_lux()
            else:
                lux = 1
            save_data(3, lux)
            display_everything()
            gas_data = gas.read_all()
            save_data(4, gas_data.oxidising / 1000)
            save_data(5, gas_data.reducing / 1000)
            save_data(6, gas_data.nh3 / 1000)
            display_everything()
            pms_data = None
            try:
                pms_data = pms5003.read()
            except pmsReadTimeoutError:
                logging.warn("Failed to read PMS5003")
            else:
                save_data(7, float(pms_data.pm_ug_per_m3(1.0)))
                save_data(8, float(pms_data.pm_ug_per_m3(2.5)))
                save_data(9, float(pms_data.pm_ug_per_m3(10)))
                display_everything()
            sampletime = time.strftime("%Y%m%d_%H%M%S")
            # Create a list of data
            data = [
                str(temp),
                str(pressure),
                str(humidity),
                str(gas_data.oxidising / 1000),
                str(gas_data.reducing / 1000),
                str(gas_data.nh3 / 1000),
                str(pms_data.pm_ug_per_m3(1.0)),
                str(pms_data.pm_ug_per_m3(2.5)),
                str(pms_data.pm_ug_per_m3(10)), sampletime
            ]
            print(muestra)
            time.sleep(1)
            with open(route, 'a') as f:
                f.write(data.__str__()[1:-1])
                f.write("\n")
            f.close()

    # Exit cleanly
    except KeyboardInterrupt:
        sys.exit(0)