コード例 #1
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
コード例 #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():
	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)	
コード例 #4
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>
コード例 #5
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) 
コード例 #6
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()
コード例 #7
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
コード例 #8
0
def readPotent():

	global gasValue 
	gasValue = mcp.readAnalog() # read gas information from mcp-3002 
コード例 #9
0
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()
コード例 #10
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)
コード例 #11
0
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
コード例 #12
0
ファイル: pot_repeat.py プロジェクト: refap3/refAP3repo
#!/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>

コード例 #13
0
def readX():	# <3>
	return mcp.readAnalog(0, 0)
コード例 #14
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
コード例 #15
0
#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)
コード例 #16
0
ファイル: ldr.py プロジェクト: hackabletype/37-Sensors-Code
def main():
	while True:
		lightLevel = mcp.readAnalog()
		print("Current light level is %i " % lightLevel)
		time.sleep(0.5)	
コード例 #17
0
def readSmokeLevel():
	global smokeLevel
	smokeLevel = mcp.readAnalog()	# <2>
コード例 #18
0
def readY():
	return mcp.readAnalog(0, 1)	# <4>
コード例 #19
0
def main():
	while True:
		h = mcp.readAnalog()	# <1>
		h = h / 1024 * 100	# <2>
		print("Current humidity is %d %%" % h)
		time.sleep(5) 
コード例 #20
0
def readAlcoholLevel():
  return mcp.readAnalog()
コード例 #21
0
def readFlexiForce():
	return mcp.readAnalog()	# <2>
コード例 #22
0
def readSound(samples):
	buff = []	# <2>
	for i in range(samples):	# <3>
		buff.append(mcp.readAnalog())	# <4>
	return buff
コード例 #23
0
ファイル: pot_once.py プロジェクト: dragoto91/ProjectAutoma
	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