コード例 #1
0
def main():
    # Grove - 16x2 LCD(White on Blue) connected to I2C port
    lcd = JHD1802()

    # Grove - Moisture Sensor connected to port A0
    sensor = GroveMoistureSensor(0)

    # Grove - Buzzer connected to port PWM
    buzzer = upmBuzzer.Buzzer(getGpioLookup('GPIO12'))

    while True:
        mois = sensor.moisture
        if 0 <= mois and mois < 300:
            level = 'dry'
        elif 300 <= mois and mois < 600:
            level = 'moist'
        else:
            level = 'wet'
            buzzer.playSound(upmBuzzer.BUZZER_DO, 200000)

        print('moisture: {}, {}'.format(mois, level))

        lcd.setCursor(0, 0)
        lcd.write('moisture: {0:>6}'.format(mois))

        lcd.setCursor(1, 0)
        lcd.write('{0:>16}'.format(level))

        time.sleep(1)
コード例 #2
0
def main():
    sensor = DHT("11", 12)
    lcd = JHD1802()

    lcd.home()
    lcd.write("LCD model:".format(lcd.name))
    lcd.setCursor(1, 0)
    lcd.write("{}".format(lcd.name))
    time.sleep(5)
    lcd.clear()

    while True:
        humidity = []
        temperature = []

        for _ in range(60 * 60):
            humi, temp = sensor.read()
            humidity.append(humi)
            temperature.append(temp)
            lcd.setCursor(0, 0)
            lcd.write('Temp.: {}C'.format(temp))
            lcd.setCursor(1, 0)
            lcd.write('Humi.: {}%'.format(humi))
            time.sleep(1)
        lcd.clear()
        temp_avg = round(sum(temperature) / len(temperature), 1)
        hum_avg = round(sum(humidity) / len(humidity), 1)
        lcd.setCursor(0, 0)
        lcd.write('Avg. temp.: {0:.1f}C'.format(temp_avg))
        lcd.setCursor(1, 0)
        lcd.write('Avg. humi.: {0:.1f}%'.format(hum_avg))
        time.sleep(20)
        lcd.clear()
コード例 #3
0
def main():
    sensor_moist = GroveMoistureSensor(0)
    sensor_tmp = DHT("11", 12)
    lcd = JHD1802()

    lcd.home()
    lcd.write("LCD model:".format(lcd.name))
    lcd.setCursor(1, 0)
    lcd.write("{}".format(lcd.name))
    time.sleep(5)
    lcd.clear()

    while True:
        for i in range(10):
            humi, temp = sensor_tmp.read()
            lcd.setCursor(0, 0)
            lcd.write('Temp.: {0:.1f}C'.format(temp))
            lcd.setCursor(1, 0)
            lcd.write('Humi.: {0:.1f}%'.format(humi))
            time.sleep(5)
            # lcd.clear()
        lcd.clear()
        mois = sensor_moist.moisture
        lcd.setCursor(0, 0)
        lcd.write('moisture: {0:>6}'.format(mois))
        time.sleep(5)
        lcd.clear()
コード例 #4
0
def main():
    # Grove - 16x2 LCD(White on Blue) connected to I2C port
    lcd = JHD1802()

    lcd.setCursor(0, 0)
    lcd.write('hello, world!!!')

    print('application exiting...')
コード例 #5
0
def main():

    value = "Jarvis Focus"

    # Grove - 16x2 LCD(White on Blue) connected to I2C port
    lcd = JHD1802()

    display_in_lcd(lcd, 0, value)
    time.sleep(2)
    display_in_lcd(lcd, 0, "Identify")
    display_in_lcd(lcd, 1, "Temp-Humi")
    time.sleep(2)
    # Grove - Light Sensor connected to port A0
    light_sensor = GroveLightSensor(0)

    # Range Sensor - D24
    ultrasonic_range_senor = GroveUltrasonicRanger(24)

    # Motion Sensor - D18
    motion_sensor = GroveMiniPIRMotionSensor(18)

    # Grove - Temperature&Humidity Sensor connected to port D5
    climate_sensor = DHT('11', 5)

    # Grove - LED Button connected to port D16
    button = GroveLedButton(16)

    def on_detect():
        print('motion detected')
        
    motion_sensor.on_detect = on_detect

    def on_event(index, event, tm):
        if event & Button.EV_SINGLE_CLICK:
            print('single click')
            button.led.light(True)

        elif event & Button.EV_LONG_PRESS:
            print('long press')
            button.led.light(False)
    button.on_event = on_event
    
    while True:
        distance = ultrasonic_range_senor.get_distance()
        print('{} cm'.format(distance))
        light_sensor_output = light_sensor.light
        humi, temp = climate_sensor.read()
        row_one = f"L:{light_sensor_output}"
        row_two = f"H:{humi}-T:{temp}"
        display_in_lcd(lcd, 0, row_one)
        display_in_lcd(lcd, 1, row_two)
        time.sleep(2)
