def main(): # Instantiate a Grove Moisture sensor on analog pin A0 myMoisture = upmMoisture.GroveMoisture(0) ## 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 myMoisture def exitHandler(): print "Exiting" sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) # Values (approximate): # 0-300, sensor in air or dry soil # 300-600, sensor in humid soil # 600+, sensor in wet soil or submerged in water # Read the value every second and print the corresponding moisture level while(1): moisture_val = myMoisture.value() if (moisture_val >= 0 and moisture_val < 300): result = "Dry" elif (moisture_val >= 300 and moisture_val < 600): result = "Moist" else: result = "Wet" print "Moisture value: {0}, {1}".format(moisture_val, result) time.sleep(1)
import requests from iot_utils import * __author__ = 'KT Kirk' """ Send sensor one time, uses with hssi_iot.service """ # Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS) myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62) myLcd.setColor(53, 39, 249) # Blue myLcd.setCursor(0,0) myLcd.write('IoT') # Instantiate a Grove Moisture sensor on analog pin A1 moisture = upmMoisture.GroveMoisture(1) # Create the light sensor object using AI2 pin 2 light = grove.GroveLight(2) # Instantiate a UV sensor on analog pin A3 uv = upmUV.GUVAS12D(3); # analog voltage, usually 3.3 or 5.0 GUVAS12D_AREF = 5.0; SAMPLES_PER_QUERY = 1024; # Create the temperature sensor object using AIO pin 0 i2c_th = th02.TH02() # p = Phant(keys["publicKey"],
#!/usr/bin/python import time, sys, signal, atexit, mraa, thread, threading, os import pyupm_grove as grove import pyupm_guvas12d as upmUV import pyupm_grovemoisture as upmMoisture import pyupm_stepmotor as mylib import pyupm_servo as servo from multiprocessing import Process # IO Def myIRProximity = mraa.Aio(5) #GP2Y0A on Analog pin 5 temp = grove.GroveTemp(0) #grove temperature on A0 myMoisture = upmMoisture.GroveMoisture(1) #Moisture sensor on A1 light = grove.GroveLight(2) #Light sensor on A2 myUVSensor = upmUV.GUVAS12D(3) #UV sensor on A3 stepperX = mylib.StepMotor(2, 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) 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
import time, sys, signal, atexit import pyupm_grovemoisture as upmMoisture # Instantiate a Grove Moisture sensor on analog pin A0 myMoisture = upmMoisture.GroveMoisture(0) ## 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 myMoisture def exitHandler(): print "Exiting" sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) # Values (approximate): # 0-300, sensor in air or dry soil # 300-600, sensor in humid soil # 600+, sensor in wet soil or submerged in water # Read the value every second and print the corresponding moisture level while (1): moisture_val = myMoisture.value()