def main(): # Create the relay switch object using GPIO pin 0 relay = grove.GroveRelay(0) # Close and then open the relay switch 3 times, # waiting one second each time. The LED on the relay switch # will light up when the switch is on (closed). # The switch will also make a noise between transitions. for i in range(0, 3): relay.on() if relay.isOn(): print relay.name(), 'is on' time.sleep(1) relay.off() if relay.isOff(): print relay.name(), 'is off' time.sleep(1) # Delete the relay switch object del relay
credentials.read(credentialsfile) controlmode = 1 Angle = 0 # Create the button object usind D3 button = grove.GroveButton(3) # Create the servo object using D6 gServo = servo.ES08A(6) # Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS) myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62) # Create the light sensor object using AIO pin 2 light = grove.GroveLight(2) # Create the temperature sensor object using AIO pin 2 #temp = grove.GroveTemp(2) # Create relay object using D5 relay = grove.GroveRelay(5) # Initialize TH02 temperature sensor at 0x40 gTemp = temp.TH02(0, 0x40) # Initialize servo to 0 degrees gServo.setAngle(Angle) def functionLight(bot, update): luxes = light.value() bot.sendMessage(update.message.chat_id, text='Room Light: ' + str(luxes) + ' luxes') def functionTemperature(bot, update): temperature = gTemp.getTemperature()
def getRelay(self, pin=5): if self.relay is None: # Create the relay switch object using GPIO pin 5 default self.relay = grove.GroveRelay(pin) return self.getProxyObject(self.relay)
#!/usr/bin/python # ========== * IMPORT SECTION * ========== # # UPM Modules import pyupm_i2clcd as lcd import pyupm_grove as g from time import sleep # BT Needed Modules import spp as s # ========= * SETTING UP GPIOS * ========= # light = g.GroveLight(0) # Light sensor is connected to slot A0 display = lcd.Jhd1313m1(0, 0x3E, 0x62) # LCD goes on any I2C slot relay = g.GroveRelay(4) # Relay module is connected to slot D4 # ========= * PROJECT FUNCTIONS * ======== # # ------------ LCD Functions ------------- # # Display light sensor data def displayLightInfo(): display.clear() # Clear LCD display.setCursor(0, 0) # Set LCD cursor position (top left corner) display.write('Light:%s' % str(light.value())) # Display light sensor data sleep(1) # Display message on LCD
#!/usr/bin/python # http://iotdk.intel.com/docs/master/upm/classupm_1_1_grove_button.html # http://iotdk.intel.com/docs/master/upm/classupm_1_1_grove_relay.html import os import time from threading import Thread import pyupm_grove as grove curtainup = grove.GroveRelay(2) curtaindown = grove.GroveRelay(3) sensorup = grove.GroveButton(8) sensordown = grove.GroveButton(7) commandup = grove.GroveButton(6) commanddown = grove.GroveButton(5) curtainstatus = 'Stopped' def SystemStatus(): while True: #os.system('clear') print 'Curtain Up: ' + str(curtainup.isOn()) print 'Curtain Down: ' + str(curtaindown.isOn()) print 'Sensor Up: ' + str(sensorup.value()) print 'Sensor Down: ' + str(sensordown.value()) print '' print 'Curtain Status: ' + curtainstatus time.sleep(.5)
#!/usr/bin/python import pyupm_grove as g import pyupm_i2clcd as lcd from time import sleep light = g.GroveLight(0) display = lcd.Jhd1313m1(0, 0x3E, 0x62) relay = g.GroveRelay(4) watering = 0 already_watered = 0 def displayLight(): if light.value() <= 20: display.setColor(255, 0, 0) elif light.value() in range(21, 29): display.setColor(255, 255, 0) elif light.value() >= 30: display.setColor(0, 255, 0) def function(data): func = functionInUse.get(data, dummy) func() def dummy(): pass
import dweepy import pyupm_grove as grove from plotly.graph_objs import Scatter, Layout, Figure from threading import Thread from flask import Flask from flask_restful import Api, Resource username = '******' api_key = 's2s780r8rl' stream_token = '09wwi43qla' bar0 = "**************************************************************" bar1 = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" bar2 = "==============================================================" relay1 = grove.GroveRelay(2) p = 0 stream = py.Stream(stream_token) idDevice = "None" message = "Empty message..." data = {} myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62) myLcd.setCursor(0, 0) myLcd.setColor(255, 0, 0) myLcd.setCursor(0, 0) myLcd.write(' Starting...') myLcd.setCursor(1, 0) myLcd.write(' Please Wait...') app = Flask(__name__)
if (mode == 0): mode = 1 else: mode = 0 ################################################################################### ##### Inicializacao dos sensores, atuadores e variaveis utilizadas no sistema ##### ################################################################################### # Inicializacao do LCD lcd = upmlcd.Jhd1313m1(0, 0x3E, 0x62) lcd.setColor(0, 0, 0) # Inicializacao do rele relay = pyupm_grove.GroveRelay(6) # Inicializacao do sensor de luz como uma entrada analogica lightSensor = mraa.Aio(3) # Inicializacao do painel solar como uma entrada analogica solarPanel = mraa.Aio(0) # Inicializacao do botao como uma entrada digital, que tem uma interrupcao associada button = mraa.Gpio(4) button.dir(mraa.DIR_IN) button.isr(mraa.EDGE_FALLING, buttonISR, buttonISR) # Inicializacao do motor de passo stepper = upmstepper.ULN200XA(96, 8, 9, 10, 11) stepper.setSpeed(30) #30 rpm