예제 #1
0
def readCompoundEye():
    global irUpValue, irDownValue, irLeftValue, irRightValue, distance  # <4>
    ledPin = 25
    gpio.mode(ledPin, "out")  # <5>
    gpio.write(ledPin, gpio.HIGH)
    #Wait for sensors to get ready
    time.sleep(0.05)  # <6>

    irUpValue = mcp.readAnalog(0, 0)  # <7>
    irDownValue = mcp.readAnalog(1, 0)
    irLeftValue = mcp.readAnalog(0, 1)
    irRightValue = mcp.readAnalog(1, 1)

    ambientLight = 0
    gpio.write(ledPin, gpio.LOW)  # <8>
    time.sleep(0.05)
    ambientLight = mcp.readAnalog(0, 0)  # <8>
    irUpValue = irUpValue - ambientLight  # <9>
    ambientLight = mcp.readAnalog(1, 0)  # <10>
    irDownValue = irDownValue - ambientLight
    ambientLight = mcp.readAnalog(0, 1)
    irLeftValue = irLeftValue - ambientLight
    ambientLight = mcp.readAnalog(1, 1)
    irRightValue = irRightValue - ambientLight

    distance = (irUpValue + irDownValue + irLeftValue +
                irRightValue) / 4  # <11>
예제 #2
0
def readCompoundEye():
	global irUpValue,irDownValue,irLeftValue,irRightValue,distance	# <4>
	ledPin = 25	
	gpio.mode(ledPin, "out")	# <5>
	gpio.write(ledPin, gpio.HIGH)
	#Wait for sensors to get ready
	time.sleep(0.05)	# <6>
	
	irUpValue = mcp.readAnalog(0, 0)	# <7>
	irDownValue = mcp.readAnalog(1, 0)
	irLeftValue = mcp.readAnalog(0, 1)
	irRightValue = mcp.readAnalog(1, 1)
	
	ambientLight = 0
	gpio.write(ledPin, gpio.LOW)	# <8>
	time.sleep(0.05)
	ambientLight = mcp.readAnalog(0, 0)	# <8>
	irUpValue = irUpValue - ambientLight	# <9>
	ambientLight = mcp.readAnalog(1, 0)	# <10>
	irDownValue = irDownValue - ambientLight
	ambientLight = mcp.readAnalog(0, 1)
	irLeftValue = irLeftValue - ambientLight
	ambientLight = mcp.readAnalog(1, 1)
	irRightValue = irRightValue - ambientLight
	
	distance = (irUpValue+irDownValue+irLeftValue+irRightValue)/4	# <11>	
예제 #3
0
def main():
	initializeColorSensor()
	while True:	# <4>
		redValue = mcp.readAnalog(0, 0)
		greenValue = mcp.readAnalog(0, 1)
		blueValue = mcp.readAnalog(1, 0)	# <5>

		redValue = redValue * 10 / 1.0;	# <6>
		greenValue = greenValue * 10 / 0.75;
		blueValue = blueValue * 10 / 0.55;

		print("R: %d, G: %d, B: %d" % (redValue,greenValue,blueValue))	# <7>

		time.sleep(0.1)	# s
예제 #4
0
def main():
    initializeColorSensor()
    while True:  # <4>
        redValue = mcp.readAnalog(0, 0)
        greenValue = mcp.readAnalog(0, 1)
        blueValue = mcp.readAnalog(1, 0)  # <5>

        redValue = redValue * 10 / 1.0
        # <6>
        greenValue = greenValue * 10 / 0.75
        blueValue = blueValue * 10 / 0.55

        print("R: %d, G: %d, B: %d" % (redValue, greenValue, blueValue))  # <7>

        time.sleep(0.1)  # s
예제 #5
0
def main():
    while True:
        smokeLevel = mcp.readAnalog(0,0)
        print("Current smoke level is %i " % smokeLevel)
        if smokeLevel > 120:
            print("Smoke detected")
            dweepy.dweet_for('sensorgas_viro', {'Estat':'Gas detectat'})
        time.sleep(5)
예제 #6
0
def main():
    while True:
        rawData = mcp.readAnalog()  # <2>
        percent = rawData / 1023.0  # <3>
        volts = percent * 3.3  # <4>
        temperature = 100.0 * volts  # <5>
        print("Current temperature is %.1f C " % temperature)
        time.sleep(0.5)