コード例 #6
0
def main():
    # Grove - 16x2 LCD(White on Blue) connected to I2C port
    lcd = JHD1802()

    # Grove - Temperature&Humidity Sensor connected to port D5
    sensor = DHT('11', 5)

    while True:
        humi, temp = sensor.read()
        print('temperature {}C, humidity {}%'.format(temp, humi))

        lcd.setCursor(0, 0)
        lcd.write('temperature: {0:2}C'.format(temp))

        lcd.setCursor(1, 0)
        lcd.write('humidity: {0:5}%'.format(humi))

        time.sleep(1)
コード例 #7
0
def main():

    value = "Jarvis Sense"

    # Grove - 16x2 LCD(White on Blue) connected to I2C port
    lcd = JHD1802()

    display_in_lcd(lcd, 0, value)
    time.sleep(2)
    display_in_lcd(lcd, 0, "Light-Moisture")
    display_in_lcd(lcd, 1, "Temp-Humi")
    time.sleep(2)
    # Grove - Light Sensor connected to port A0
    light_sensor = GroveLightSensor(0)

    # Grove - Moisture Sensor connected to port A2
    moisture_sensor = GroveMoistureSensor(2)

    # Grove - Temperature&Humidity Sensor connected to port D5
    climate_sensor = DHT('11', 5)

    # Grove - Relay connected to port D16
    relay = GroveRelay(16)
    relay.off(
    )  # It was supposed to be off. Due to mis-wiring it works the other way

    while True:
        light_sensor_output = light_sensor.light
        humi, temp = climate_sensor.read()
        moisture = moisture_sensor.moisture
        turn_on_fan = True if light_sensor_output < 30 else False
        fan_status = " "
        if turn_on_fan:
            relay.off()  # Turn of the relay will turn on the Fan
            fan_status = "Fan"
        else:
            relay.on()  # Turn off the fan
            fan_status = "X"

        row_one = f"L:{light_sensor_output}-M:{moisture} "
        row_two = f"H:{humi}-T:{temp}C-{fan_status}"
        display_in_lcd(lcd, 0, row_one)
        display_in_lcd(lcd, 1, row_two)
        time.sleep(2)
コード例 #8
0
        # Cannot synchronously wait for resubscribe result because we're on the connection's event-loop thread,
        # evaluate result with a callback instead.
        resubscribe_future.add_done_callback(on_resubscribe_complete)


def on_resubscribe_complete(resubscribe_future):
    resubscribe_results = resubscribe_future.result()
    print("Resubscribe results: {}".format(resubscribe_results))

    for topic, qos in resubscribe_results['topics']:
        if qos is None:
            sys.exit("Server rejected resubscribe to topic: {}".format(topic))


lcd = JHD1802()
lcd.setCursor(0, 0)
lcd.write("Hello Raspberry")

# Grove - LED Button connected to port D22
button = GroveLedButton(22)


# Callback when the subscribed topic receives a message
def on_message_received(topic, payload, **kwargs):

    print("Received message from topic '{}': {}".format(topic, payload))
    lcd.setCursor(0, 0)
    lcd.write(str(payload))
    if ("led" in str(payload)):
        if ("true" in str(payload)):
