예제 #1
0
def main():
    #mlx90614 calling function
    i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
    mlx = adafruit_mlx90614.MLX90614(i2c)

    while mlx is not None:

        #mlx90614s readings
        mlx_ambient = round(mlx.ambient_temperature, 2)
        mlx_object = round(mlx.object_temperature, 2)

        print("mlx_ambient: ", mlx_ambient, "   mlx_object: ", mlx_object,
              "  ", str(datetime.now()))

        #save sensor data to firestore
        db.collection('heat_sensor').add({
            'mlx_ambient':
            mlx_ambient,
            'mlx_object':
            mlx_object,
            'timestamp':
            firestore.SERVER_TIMESTAMP
        })

        #store data every 3 seconds
        time.sleep(3)
예제 #2
0
def readTemperatura():
    global promedioTemperatura
    promedioTemperatura = 0.0
    i2c = board.I2C()
    mlx = adafruit_mlx90614.MLX90614(i2c)
    temp = 0.0
    tLow = 0.0
    tHigh = 0.0
    TA = 0.0
    TF = 0.0
    TCore = 0.0
    varTemp = 0.007358834
    varProcess = 1e-9
    Pc = 0.0
    G = 0.0
    P = 1.0
    Xp = 0.0
    Zp = 0.0
    Xe = 0.0

    for i in range(10):
        temp = mlx.object_temperature

        while temp < 0 or temp > 45:
            print("Sensor no responde")
            #mlx.writeEmissivity(0.98);
            time.sleep(100)
            temp = mlx.object_temperature
            print(temp)

        #FILTRO KALMAN
        Pc = P + varProcess
        G = Pc / (Pc + varTemp)
        P = (1 - G) * Pc
        Xp = Xe
        Zp = Xp
        Xe = G * (temp - Zp) + Xp
        time.sleep(0.01)  #delay de 10ms

    TA = mlx.ambient_temperature

    if TA <= 25:
        tLow = 32.66 + 0.186 * (TA - 25)
        tHigh = 34.84 + 0.148 * (TA - 25)
    if TA > 25:
        tLow = 32.66 + 0.086 * (TA - 25)
        tHigh = 34.84 + 0.100 * (TA - 25)

    TF = Xe

    if TF < tLow:
        TCore = 36.3 + (0.551658273 + 0.021525068 * TA) * (TF - tLow)
    if tLow < TF and TF < tHigh:
        TCore = 36.3 + 0.5 / (tHigh - tLow) * (TF - tLow)
    if TF > tHigh:
        TCore = 36.8 + (0.829320618 + 0.002364434 * TA) * (TF - tHigh)

    promedioTemperatura = TCore
예제 #3
0
 def __init__(self):
     self.thermal_stat = True
     self.back_temper_flag = False
     self.no_face_detection = True
     self.detection_state = THERMAL_STATE_NO_DETECTION
     self.body_temp = -1000
     self.back_temper = -1000
     i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
     self.mlx = adafruit_mlx90614.MLX90614(i2c)
     self.sensor_thread = threading.Thread(target=self.detect_thread_func)
     #self.sensor_thread = threading.Thread(target=self.threadfunc)
     self.sensor_thread.start()
예제 #4
0
 def __init__(self):
     try:
         self.i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
         self.mlx = adafruit_mlx90614.MLX90614(self.i2c)
     except:
         print("The sensor was not plugged in correctly")
         print(
             "Please plug the sensor into the GPIO pins SDA, SCL, GND and 3v3 power and run again"
         )
         print(
             "Make sure to only use a 3 volt version of the MLX90614 sensor"
         )
         print(
             "This software has only been tested to work with a 3 volt sensor"
         )
         print("The application will now exit")
         exit()
예제 #5
0
import paho.mqtt.client as mqtt
from threading import Thread
import eventlet
import picamera
import cv2
import socket
import io

#starting eventlet for socketio and setting up GPIO pin modes
eventlet.monkey_patch()
GPIO.setwarnings(False)
ir = 21
GPIO.setup(ir, GPIO.IN)
#initializing I2C bus
i2c = bus.I2C(board.SCL, board.SDA, frequency=100000)
mlx = adafruit_mlx90614.MLX90614(i2c)