def main():
	while True:
		rawData = mcp.readAnalog()	# <2>
		percent = rawData / 1023.0	# <3>
		volts = percent * 3.3 	# <4>
		temperature = 100.0 * volts	# <5>
		print("Current temperature is %.1f C " % temperature)
		time.sleep(0.5)	
예제 #8
0
def main():
	while True:
		smokeLevel = mcp.readAnalog()
		print("Current smoke level is %i " % smokeLevel)
		if smokeLevel > 120:
			print("Smoke detected")
			sendEmail("Smoke","Smoke level was %i" % smokeLevel) # <17>
			time.sleep(gracePeriod)	# <18>
		time.sleep(0.5) # s	# <19>
예제 #9
0
def main():
    while True:
        smokeLevel = mcp.readAnalog()
        print("Current smoke level is %i " % smokeLevel)
        if smokeLevel > 120:
            print("Smoke detected")
            sendEmail("Smoke", "Smoke level was %i" % smokeLevel)  # <17>
            time.sleep(gracePeriod)  # <18>
        time.sleep(0.5)  # s	# <19>
예제 #10
0
    def startDev(self):
        '''
		Start capturing LPG gas detection
		'''
        print "[INFO] Start LPG detection"
        index = 0
        avgGasLevel = 0
        try:
            while True:
                self.gasLevel = mcp.readAnalog()
                self.gasLevel = self.gasLevel * 10  #Mapping 0-1000 to 0-10000
                print "Gas Level: " + str(self.gasLevel)
                if ((self.gasLevel > self.halfThreshold) and
                    (self.powerMode
                     == 0)):  #Second condition avoids lot of function calls
                    self.setPowerMode(1)

                if ((self.gasLevel <= self.halfThreshold) and
                    (self.powerMode
                     == 1)):  #Second condition avoids lot of function calls
                    self.setPowerMode(0)

                #Fill moving window
                if (len(self.mvWindow) < self.mvWindowSize):
                    self.mvWindow.append(self.gasLevel)
                    index += 1
                #Get Moving average
                else:
                    self.mvWindow[index % self.mvWindowSize] = self.gasLevel
                    avgGasLevel = int(
                        sum(self.mvWindow) / float(len(self.mvWindow)) +
                        0.5)  #Round off
                    index += 1

                #Moving average greater than thershold, notify
                if (avgGasLevel > self.threshold and not self.alertStatus
                    ):  #Second condition avoids lot of function call
                    self.setAlert(True)

                elif (avgGasLevel <= self.threshold and self.alertStatus
                      ):  #Second condition avoids lot of function call
                    self.setAlert(False)

                #Gas level crossed threshold and no notification sent to device
                if (avgGasLevel > self.threshold and not self.notifyStatus):
                    self.notifyStatus = self.notifyDevice(
                        avgGasLevel, self.productcode, self.hostname)

                self.sendData(avgGasLevel, self.productcode, self.hostname)

                time.sleep(self.currSampleRate)

        except Exception:
            traceback.print_exc()
        finally:
            self.cleanupDev()
예제 #11
0
def main():
    while True:
        rawMagneticStrength = mcp.readAnalog()
        print("Raw strength:  %i " % rawMagneticStrength)
        zeroedStrength = rawMagneticStrength - zeroLevel
        print("Zeroed strength: %i " % zeroedStrength)
        if (zeroedStrength > 0):
            print("South pole")
        elif (zeroedStrength < 0):
            print("North pole")
        time.sleep(0.5)
예제 #12
0
def main():
  while True:	
 	rawMagneticStrength = mcp.readAnalog()
	print("Raw strength:  %i " % rawMagneticStrength)	
	zeroedStrength = rawMagneticStrength - zeroLevel
	print("Zeroed strength: %i " % zeroedStrength)	
	if(zeroedStrength > 0):
		print("South pole") 
	elif(zeroedStrength < 0):
		print("North pole") 
	time.sleep(0.5) 