def main():
    relay = GroveRelay(18)
    button = GroveLedButton(5)
    lcd = JHD1802()
    temp_humd_sensor = DHT('11',16)
    classifier = '/home/pi/Desktop/Application/haarcascade_frontalface_default.xml'
    lcd.setCursor(0,0)
    lcd.write("System Activated")
    def doorbell_ring(index,event,tm):
        if event & Button.EV_SINGLE_CLICK:
            time_string = datetime.datetime.now().strftime("%H:%M:%S")
            lcd.setCursor(0,0)
            lcd.write("Doorbell Pressed")
            print("[INFO]Doorbell Rung...")
            button.led.light(True)
            lcd.setCursor(1,0)
            lcd.write("Look at Camera  ")
            time.sleep(2)
            with picamera.PiCamera() as camera:
                camera.resolution = (320, 240)
                lcd.setCursor(1,0)
                lcd.write("3 2 1...        ")
                time.sleep(3)
                camera.capture(stream,format='jpeg')
                lcd.setCursor(1,0)
                lcd.write("Image Captured ")
                print("[INFO]Image Captured...")
            data = pickle.loads(open('/home/pi/Desktop/Application/encodings.pickle', "rb").read())
            buff = numpy.frombuffer(stream.getvalue(), dtype=numpy.uint8)
            image = cv2.imdecode(buff, 1)
            face_cascade = cv2.CascadeClassifier(classifier)
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
            rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1,minNeighbors=5, minSize=(30, 30),flags=cv2.CASCADE_SCALE_IMAGE)
            boxes = [(y, x + w, y + h, x) for (x, y, w, h) in faces]
            encodings = face_recognition.face_encodings(rgb, boxes)
            names = []
            face_detected = False
            for encoding in encodings:
                matches = face_recognition.compare_faces(data["encodings"],encoding)
                name = "Unknown"
                if True in matches:
                     matchedIdxs = [i for (i, b) in enumerate(matches) if b]
                     counts = {}
                     for i in matchedIdxs:
                         name = data["names"][i]
                         counts[name] = counts.get(name, 0) + 1
                     name = max(counts, key=counts.get)
                names.append(name)
            for ((top, right, bottom, left), name) in zip(boxes, names):
                cv2.rectangle(image, (left, top), (right, bottom),(0, 255, 0), 2)
                y = top - 15 if top - 15 > 15 else top + 15
                cv2.putText(image, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX,0.75, (0, 255, 0), 2)
                face_detected = True
                if name != 'Unknown':
                     print("[INFO]Face Detected...")
                     print('[INFO] Entry Granted')
                     lcd.setCursor(0,0)
                     lcd.write("Welcome Home    ")
                     lcd.setCursor(1,0)
                     lcd.write("{}!          ".format(name))
                     relay.on()
                     print("[INFO] Door Locked")
                     time.sleep(5)
                     relay.off()
                else:
                     print('[INFO] Entry Denied ')
                     lcd.setCursor(0,0)
                     lcd.write("Face Unknown    ")
                     lcd.setCursor(1,0)
                     lcd.write("Contact Owner   ")
                     print('[INFO] Door Locked')
                     relay.off()
            if not face_detected:
               lcd.setCursor(0,0)
               lcd.write("No Face Detected ")
               lcd.setCursor(1,0)
               lcd.write("Try Again...     ")
            button.led.light(False)
            cv2.imwrite(path1+'/'+time_string+'.jpg',image)
            print("[INFO]Image Stored...\n")
            time.sleep(5)
            humidity,temperature = temp_humd_sensor.read()
            lcd.setCursor(0,0)
            lcd.write("Temperature: {0:2}C".format(temperature))
            lcd.setCursor(1,0)
            lcd.write("Humidity: {0:5}%".format(humidity))
    button.on_event = doorbell_ring
    while True:
            client_socket, address = server_socket.accept()
            print("[INFO] Connection Established")
            full_message = client_socket.recv(8)
            decoded_message = full_message.decode('utf-8')
            print('[INCOMING SIGNAL] {}'.format(decoded_message))
            if(decoded_message == '1'):
               relay.on()
               lcd.setCursor(0,0)
               lcd.write("Welcome Home!   ")
               lcd.setCursor(1,0)
               lcd.write("Door Unlocked...")
               print("[INFO] Door Open")
               time.sleep(3)
            elif (decoded_message == '2'):
               relay.off()
               lcd.setCursor(0,0)
               lcd.write("Entry Denied    ")
               lcd.setCursor(1,0)
               lcd.write("Door Locked...  ")
               print("[INFO] Door Closed")
               time.sleep(3)
            elif(decoded_message == '4'):
               try:
                  with picamera.PiCamera() as camera:
                         print("[INFO] Live Video Stream Started...")
                         while True:
                            client, address = server_socket.accept()
                            message = client.recv(8)
                            try:
                               check = message.decode('utf-8')
                               if(check == '1'):
                                  camera.capture('video.jpg')
                                  photo = 'video.jpg'
                                  file = open(photo,'rb')
                                  byte = file.read(1024)
                                  while(byte):
                                     client.send(byte)
                                     byte = file.read(1024)
                                  file.close()
                                  client.close()
                               elif(check == '0'):
                                  client.close()
                                  break
                            finally:
                               try:
                                  client.close()
                               finally:
                                  pass
               finally:
                   print("[INFO] Live Video Stream Ended...")
            elif(decoded_message == '5'):
                     humidity,temperature = temp_humd_sensor.read()
                     data  = str(humidity) + ' ' +  str(temperature)
                     client,address = server_socket.accept()
                     try:
                        client.send(data.encode('utf-8'))
                        client.close()
                     except:
                        try:
                          client.close()
                        except:
                          pass
            humidity,temperature = temp_humd_sensor.read()
            lcd.setCursor(0,0)
            lcd.write("Temperature: {0:2}C".format(temperature))
            lcd.setCursor(1,0)
            lcd.write("Humidity: {0:5}%".format(humidity))