Exemplo n.º 1
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)
Exemplo n.º 2
0
def radar(width, height, color):
    #radar display config
    screen_width = width
    screen_height = height
    x = pygame.init()
    pygame.font.init()
    defaultFont = pygame.font.get_default_font()
    fontRenderer = pygame.font.Font(defaultFont, 20)
    #screen_width = 800
    #screen_height =500
    radarDisplay = pygame.display.set_mode((screen_width, screen_height))
    pygame.display.set_caption('Radar Screen')
    #GPIO setup

    RangerRead = GroveUltrasonicRanger(5)

    # targets list
    targets = {}
    a = 0
    #radar read and write to dict
    while True:
        for angle in range(0, 180):
            distance = RangerRead.get_distance()
            distance = round(distance, 2)
            if distance != -1 and distance <= 50:
                targets[angle] = Target(angle, distance)

            draw(radarDisplay, targets, angle, distance, fontRenderer,
                 screen_width, screen_height, color)
            time.sleep(0.0001)
            #draw_bck(radarDisplay, fontRenderer, screen_width, screen_height)
        targets = {}

        for angle in range(180, 0, -1):
            distance = RangerRead.get_distance()
            distance = round(distance, 2)
            if distance != -1 and distance <= 50:
                targets[angle] = Target(angle, distance)

            draw(radarDisplay, targets, angle, distance, fontRenderer,
                 screen_width, screen_height, color)
            time.sleep(0.0001)

            #draw_bck(radarDisplay, fontRenderer, screen_width, screen_height)

        targets = {}
def main():
    # Grove - Ultrasonic Ranger connected to port D5
    sensor = GroveUltrasonicRanger(5)

    # Grove - Relay connected to port D16
    relay = GroveRelay(16)

    while True:
        distance = sensor.get_distance()
        print('{} cm'.format(distance))

        if distance < 20:
            relay.on()
            print('relay on')

            time.sleep(1)

            relay.off()
            print('relay off')

            continue

        time.sleep(1)
Exemplo n.º 4
0
def main():

    # Grove - Servo connected to PWM port
    servo = GroveServo(12)
    servo_angle = 90

    # Grove - mini PIR motion pir_sensor connected to port D5
    pir_sensor = GroveMiniPIRMotionSensor(5)

    # Grove - Ultrasonic Ranger connected to port D16
    ultrasonic_sensor = GroveUltrasonicRanger(16)

    # Grove - LED Button connected to port D18
    button = GroveLedButton(18)

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

    # Grove - Light Sensor connected to port A2
    light_sensor = GroveLightSensor(2)
    light_state = False

    # Grove - Temperature&Humidity Sensor connected to port D22
    dht_sensor = DHT('11', 22)

    # Callback for server RPC requests (Used for control servo and led blink)
    def on_server_side_rpc_request(request_id, request_body):
        log.info('received rpc: {}, {}'.format(request_id, request_body))
        if request_body['method'] == 'getLedState':
            client.send_rpc_reply(request_id, light_state)
        elif request_body['method'] == 'setLedState':
            light_state = request_body['params']
            button.led.light(light_state)
        elif request_body['method'] == 'setServoAngle':
            servo_angle = float(request_body['params'])
            servo.setAngle(servo_angle)
        elif request_body['method'] == 'getServoAngle':
            client.send_rpc_reply(request_id, servo_angle)

    # Connecting to ThingsBoard
    client = TBDeviceMqttClient(thingsboard_server, access_token)
    client.set_server_side_rpc_request_handler(on_server_side_rpc_request)
    client.connect()

    # Callback on detect the motion from motion sensor
    def on_detect():
        log.info('motion detected')
        telemetry = {"motion": True}
        client.send_telemetry(telemetry)
        time.sleep(5)
        # Deactivating the motion in Dashboard
        client.send_telemetry({"motion": False})
        log.info("Motion alert deactivated")

    # Callback from button if it was pressed or unpressed
    def on_event(index, event, tm):
        if button._GroveLedButton__btn.is_pressed():
            log.debug('button: single click')
            telemetry = {"button_press": True}
            client.send_telemetry(telemetry)
            log.info("Pressed")
        else:
            log.debug('button: single click')
            telemetry = {"button_press": False}
            client.send_telemetry(telemetry)
            log.info("Unpressed")
        if event & Button.EV_SINGLE_CLICK:
            button.led.light(True)
        elif event & Button.EV_DOUBLE_CLICK:
            button.led.blink()
        elif event & Button.EV_LONG_PRESS:
            button.led.light(False)

    # Adding the callback to the motion sensor
    pir_sensor.on_detect = on_detect
    # Adding the callback to the button
    button.on_event = on_event
    try:
        while True:
            distance = ultrasonic_sensor.get_distance()
            log.debug('distance: {} cm'.format(distance))

            humidity, temperature = dht_sensor.read()
            log.debug('temperature: {}C, humidity: {}%'.format(
                temperature, humidity))

            moisture = moisture_sensor.moisture
            log.debug('moisture: {}'.format(moisture))

            log.debug('light: {}'.format(light_sensor.light))

            # Formatting the data for sending to ThingsBoard
            telemetry = {
                'distance': distance,
                'temperature': temperature,
                'humidity': humidity,
                'moisture': moisture,
                'light': light_sensor.light
            }

            # Sending the data
            client.send_telemetry(telemetry).get()

            time.sleep(.1)
    except Exception as e:
        raise e
    finally:
        client.disconnect()
Exemplo n.º 5
0
Arquivo: radar2.py Projeto: kgol/Radar
from display_bck import draw_bck
from grove.gpio import GPIO
from grove.grove_ultrasonic_ranger import GroveUltrasonicRanger

#radar display config
x = pygame.init()
pygame.font.init()
defaultFont = pygame.font.get_default_font()
fontRenderer = pygame.font.Font(defaultFont, 20)
screen_width = 800
screen_height = 500
radarDisplay = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('Radar Screen')
#GPIO setup

RangerRead = GroveUltrasonicRanger(5)

# targets list
targets = {}
a = 0
#radar read and write to dict
while True:
    for angle in range(0, 180):
        distance = RangerRead.get_distance()
        distance = round(distance, 2)
        if distance != -1 and distance <= 50:
            targets[angle] = Target(angle, distance)

        draw(radarDisplay, targets, angle, distance, fontRenderer,
             screen_width, screen_height)
        time.sleep(0.0001)
import datetime
import threading
import time

import paho.mqtt.publish as publish
import requests
from flask import Flask
from grove.gpio import GPIO
from grove.grove_ultrasonic_ranger import GroveUltrasonicRanger
import logging

# Connect the GroveUltrasonicRanger to D5 & D16
ultrasonic_ranger_1 = GroveUltrasonicRanger(5)
ultrasonic_ranger_2 = GroveUltrasonicRanger(16)
# Connect the buzzer to digital port 6
buzzer = GPIO(6, GPIO.OUT)
# Connect led to digital port 17
led = GPIO(17, GPIO.OUT)

app = Flask(__name__)

# variable states
alarmActive = False
buzzerActive = 0
testColor = 0
last_ultrasonic_ranger_1 = False
last_ultrasonic_ranger_2 = False

trigger_distance = 120
time_a = datetime.time(22, 0)
time_b = datetime.time(5, 00)
Exemplo n.º 7
0
def checkProximity():
    usonic = GroveUltrasonicRanger(5)
    print(usonic.get_distance())
    return usonic.get_distance