#starting mqtt service
mqttc = mqtt.Client()
mqttc.connect("localhost", 1883, 60)
mqttc.loop_start()

app = Flask(__name__)

socketio = SocketIO(app, async_mode=None, logger=True, engineio_logger=True)

thread = None

ap = argparse.ArgumentParser()
ap.add_argument("-f",
                "--face",
예제 #6
0
def detect_mask(frameCount):

    global vs, outputFrame, lock, scannedState

    i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
    mlx = adafruit_mlx90614.MLX90614(i2c)

    with open('lbl.txt', 'r') as f:
        labels = [line.strip() for line in f.readlines()]

    interpreter = tflite.Interpreter(model_path='model4.tflite')
    interpreter.allocate_tensors()

    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()
    height = input_details[0]['shape'][1]
    width = input_details[0]['shape'][2]

    while True:
        frame = vs.read()
        frame = imutils.resize(frame, width=480)
        frame_org = frame.copy()
        frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        imH, imW = frame.shape[:2]
        frame_resized = cv2.resize(frame_rgb, (width, height))
        input_data = np.expand_dims(frame_resized, axis=0)

        interpreter.set_tensor(input_details[0]['index'], input_data)
        interpreter.invoke()

        boxes = interpreter.get_tensor(output_details[0]['index'])[
            0]  # Bounding box coordinates of detected objects
        classes = interpreter.get_tensor(
            output_details[1]['index'])[0]  # Class index of detected objects
        scores = interpreter.get_tensor(
            output_details[2]['index'])[0]  # Confidence of detected objects

        for i in range(len(scores)):
            if ((scores[i] > 0.3) and (scores[i] <= 1.0)):
                ymin = int(max(1, (boxes[i][0] * imH)))
                xmin = int(max(1, (boxes[i][1] * imW)))
                ymax = int(min(imH, (boxes[i][2] * imH)))
                xmax = int(min(imW, (boxes[i][3] * imW)))

                temp = mlx.object_temperature
                err = 16.8
                cal = 3.8
                temp = ((temp * (err / 100)) + temp) + cal

                color = (10, 255, 0)

                if classes[i]:
                    color = (10, 120, 255)

                if temp > 38.0:
                    color = (10, 0, 255)

                # cv2.rectangle(frame, (xmin,ymin), (xmax,ymax), color, 2)
                cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color, 2)

                object_name = labels[int(
                    classes[i]
                )]  # Look up object name from "labels" array using class index
                label = "{0}: {1}C".format(object_name, str(round(
                    temp, 1)))  # Example: 'person: 72%'7
                labelSize, baseLine = cv2.getTextSize(label,
                                                      cv2.FONT_HERSHEY_SIMPLEX,
                                                      0.7, 2)  # Get font size
                label_ymin = max(
                    ymin, labelSize[1] + 10
                )  # Make sure not to draw label too close to top of window
                cv2.rectangle(
                    frame, (xmin, label_ymin - labelSize[1] - 10),
                    (xmin + labelSize[0], label_ymin + baseLine - 10), color,
                    cv2.FILLED)  # Draw white box to put label text in
                cv2.putText(frame, label, (xmin, label_ymin - 7),
                            cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0),
                            2)  # Draw label text

                save_frame = frame_org.copy()

                cv2.putText(save_frame, "{0}".format(object_name),
                            (xmin, label_ymin + 12), cv2.FONT_HERSHEY_SIMPLEX,
                            0.7, color, 2)  # Draw label text
                cv2.putText(save_frame, "{0}C".format(str(round(temp, 1))),
                            (xmin, ymax - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.7,
                            color, 2)  # Draw label text

                if not scannedState:
                    time.sleep(1)
                    beep()

                scannedState = True
                simpan_gambar(save_frame[ymin:ymax, xmin:xmax])

        cv2.circle(frame, (int(imW / 2), int(imH / 3)), 2, (0, 0, 255), 2)

        with lock:
            outputFrame = frame.copy()
예제 #7
0
#!/usr/bin/env python3

import board
import busio as io
import adafruit_mlx90614

i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
temperature = adafruit_mlx90614.MLX90614(i2c).object_temperature
print("{0:0.2f}".format(temperature))
예제 #8
0
import board
import busio as io
import adafruit_mlx90614 as ml

i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
mlx = ml.MLX90614(i2c)

def get_object_temperature():    
    return mlx.object_temperature
예제 #9
0
#!/usr/bin/env python3

import board
import busio as io
import adafruit_mlx90614

i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
temperature = adafruit_mlx90614.MLX90614(i2c).ambient_temperature
print("{0:0.2f}".format(temperature))
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 29 18:11:58 2020

@author: ME
"""
try:
    import keyboard
    import board
    import busio as io
    import adafruit_mlx90614
    import adafruit_vl53l0x
    i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
    temperature_sensor = adafruit_mlx90614.MLX90614(i2c)
    proximity_sensor = adafruit_vl53l0x.VL53L0X(i2c)
except Exception as e:
    print(e)
    pass


def init_sensors(rpi):
    if rpi:
        return (get_temperature_rpi, get_proximity_rpi)
    else:
        return (get_temperature_pc, get_proximity_pc)


def temperature_adjusted(x):
    return (0.81 + 0.0000486382 * (x) + 0.0000208635 * pow(x, 2)) * 100

예제 #11
0
    def __init__(self):

        #set up the necessary info for the sensors that are active.

        # create a simple reference for the degree symbol since we use it a lot
        self.deg_sym = '\xB0'

        self.generators = False

        # add individual sensor module parameters below.
        #0				1			2		3		4
        #info = (lower range, upper range, unit, symbol)
        #'value','min','max','dsc','sym','dev','timestamp'

        # testing:
        # data fragments (objects that contain the most recent sensor value,
        # plus its context) are objects called Fragment().
        if configure.system_vitals:

            self.step = 0.0
            self.step2 = 0.0
            self.steptan = 0.0
            totalmem = float(psutil.virtual_memory().total) / 1024

            self.cputemp = Fragment(0, 100, "CpuTemp", self.deg_sym + "c",
                                    "RaspberryPi")
            self.cpuperc = Fragment(0, 100, "CpuPercent", "%", "Raspberry Pi")
            self.virtmem = Fragment(0, totalmem, "VirtualMemory", "b",
                                    "RaspberryPi")
            self.bytsent = Fragment(0, 100000, "BytesSent", "b", "RaspberryPi")
            self.bytrece = Fragment(0, 100000, "BytesReceived", "b",
                                    "RaspberryPi")

            if self.generators:
                self.sinewav = Fragment(-100, 100, "SineWave", "",
                                        "RaspberryPi")
                self.tanwave = Fragment(-500, 500, "TangentWave", "",
                                        "RaspberryPi")
                self.coswave = Fragment(-100, 100, "CosWave", "",
                                        "RaspberryPi")
                self.sinwav2 = Fragment(-100, 100, "SineWave2", "",
                                        "RaspberryPi")

        if configure.sensehat:
            self.ticks = 0
            self.onoff = 1

            # instantiate a sensehat object,
            self.sense = SenseHat()
            # Initially clears the LEDs once loaded
            self.sense.clear()
            # Sets the IMU Configuration.
            self.sense.set_imu_config(True, False, False)
            # activates low light conditions to not blind the user.
            self.sense.low_light = True

            self.sh_temp = Fragment(0, 65, "Thermometer", self.deg_sym + "c",
                                    "sensehat")
            self.sh_humi = Fragment(20, 80, "Hygrometer", "%", "sensehat")
            self.sh_baro = Fragment(260, 1260, "Barometer", "hPa", "sensehat")
            self.sh_magx = Fragment(-500, 500, "MagnetX", "G", "sensehat")
            self.sh_magy = Fragment(-500, 500, "MagnetY", "G", "sensehat")
            self.sh_magz = Fragment(-500, 500, "MagnetZ", "G", "sensehat")
            self.sh_accx = Fragment(-500, 500, "AccelX", "g", "sensehat")
            self.sh_accy = Fragment(-500, 500, "AccelY", "g", "sensehat")
            self.sh_accz = Fragment(-500, 500, "AccelZ", "g", "sensehat")

        if configure.ir_thermo:
            i2c = io.I2C(configure.PIN_SCL,
                         configure.PIN_SDA,
                         frequency=100000)
            self.mlx = adafruit_mlx90614.MLX90614(i2c)

            self.irt_ambi = Fragment(0, 80, "IR ambient [mlx]",
                                     self.deg_sym + "c")
            self.irt_obje = Fragment(0, 80, "IR object [mlx]",
                                     self.deg_sym + "c")

        if configure.envirophat:  # and not configure.simulate:

            self.ep_temp = Fragment(0, 65, "Thermometer", self.deg_sym + "c",
                                    "Envirophat")
            self.ep_colo = Fragment(20, 80, "Colour", "RGB", "Envirophat")
            self.ep_baro = Fragment(260, 1260, "Barometer", "hPa",
                                    "Envirophat")
            self.ep_magx = Fragment(-500, 500, "Magnetomer X", "G",
                                    "Envirophat")
            self.ep_magy = Fragment(-500, 500, "Magnetomer Y", "G",
                                    "Envirophat")
            self.ep_magz = Fragment(-500, 500, "Magnetomer Z", "G",
                                    "Envirophat")
            self.ep_accx = Fragment(-500, 500, "Accelerometer X (EP)", "g",
                                    "Envirophat")
            self.ep_accy = Fragment(-500, 500, "Accelerometer Y (EP)", "g",
                                    "Envirophat")
            self.ep_accz = Fragment(-500, 500, "Accelerometer Z (EP)", "g",
                                    "Envirophat")

        if configure.bme:
            # Create library object using our Bus I2C port
            i2c = io.I2C(configure.PIN_SCL, configure.PIN_SDA)
            self.bme = adafruit_bme680.Adafruit_BME680_I2C(i2c,
                                                           address=0x76,
                                                           debug=False)

            self.bme_temp = Fragment(-40, 85, "Thermometer",
                                     self.deg_sym + "c", "BME680")
            self.bme_humi = Fragment(0, 100, "Hygrometer", "%", "BME680")
            self.bme_press = Fragment(300, 1100, "Barometer", "hPa", "BME680")
            self.bme_voc = Fragment(300000, 1100000, "VOC", "KOhm", "BME680")

        if configure.pocket_geiger:
            self.radiat = Fragment(0.0, 10000.0, "Radiation", "urem/hr",
                                   "pocketgeiger")
            self.radiation = RadiationWatch(configure.PG_SIG, configure.PG_NS)
            self.radiation.setup()

        if configure.amg8833:
            self.amg_high = Fragment(0.0, 80.0, "IRHigh", self.deg_sym + "c",
                                     "amg8833")
            self.amg_low = Fragment(0.0, 80.0, "IRLow", self.deg_sym + "c",
                                    "amg8833")

        configure.sensor_info = self.get_all_info()
예제 #12
0
if __name__ == "__main__":

    # Create logger and set options
    logging.getLogger().setLevel(logging.DEBUG)
    logging.info("Starting logging")

    try:
        i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
        htu21dsensor = HTU21D(i2c)
    except:
        logging.info("No htu21dsensor detected, or a fault happened.",
                     exc_info=True)
        quit()
    try:
        MLX_temp_sensor = adafruit_mlx90614.MLX90614(i2c)
    except:
        logging.info("No MLX90614 detected, or a fault happened.",
                     exc_info=True)
        quit()

    while True:
        htusensor = {
            "temperature": htu21dsensor.temperature,
            "humidity": htu21dsensor.relative_humidity
        }
        logging.debug("Read this from htu21d: {}".format(htusensor))
        logging.info("Doing database logging now")
        logTemplineDB(logging, 'here', htu21dsensor.temperature)
        logTemplineDB(logging, 'MLXambient',
                      MLX_temp_sensor.ambient_temperature)
예제 #13
0
 def __init__(self):
     self.i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
     self.mlx = adafruit_mlx90614.MLX90614(self.i2c)