Exemple #1
0
 def __init__(self, pin):
     # High = light on
     self.led = Factory.getOneLed("GPIO-HIGH", pin)
     # Low = pressed
     self.btn = Factory.getButton("GPIO-LOW", pin + 1)
     self.__on_event = None
     self.btn.on_event(self, GroveLedButton.__handle_event)
 def __init__(self, pin):
     # High = pressed
     self.__btn = Factory.getButton("GPIO-HIGH", pin)
     # single WS2812 LED
     self.led = Factory.getOneLed("WS2812-PWM", pin + 1)
     self.__on_event = None
     self.__btn.on_event(self, GroveKeycap.__handle_event)
Exemple #3
0
 def __init__(self, pin):
     # Low = pressed
     self.__led = Factory.getOneLed("GPIO-HIGH", pin)
     self.__btn = Factory.getButton("GPIO-LOW", pin + 1)
     self.__led.light(False)
     self.__on_release = None
     self.__on_press = None
     self.__btn.on_event(self, GroveLedButton.__handle_event)
 def __init__(self, pin):
     # High = pressed
     self.__btn = Factory.getButton("GPIO-HIGH", pin)
     self.__last_time = time.time()
     self.__on_press = None
     self.__on_release = None
     self.__btn.on_event(self, GroveButton.__handle_event)
Exemple #5
0
def main():
    print("Insert Grove - I2C-High-Accuracy-Temperature")
    print("  to Grove-Base-Hat any I2C slot")

    sensor = Factory.getTemper("MCP9808-I2C")
    sensor.resolution(Temper.RES_1_16_CELSIUS)

    print('Detecting temperature...')
    while True:
        print('{} Celsius'.format(sensor.temperature))
        time.sleep(1)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = Factory.getTemper("NTC-ADC", pin)

    print('Detecting temperature...')
    while True:
        print('{} Celsius'.format(sensor.temperature))
        time.sleep(1)
def main():
    config = configparser.ConfigParser()
    config.read('config.ini')
    pin = int(config['DEFAULT']['temp_sensor_pin'])
    red = redis.Redis()

    sensor = Factory.getTemper("NTC-ADC", pin)
    
    while True:
        temp = float(sensor.temperature)
        red.mset({'temperature': round(temp)})
        time.sleep(INTERVAL)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = Factory.getTemper("NTC-ADC", pin)

    print('Detecting temperature...')
    while True:
        print('{} Celsius'.format(sensor.temperature))
        url = 'http://127.0.0.1:8000/temperature/{}?Value={}'.format(
            pin, sensor.temperature)
        urllib.request.urlopen(url)
        time.sleep(0.4)
Exemple #9
0
def main():
    print("Insert Grove - I2C-High-Accuracy-Temperature")
    print("  to Grove-Base-Hat any I2C slot")

    #I2C address of temperature device: 0x18 (default) to 0x1F
    i2c_id = 0x18

    sensor = Factory.getTemper("MCP9808-I2C", address=i2c_id)
    sensor.resolution(Temper.RES_1_16_CELSIUS)

    print('Detecting temperature...')
    while True:
        print('{} Celsius'.format(sensor.temperature))
        time.sleep(1)
Exemple #10
0
def main():

    # print disable
    sys.stdout = open(os.devnull, 'w')

    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = Factory.getTemper("NTC-ADC", pin)

    # print enable
    sys.stdout = sys.__stdout__

    print(sensor.temperature)
Exemple #11
0
import time
from grove.factory import Factory

pin = 16  # D16
button = Factory.getButton("GPIO-HIGH", pin)

