def __init__(self): self.client = paho.Client() self.client.on_publish = self.on_publish self.client.connect("test.mosquitto.org", 1883, 60) self.button = grove.GroveButton(2) self.temp = grove.GroveTemp(0)
def main(): # Create the button object using GPIO pin 0 button = grove.GroveButton(0) # Read the input and print, waiting one second between readings while 1: print button.name(), ' value is ', button.value() time.sleep(1) # Delete the button object del button
def setup_devices(): from libs.smarty import config_buzzer, config_accelerometer from libs.lcd_display import config_lcd global myBuzzer global myDigitalAccelerometer global myLcd global myButton if (prefs.getboolean("defaults", "buzzer_en")): myBuzzer = config_buzzer() myDigitalAccelerometer = config_accelerometer() if (prefs.getboolean("defaults", "lcd_en")): myLcd = config_lcd() myButton = grove.GroveButton(7) return
# included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from __future__ import print_function import time import pyupm_grove as grove import pyupm_grovespeaker as upmGrovespeaker # Create the button object using GPIO pin 0 button = grove.GroveButton(0) # Instantiate a Grove Speaker on digital pin D4 mySpeaker = upmGrovespeaker.GroveSpeaker(4) # Read the input and print, waiting one second between readings while 1: print("{} value is {}".format(button.name(), button.value())) if button.value(): mySpeaker.playSound('c', True, "med") time.sleep(1) # Delete the button object del button
waterpump = mraa.Gpio(10) #Water pump's Relay on GPIO 10 waterpump.dir(mraa.DIR_OUT) waterpump.write(0) gServo = servo.ES08A(6) #Servo object using D6 gServo.setAngle(50) switchY = mraa.Gpio(7) #SwitchY for GPIO 7 switchY.dir(mraa.DIR_IN) switchX = mraa.Gpio(8) #SwitchX for GPIO 8 switchX.dir(mraa.DIR_IN) EnableStepperX = mraa.Gpio(9) #StepperMotorX Enable on GPIO 9 EnableStepperX.dir(mraa.DIR_OUT) EnableStepperX.write(1) EnableStepperY = mraa.Gpio(11) #StepperMotorY Enable on GPIO 11 EnableStepperY.dir(mraa.DIR_OUT) EnableStepperY.write(1) button = grove.GroveButton(0) #Digital Button on D0 plant_number = 8 plant_positionX = [267,801,1335] plant_positionY = [350,1050,1750] stepperX.setSpeed(150) stepperY.setSpeed(150) EnableStepperX.write(0) EnableStepperY.write(0) '''while(switchX.read()): stepperX.stepForward(80) time.sleep(0.3) while(switchY.read()): stepperY.stepBackward(80) time.sleep(0.3)
def getButton(self, pin=0): if self.button is None: # Create the button object using GPIO pin 1 self.button = grove.GroveButton(pin) return self.getProxyObject(self.button)
#!/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)
# ---------- GROVE PUSH BUTTON ---------- # # Basic sample using UPM module for the # # Grove push button v1.1 # # Daniela Plascencia | [email protected] # import pyupm_grove as g from time import sleep if __name__ == '__main__': bttn = g.GroveButton(4) # Instance the button and # sets it in digital input 4 # The status of the button is retrieved # and then printed on screeen while True: if bttn.value(): print 'Button is pressed' else: print 'Button is not pressed' sleep(1.0)
import pyupm_i2clcd as lcd # Pins used in Grove kit. PILL_BUTTON = 2 # Response codes. SUCCESS_CODE = "OK" # Configuration values. PILL_TIMER_LIMIT = 5 # in seconds LCD_BACKGROUND_COLOR = (50, 50, 100) # in RGB decimal values LCD_BACKGROUND_ALERT_COLOR = (255, 0, 0) # in RGB decimal values # Initialize your devices. display = lcd.Jhd1313m1(0, 0x3E, 0x62) pill_button = grove.GroveButton(PILL_BUTTON) # Initialize flags. initialized = False pill_counter = 0 pill_is_due = False pill_button_released = True # Initialize variables. timer = None def displayInit(color): display.setColor(*color) display.clear()
3) #StepMotorY object on pins 2 (dir) and 3 (step) stepperY = mylib.StepMotor(4, 5) #StepMotorX object on pins 4 (dir) and 5 (step) waterpump = mraa.Gpio(10) #Water pump's Relay on GPIO 10 waterpump.dir(mraa.DIR_OUT) waterpump.write(0) gServo = servo.ES08A(6) #Servo object using D6 gServo.setAngle(50) switchY = mraa.Gpio(7) #SwitchY for GPIO 7 switchY.dir(mraa.DIR_IN) switchX = mraa.Gpio(8) #SwitchX for GPIO 8 switchX.dir(mraa.DIR_IN) EnableStepper = mraa.Gpio(9) #StepperMotor Enable on GPIO 9 EnableStepper.dir(mraa.DIR_OUT) EnableStepper.write(0) button = grove.GroveButton(0) #Digital Button on D0 -> ## button.value() # Variable Def AREF = 5.0 SAMPLES_PER_QUERY = 1024 flag = 1 # Defined all 5 Sensors UVvalue = myUVSensor.value( AREF, SAMPLES_PER_QUERY) #Voltage value (higher means more UV) Lightvalue = light.value() # in lux Distancevalue = float(myIRProximity.read( )) * AREF / SAMPLES_PER_QUERY #Distance in Voltage (higher mean closer) Soilvalue = myMoisture.value() # 0-300 Dry, 300-600 Most, <600 Wet Tempvalue = temp.value() # Celsius
import time import pyupm_grove as grove import pyupm_i2clcd as lcd from socketIO_client import SocketIO, BaseNamespace class SensorNamespace(BaseNamespace): def on_connect(self): print('[Connected]') socketIO = SocketIO('antoniohernandez.me', 8000) sensor_socket = socketIO.define(SensorNamespace, '/sensor') # Create the buttons buttonInp = grove.GroveButton(3) buttonInp2 = grove.GroveButton(7) buttonOut = grove.GroveButton(4) buttonOut2 = grove.GroveButton(8) available = capacity = 21 bandera=True # Initialize Jhd1313m1 at 0x3E (Lcd address) myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62) # RGB Blue myLcd.setColor(255, 55, 0) # Read the input and print, waiting one second between readings while 1: if buttonInp.value() == 1 or buttonInp2==1: available= available - 1 if available<0: sensor_socket.emit('signal', {'area' : 'A', 'availability' :
def get_actuator(self): return pyupm_grove.GroveButton(self.pin)
import time import pyupm_grove as grove import pyupm_i2clcd as lcd from firebase import firebase import mraa firebase = firebase.FirebaseApplication('https://letsparkiot.firebaseIO.com', None) button1 = grove.GroveButton(2) button2 = grove.GroveButton(6) id_zone = "A" #counter=int(firebase.get("/ITESM/General/"+id_zone+"/Capacity",None)) counter = [0, 0] counter[0] = counter[1] = firebase.get( "/Parking/ITESM/General/" + id_zone + "/Capacity", None) #firebase.put('/ITESM/General/'+id_zone,"Capacity",counter) myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62) myLcd.setCursor(0, 0) myLcd.write("Available : " + str(counter[0])) led_disp = mraa.Gpio(7) led_disp.dir(mraa.DIR_OUT)
import pyupm_ttp223 as ttp223 import pyupm_i2clcd as lcd import pyupm_mic as upmMicrophone import pyupm_buzzer as upmBuzzer from datetime import datetime as dt ###################### Setup devices ############################ chords = [upmBuzzer.DO, upmBuzzer.RE, upmBuzzer.MI, upmBuzzer.FA, upmBuzzer.SOL, upmBuzzer.LA, upmBuzzer.SI, upmBuzzer.DO, upmBuzzer.SI] # New knob on AIO pin 0 knob = grove.GroveRotary(0) # Create the touch object using D7 touch = grove.GroveButton(7) # Create the button object using D3 button = grove.GroveButton(3) # Attach microphone to analog port A3 myMic = upmMicrophone.Microphone(1) threshContext = upmMicrophone.thresholdContext() threshContext.averageReading = 100 threshContext.runningAverage = 200 threshContext.averagedOver = 1 # Infinite loop, ends when script is cancelled # Repeatedly, take a sample every 2 microseconds; # find the average of 128 samples; and # print a running graph of dots as averages
import mraa import pyupm_grove as grove import requests click_url = 'http://172.16.0.236:3000/trigger' pin_number = 8 # button = mraa.Gpio(pin_number) # button.dir(mraa.DIR_OUT) button = grove.GroveButton(pin_number) # last_state = button.read(pin_number) last_state = button.value() try: print 'last button state is :: ' + last_state except: print 'last button state is :: None' print 'start listen to button...' while (True): # sample = button.read(pin_number) sample = button.value() if sample != last_state: print 'A click was occurred!' last_state = sample try: requests.get(url=click_url)
# Instantiate a Servo motor on port D6 #myServo = Servo("First Servo") #myServo.attach(6) # Create the servo object using D6 gServo = servo.ES08A(6) # digital contact switch - SwitchX for GPIO 7 and SwitchY for GPIO 8 switchX = mraa.Gpio(7) # while switchX.read() == 1: switchX.dir(mraa.DIR_IN) switchY = mraa.Gpio(8) switchY.dir(mraa.DIR_IN) # Instantiate a StepperMotor Enable on GPIO 9 EnableStepper = mraa.Gpio(9) EnableStepper.dir(mraa.DIR_OUT) EnableStepper.write(1) # Create the button object using GPIO pin 0 button = grove.GroveButton(0) # Prefer use interupt -> ## button.value() # analog voltage, usually 3.3 or 5.0 for GUVAS12D AREF = 5.0 SAMPLES_PER_QUERY = 1024 ## Exit handlers ## # This function stops python from printing a stacktrace when you hit control-C def SIGINTHandler(signum, frame): raise SystemExit # This function lets you run code on exit, including functions from myUVSensor def exitHandler(): print "Exiting"
#depending on the amount of free spaces a color is chosen if count < total / 2: mylcd.setColor(0, 255, 0) elif count > total / 2 and count < (total - 5): mylcd.setColor(255, 255, 0) elif count > (total - 5): mylcd.setColor(255, 0, 0) #define the firebase database from which the program will be working firebase = firebase.FirebaseApplication('https://gubi.firebaseio.com', None) #count is equals to the property in the database "lugares" count = firebase.get('/ITESM/ZoneB/Busy', None) total = firebase.get('/ITESM/ZoneB/Total', None) #define the buttons connected to the intel edison button1 = grove.GroveButton(4) button2 = grove.GroveButton(3) button1b = grove.GroveButton(5) button2b = grove.GroveButton(6) #initialization of our variables check = True #to avoid measuring press and hold checkb = True #to avoid measuring press and hold pressed = False #this way we can determine if a button was already pressed same1 = False #in case the same button has been pressed same2 = False #in case the same button has been pressed pressedb = False #this way we can determine if a button was already pressed same1b = False #in case the same button has been pressed same2b = False #in case the same button has been pressed mylcd = lcd.Jhd1313m1(0, 0x3E, 0x62) #make mylcd reference the lcd screen connected
def on_signal(*args): global available global capacity available = args[0]['availability'] capacity = args[0]['capacity'] # Create the socketIO connection socketIO = SocketIO('antoniohernandez.me', 8000) sensor_socket = socketIO.define(SensorNamespace, '/sensor') sensor_socket.emit('initialize', {'area': sys.argv[1]}) sensor_socket.on('initialize', on_signal) socketIO.wait(seconds=2) # Create the buttons buttonInp = grove.GroveButton(8) buttonInp2 = grove.GroveButton(2) buttonOut = grove.GroveButton(5) buttonOut2 = grove.GroveButton(4) flag = True # Initialize Jhd1313m1 at 0x3E (Lcd address) myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62) # Waiting 0.5 second between readings while 1: # Change color of the LCD if available >= capacity * .3: myLcd.setColor(0, 255, 10) if available > 0 and available < capacity * .3:
def getButtonStatus(self): but = pyupm_grove.GroveButton(int(self.port)) butstatus = int(but.value()) self.info["button"] = butstatus return self.info