예제 #13
0
	def startDev(self):
		'''
		Start capturing LPG gas detection
		'''
		print "[INFO] Start LPG detection"
		index = 0
		avgGasLevel = 0
		try:
			while True:
				self.gasLevel = mcp.readAnalog()
				self.gasLevel = self.gasLevel * 10 #Mapping 0-1000 to 0-10000
				print "Gas Level: "+str(self.gasLevel)
				if((self.gasLevel > self.halfThreshold) and (self.powerMode==0)): #Second condition avoids lot of function calls
					self.setPowerMode(1)

				if((self.gasLevel <= self.halfThreshold) and (self.powerMode==1)): #Second condition avoids lot of function calls
					self.setPowerMode(0)

				#Fill moving window
				if(len(self.mvWindow)<self.mvWindowSize):
					self.mvWindow.append(self.gasLevel)
					index+=1
				#Get Moving average
				else:
					self.mvWindow[index%self.mvWindowSize] = self.gasLevel
					avgGasLevel = int(sum(self.mvWindow)/float(len(self.mvWindow))+0.5) #Round off
					index+=1

				#Moving average greater than thershold, notify
				if (avgGasLevel > self.threshold and not self.alertStatus): #Second condition avoids lot of function call
					self.setAlert(True)

				elif (avgGasLevel <= self.threshold and self.alertStatus): #Second condition avoids lot of function call
					self.setAlert(False)

				#Gas level crossed threshold and no notification sent to device
				if(avgGasLevel > self.threshold and not self.notifyStatus):
					self.notifyStatus = self.notifyDevice(avgGasLevel,self.productcode,self.hostname)

				self.sendData(avgGasLevel,self.productcode,self.hostname)

				time.sleep(self.currSampleRate)

		except Exception:
			traceback.print_exc()
		finally:
			self.cleanupDev()
예제 #14
0
def readFlexiForce():
    return mcp.readAnalog()  # <2>
예제 #15
0
def readVoltage():
    raw = mcp.readAnalog(0, 1)  # <2>
    percent = raw / 1023.0  # <3>
    volts = percent * 3.3  # <4>
    sensedVolts = volts * 13.6 / 3.3  # V/V	# <5>
    return sensedVolts  # V
예제 #16
0
def readSound(samples):
	buff = []	# <2>
	for i in range(samples):	# <3>
		buff.append(mcp.readAnalog())	# <4>
	return buff
예제 #17
0
def readAlcoholLevel():
    return mcp.readAnalog()
예제 #18
0
def readTemperature():
    data = mcp.readAnalog(0, 0)
    percent = data / 1023.0
    volts = percent * 3.3
    celcius = 100.0 * volts
    return celcius
예제 #19
0
def readX():	# <3>
	return mcp.readAnalog(0, 0)
#Raspberry Pi Potentiometer Circuit Code
import RPi.GPIO as GPIO
import botbook_mcp3002 as mcp
import time

LED = 40
lightvalue = 0

minMoisture = 200

GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED, GPIO.OUT)

    
while True:
    moisturevalue = mcp.readAnalog(0,1)
    print "Moisture = ", moisturevalue
    time.sleep( 0.2)
    if (moisturevalue <= minMoisture):
        GPIO.output(LED, GPIO.HIGH)
    elif (moisturevalue > minMoisture):
        GPIO.output(LED, GPIO.LOW)
예제 #21
0
def readFlexiForce():
	return mcp.readAnalog()	# <2>
nodeID = " Tal001 ";

delayDB = 5 #double parking threshold time
delayTR = 8 # traffic threshold time

captime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") #capture time, get date and time when picture have been token

tweetStr = "Double parking at ", nodeID + captime # sentence contatining node id and capture time

execfile("azm_keys.py") # twitter app passwords contains C_KEY,C_SECRET,A_TOKEN,A_SECRET

api = Twython(C_KEY,C_SECRET,A_TOKEN,A_SECRET) # set twitter app passwords 

while True:
    lightval = mcp.readAnalog() # read light sensor
    
    captime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    
    tweetStr = ("Double parking at ", nodeID + captime) 

    GPIO.output(TRIG, False)
    time.sleep(0.3)
    GPIO.output(TRIG, True)
    time.sleep(0.001)
    GPIO.output(TRIG, False)
    
    while GPIO.input(ECHO)==0:
        signalOff = time.time()
    while GPIO.input(ECHO)==1:
        signalOn = time.time()
def main():
	while True:
		h = mcp.readAnalog()	# <1>
		h = h / 1024 * 100	# <2>
		print("Current humidity is %d %%" % h)
		time.sleep(5) 