while True:
    print(button.is_pressed())
    time.sleep(0.1)
 def __init__(self, pin):
     #Digital Port
     self.__btn = Factory.getButton("GPIO-HIGH", pin)
 def __init__(self, pin):
     #Analog Port
     self.__tmp = Factory.getTemper("NTC-ADC", pin)
    def __init__(self, master=None):

        self.warehouse_state = False
        self.door_outside_state = False
        self.door_inside_state = False
        self.door_count = 0
        self.system_on_time = 0
        self.system_on = 0
        self.system_delta_time = 0
        self.door_open_time = 0
        self.door_time = 0

        self.warehouse_button = GroveLedButton(5)
        self.door_outside_button = GroveLedButton(18)
        self.door_inside_button = GroveLedButton(16)

        self.warehouse_button.on_press = self.on_press_main
        self.door_outside_button.on_press = self.on_press_door_outside
        self.door_inside_button.on_press = self.on_press_door_inside

        self.warehouse_relay = GroveRelay(22)
        self.door_outside_relay = GroveRelay(26)
        self.door_inside_relay = GroveRelay(24)

        self.sensor_d = Factory.getTemper("MCP9808-I2C", 0x18)
        self.sensor_d.resolution(Temper.RES_1_16_CELSIUS)
        self.sensor_w = Factory.getTemper("MCP9808-I2C", 0x19)
        self.sensor_w.resolution(Temper.RES_1_16_CELSIUS)
        print('{:.1f} {:.1f} Door & Warehouse temperature'.format(
            self.sensor_d.temperature, self.sensor_w.temperature))

        # Handle tkinter part
        super().__init__(master)
        self.master.protocol("WM_DELETE_WINDOW", self.close_app)

        self.master.wm_title("Warehouse")
        self.master.wm_resizable(width=False, height=False)
        fontlabel = ('helvetica', 15, 'bold')

        # top row names

        self.lbl_main = tk.Label(self.master,
                                 text="System",
                                 width=15,
                                 font=fontlabel)
        self.lbl_main.grid(row=0, column=0)

        self.lbl_door_outside = tk.Label(self.master,
                                         text="Outside Door",
                                         width=15,
                                         font=fontlabel)
        self.lbl_door_outside.grid(row=0, column=1)

        self.lbl_door_inside = tk.Label(self.master,
                                        text="Inside Door",
                                        width=15,
                                        font=fontlabel)
        self.lbl_door_inside.grid(row=0, column=2)

        self.lbl_info = tk.Label(self.master,
                                 text="Data",
                                 width=15,
                                 font=fontlabel)
        self.lbl_info.grid(row=0, column=3)

        # top row with switches (buttons) in on state (red, grayed in off mode)

        self.btn_warehouse_on = tk.Button(self.master,
                                          text="Turn System On",
                                          width=15)
        # only screen control after physical switch (event_warehouse_switch) is turned on, then button is also active
        self.btn_warehouse_on["command"] = self.on_press_main
        self.btn_warehouse_on.grid(row=1, column=0)

        self.btn_door_outside_open = tk.Button(self.master,
                                               text="Open Outside Door",
                                               width=15)
        self.btn_door_outside_open["command"] = self.on_press_door_outside
        self.btn_door_outside_open.grid(row=1, column=1)

        self.btn_door_inside_open = tk.Button(self.master,
                                              text="Open Inside Door",
                                              width=15)
        self.btn_door_inside_open["command"] = self.on_press_door_inside
        self.btn_door_inside_open.grid(row=1, column=2)

        self.lbl_energy = tk.Label(self.master,
                                   text="loss: 0",
                                   width=15,
                                   height=4)
        self.lbl_energy.grid(row=1, column=3)

        # Status information in middle row

        self.lbl_state_main = tk.Label(self.master,
                                       bg='light grey',
                                       text="OFF",
                                       width=15,
                                       height=4)
        self.lbl_state_main.grid(row=2, column=0)

        self.lbl_state_door_outside = tk.Label(self.master,
                                               bg='light grey',
                                               text="Closed",
                                               width=15,
                                               height=4)
        self.lbl_state_door_outside.grid(row=2, column=1)

        self.lbl_state_door_inside = tk.Label(self.master,
                                              bg='light grey',
                                              text="Closed",
                                              width=15,
                                              height=4)
        self.lbl_state_door_inside.grid(row=2, column=2)

        self.lbl_temperature = tk.Button(self.master, text="temperature")
        self.lbl_temperature.grid(row=2, column=3)

        # bottom row with switches (buttons) in off state (black button grayed in on)

        self.btn_warehouse_off = tk.Button(self.master,
                                           text="Turn System Off",
                                           width=15)
        self.btn_warehouse_off.config(bg='#00C1FF', fg='white')
        self.btn_warehouse_off["command"] = self.on_press_main
        self.btn_warehouse_off.grid(row=3, column=0)

        self.btn_door_outside_close = tk.Button(self.master,
                                                text="Close Outside Door",
                                                width=15)
        self.btn_door_outside_close.config(bg='#00C1FF', fg='white')
        self.btn_door_outside_close["command"] = self.on_press_door_outside
        self.btn_door_outside_close.grid(row=3, column=1)

        self.btn_door_inside_close = tk.Button(self.master,
                                               text="Close Inside Door",
                                               width=15)
        self.btn_door_inside_close.config(bg='#00C1FF', fg='white')
        self.btn_door_inside_close["command"] = self.on_press_door_inside
        self.btn_door_inside_close.grid(row=3, column=2)

        self.lbl_system_on = tk.Label(self.master, text="time on: 0", width=15)
        self.lbl_system_on.grid(row=3, column=3)

        self.btn_stop = tk.Button(self.master, text="Stop")
        self.btn_stop["command"] = self.close_app
        self.btn_stop.grid(row=4, column=0)

        self.lbl_count = tk.Label(self.master, text="# door: 0", width=15)
        self.lbl_count.grid(row=3, column=3)

        self.update_temp()
Exemple #15
0
 def __init__(self, pin):
     self.__btn = Factory.getButton("GPIO-HIGH", pin)
def get_temp():
    sensor = Factory.getTemper("NTC-ADC", pinTemp)
    #print('{} Celsius'.format(sensor.temperature))
    return sensor.temperature
import time
from grove.factory import Factory
# connect to alalog pin 2(slot A2)
PIN = 0
sensor = Factory.getTemper("NTC-ADC", PIN)
print('Detecting temperature...')
while True:
    print('{} Celsius'.format(sensor.temperature))
    time.sleep(2)
Exemple #18
0
 def __init__(self, pin):
     self.__pin = pin
     self.__sensor = Factory.getTemper("NTC-ADC", pin)
Exemple #19
0
def get_sensor(pin):
    sensor = Factory.getTemper("NTC-ADC", pin)
    return sensor
Exemple #20
0
 def __init__(self):
     print('Fan Init')
     self.fan = Factory.getGpioWrapper("Buzzer", 12)
     self._status = 0
     self.fan.off()
Exemple #21
0
 def __init__(self):
     self.channel = 6
     self.sensor = Factory.getTemper("NTC-ADC", 6)
Exemple #22
0
                door_inside_button.led_on()


warehouse_button = GroveLedButton(5)
door_outside_button = GroveLedButton(18)
door_inside_button = GroveLedButton(16)

warehouse_button.on_press = on_press_main
door_outside_button.on_press = on_press_door_outside
door_inside_button.on_press = on_press_door_inside

warehouse_relay = GroveRelay(22)
door_outside_relay = GroveRelay(26)
door_inside_relay = GroveRelay(24)

temperature_doors = Factory.getTemper("MCP9808-I2C", 0x18)
temperature_doors.resolution(Temper.RES_1_16_CELSIUS)
temperature_warehouse = Factory.getTemper("MCP9808-I2C", 0x19)
temperature_warehouse.resolution(Temper.RES_1_16_CELSIUS)


async def main():
    print('starting OPC server ')
    opc_server = Server()
    await opc_server.init()
    opc_url = "opc.tcp://0.0.0.0:4840"
    opc_server.set_endpoint(opc_url)

    print('starting OPC server ..')
    opc_name = "Grove-opcua-server"
    addspace = await opc_server.register_namespace(opc_name)
    def __init__(self):

        self.warehouse_state = False
        self.door_outside_state = False
        self.door_inside_state = False

        self.warehouse_button = GroveLedButton(5)
        self.door_outside_button = GroveLedButton(18)
        self.door_inside_button = GroveLedButton(16)

        self.warehouse_button.on_press = self.on_press_main
        self.door_outside_button.on_press = self.on_press_door_outside
        self.door_inside_button.on_press = self.on_press_door_inside

        self.warehouse_relay = GroveRelay(22)
        self.door_outside_relay = GroveRelay(26)
        self.door_inside_relay = GroveRelay(24)

        self.time_stamp = datetime.now()
        self.temperature_doors = Factory.getTemper("MCP9808-I2C", 0x18)
        self.temperature_doors.resolution(Temper.RES_1_16_CELSIUS)
        self.temperature_warehouse = Factory.getTemper("MCP9808-I2C", 0x19)
        self.temperature_warehouse.resolution(Temper.RES_1_16_CELSIUS)
        print('starting OPC server ')
        self.opc_server = Server(shelffile="/home/pi/grove-opc-server")
        # shelffile is trick with freeopcua to speedup loading of xml object base
        self.opc_url = "opc.tcp://0.0.0.0:4840"
        self.opc_server.set_endpoint(self.opc_url)

        print('starting OPC server ..')
        self.opc_name = "Grove-opcua-server"
        self.addspace = self.opc_server.register_namespace(self.opc_name)
        print('starting OPC server ...')

        self.opc_node = self.opc_server.get_objects_node()
        self.param = self.opc_node.add_object(self.addspace, "Parameters")

        self.opc_time = self.param.add_variable(self.addspace, "Time", 0)
        self.opc_trigger = self.param.add_variable(self.addspace, "Trigger", 0)
        self.opc_warehouse_state = self.param.add_variable(
            self.addspace, "Warehouse state", 0)
        self.opc_door_outside = self.param.add_variable(
            self.addspace, "Outside door", 0)
        self.opc_door_inside = self.param.add_variable(self.addspace,
                                                       "Inside door", 0)
        self.opc_temperature_d = self.param.add_variable(
            self.addspace, "Temperature doorlock", 0.0)
        self.opc_temperature_w = self.param.add_variable(
            self.addspace, "Temperature warehouse", 0.0)

        self.opc_time.set_read_only()
        self.opc_trigger.set_read_only()
        self.opc_warehouse_state.set_read_only()
        self.opc_door_outside.set_read_only()
        self.opc_door_inside.set_read_only()
        self.opc_temperature_d.set_read_only()
        self.opc_temperature_w.set_read_only()

        print('starting OPC server .....')
        self.opc_server.start()
        print("OPC UA Server started at {}".format(self.opc_url))
        print("time      Doors Warehouse (Celsius)")