예제 #24
0
def readTemperature():  # <3>
    data = mcp.readAnalog(0, 0)  # <4>
    percent = data / 1023.0  # <5>
    volts = percent * 3.3  # <6>
    celcius = 100.0 * volts  # <7>
    return celcius  # <8>
예제 #25
0
def main():
    while True:
        lightLevel = mcp.readAnalog()
        print("Current light level is %i " % lightLevel)
        time.sleep(0.5)
def readPotent():

	global gasValue 
	gasValue = mcp.readAnalog() # read gas information from mcp-3002 
예제 #27
0
def main():
	while True:
		h = mcp.readAnalog()	# <1>
		h = h / 1024 * 100	# <2>
		print("Current humidity is %d %%" % h)
		time.sleep(5) 
import sys
from twython import Twython
import RPi.GPIO as GPIO

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

execfile("azm_keys.py") # execute file containing AzmRpi twitter app secret passwords
api = Twython(C_KEY,C_SECRET,A_TOKEN,A_SECRET)

Pump = 40 # pump pin
FlameValue = 0

GPIO.setup(Pump, GPIO.OUT) # set pump pin as an output pin

FlameValue = mcp.readAnalog(0,1) # read flame sensor value

DT = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") # get date and time

TweetStatus = 'Fire detected at TAL001, ' + str(DT) # twitter status sentence including date time

while True:
    
    DT = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") # get date and time
    
    TweetStatus = 'Fire detected at TAL001, ' + str(DT) # twitter status sentence including date time
    
    MoistureValue = mcp.readAnalog(0,0) # read moisture sensor value
    FlameValue = mcp.readAnalog(0,1) # read flame sensor value
    
    print "Moisture = ", MoistureValue
예제 #29
0
def readY():
	return mcp.readAnalog(0, 1)	# <4>
#Raspberry Pi Potentiometer Circuit Code
import RPi.GPIO as GPIO
import botbook_mcp3002 as mcp
import time

LED = 40
lightvalue = 0

GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED, GPIO.OUT)

    
while True:
    lightvalue = mcp.readAnalog(0,0)
    gasValue = mcp.readAnalog(0,1)
    print "LightValue = ", lightvalue, "CO Gas Value= ", gasValue
    time.sleep( 0.2)
    if (lightvalue <=700):
        GPIO.output(LED, GPIO.HIGH)
    elif (lightvalue >700):
        GPIO.output(LED, GPIO.LOW)
def readAlcoholLevel():
  return mcp.readAnalog()
예제 #32
0
파일: xy_joystick.py 프로젝트: upyy/xiaoche
def readX():  # <3>
    return mcp.readAnalog(0, 0)
예제 #33
0
def readSmokeLevel():
    global smokeLevel
    smokeLevel = mcp.readAnalog()
예제 #34
0
def main():
	while True:
		lightLevel = mcp.readAnalog()
		print("Current light level is %i " % lightLevel)
		time.sleep(0.5)	
예제 #35
0
#!/usr/bin/python

# pot_repeat.py - continuously measure resistance of a potentiometer
# (c) BotBook.com - Karvinen, Karvinen, Valtokari
# from the book getting started with sensors

# read and convert values between 0 and 1023 (10 bits)

import botbook_mcp3002 as mcp	# <1>
import time	# <2>

while(True):	# <3>
	x = mcp.readAnalog(0,0)	# <4>
	print(x)	# <5>
	time.sleep(0.5)	# seconds	# <6>

예제 #36
0
def readPotentiometer():
    global potentiometer
    potentiometer = mcp.readAnalog()  #
예제 #37
0
파일: xy_joystick.py 프로젝트: upyy/xiaoche
def readY():
    return mcp.readAnalog(0, 1)  # <4>
예제 #38
0
def readCurrent():
    raw = mcp.readAnalog(0, 0)
    percent = raw / 1023.0
    volts = percent * 3.3
    sensedCurrent = volts * 45.0 / 3.3  # A/V # <6>
    return sensedCurrent  # A
예제 #39
0
	def writeSensor(self,fileH):
		x = str(mcp.readAnalog(0,0))	# <2>
		ts = str(time.time())
		print(x+","+ts+","+"0",file=fileH)
		print (x+","+ts)
		return x
def readSmokeLevel():
	global smokeLevel
	smokeLevel = mcp.readAnalog()	# <2>