Exemple #24
0
import sys
import time

from grove.factory import Factory
from grove.grove_relay import GroveRelay
from grove.adc import ADC
from statistics import mean

PIN = 22  # relay PIN
relay = GroveRelay(PIN)
adc = ADC()
print("name: {0:20}, version: {1:4}".format(adc.name, adc.version))

# LCD 16x2 Characters
# lcd = Factory.getDisplay("JHD1802")
lcd = Factory.getLcd("JHD1802")
rows, cols = lcd.size()
print("LCD model: {}".format(lcd.name))
print("LCD type : {} x {}".format(cols, rows))
lcd.setCursor(0, 0)

# ph = (voltage - b)/a
a = (2.5 - 3.0) / (7.0 - 4.01)
b = 2.5 - a * 7.0
offset = 0.0283
n = 1000

# ds18b20 sensor id
_serialnum = "28-00000b702a1d"

try:
Exemple #25
0
import bluetooth
import datetime
import psutil
from influxdb import InfluxDBClient

vacio = False

# influx configuration - edit these
ifuser = "******"
ifpass = "******"
ifdb = "proyecto"
ifhost = "grupo15"
ifport = 8086
measurement_name = "system"

magnet = Factory.getGpioWrapper("Electromagnet", 12)
switch = GroveSwitch(18)
button = GroveButton(5)


def on_press(t):
    if (switch.state):
        magnet.off()
        print("Electromagnet apagado")
    else:
        magnet.on()
        global vacio
        vacio = False
        print("Electromagnet encendido")

Exemple #26
0
 def __init__(self):
     self.btn = Factory.getButton("I2C", 0)
     self.__on_event = None
     self.btn.on_event(self, GroveMultiSwitch.__handle_event)
Exemple #27
0
door_1_state = False
door_2_state = False


def main():

    global main_state, door_1_state, door_2_state

    main_button = GroveLedButton(5)
    door_1_button = GroveLedButton(18)
    door_2_button = GroveLedButton(16)
    main_relay = GroveRelay(22)
     door_1_relay = GroveRelay(26)
    door_2_relay = GroveRelay(24)

    sensor_d = Factory.getTemper("MCP9808-I2C", 0x18)
    sensor_d.resolution(Temper.RES_1_16_CELSIUS)
    sensor_w = Factory.getTemper("MCP9808-I2C", 0x19)
    sensor_w.resolution(Temper.RES_1_16_CELSIUS)

    print('Time Temp.: door & warehouse (C)')

    def on_press_main():
        global main_state, door_1_state, door_2_state
        if main_state:
            main_state = False
            door_1_state = False
            door_2_state = False
            main_relay.off()
            door_1_relay.off()
            door_2_relay.off()
Exemple #28
0
 def __init__(self, pin):
     self.__tmp = Factory.getTemper("NTC-ADC", pin)
Exemple #29
0
import time
from grove.factory import Factory

# LCD 16x2 Characters
lcd = Factory.getDisplay("JHD1802")
rows, cols = lcd.size()
print("LCD model: {}".format(lcd.name))
print("LCD type : {} x {}".format(cols, rows))

lcd.setCursor(0, 0)
lcd.write("hello world!")
lcd.setCursor(0, cols - 1)
lcd.write('X')
lcd.setCursor(rows - 1, 0)
for i in range(cols):
    lcd.write(chr(ord('A') + i))

time.sleep(3)
lcd.clear()
Exemple #30
0
import time
from grove.factory import Factory
from grove_button import GroveButton
import bluetooth
buttonNotPressed = False
buzzer = Factory.getGpioWrapper("Buzzer", 12)
button = GroveButton(5)


def on_press(t):
    global buttonNotPressed
    if (buttonNotPressed):
        buttonNotPressed = False
        client.send("Abre")
    else:
        print(
            "El frigorifico no esta listo para ser avierto. Espere a que su avisador suene"
        )


button.on_press = on_press


def on_bluetooth():
    global buttonNotPressed
    buzzer.on()
    time.sleep(1)
    buttonNotPressed = True
    while buttonNotPressed:
        time.sleep(1)
        print("Sleep")