Exemple #1
0
def loop():
    while True:
        readSensors()
        res = ADC0832.getResult()
        moisture = 255 - res
        #        Msg2 = str('analog value: %03d moisture: %d' %(res, moisture))
        Msg2 = str('moisture %d' % (moisture))

        d = checkdist()
        df = "%0.2f" % d
        Msg3 = str('Distance %s' % df)

        res2 = ADC0832.getResult() - 80
        if res2 < 0:
            res2 = 0
        if res2 > 100:
            res2 = 100
#        print ('res2 = %d' % res2)
        Msg4 = ('Light %d' % res2)

        res3 = ADC0832.getResult()
        Gas_concentration = res3
        #        print ('analog value: %03d Gas concentration: %d' %(res3, Gas_concentration))
        Msg5 = str('Gas-concentration %d' % (Gas_concentration))
        #        d_time = datetime.datetime.now()
        d_date = datetime.datetime.now().date()
        d_time = datetime.datetime.now().time()
        d_time2 = d_time.strftime('%H:%M:%S')

        Msg6 = str(d_date) + ' ' + str(
            d_time2
        ) + ' ' + Msg + ' ' + Msg2 + ' ' + Msg3 + ' ' + Msg4 + ' ' + Msg5
        client.publish(Topic, Msg6)
        print(Msg6)
        time.sleep(360)
def setup():
	ADC0832.setup()				# Setup ADC0832
	GPIO.setmode(GPIO.BOARD)	# Numbers GPIOs by physical location
	GPIO.setup(btn, GPIO.IN, pull_up_down=GPIO.PUD_UP)	# Setup button pin as input an pull it up
	GPIO.add_event_detect(btn, GPIO.FALLING, callback=button_pressed, bouncetime=100)
	global state
	state = ['up', 'down', 'left', 'right']	
Exemple #3
0
def setup():
    GPIO.setmode(GPIO.BOARD)  #Number GPIOs by its physical location
    GPIO.setwarnings(False)
    for pin in pins:
        GPIO.setup(pin, GPIO.OUT)  #set all pins' mode is output
        GPIO.output(pin, GPIO.HIGH)  #set all pins are high level(3.3V)
    ADC0832.setup()
Exemple #4
0
def UserPickPattern():
        uArr = []
        ADC0832.setup()

        for x in range(4):
                    print"Move the red wire to your choice for the color in spot #",x+1," and press enter"
                    raw_input()
                    u = ADC0832.getResult()            #Get reading from ADC
                    if u > 248 and u < 252:
                        uArr.append(1)
                    elif u > 231 and u < 235:
                        uArr.append(2)
                    elif u > 126 and u < 130:
                        uArr.append(3)
                    elif u > 242 and u < 246:
                        uArr.append(4)
                    elif u > 211 and u < 215:
                        uArr.append(5)
                    elif u > 120 and u < 124:
                        uArr.append(6)
                    else:
                        uArr.append(0)
                    
        #print colored('0 ',colArr[uArr[0]]),colored('0 ',colArr[uArr[1]]),colored('0 ',colArr[uArr[2]]),colored('0 ',colArr[uArr[3]])
        return uArr            
Exemple #5
0
def init():
    ADC0832.setup()
    if ARG_DISPLAY == 1:
        print("")
        print("Analog Temperatur")
        print("")
        print("ADC")
        print("ADC		   RPI")
        print("---------------------------------------")
        print("Pin 1		-> Pin 11 (GPIO 17)")
        print("Pin 2		-> (+++Sensor+++)")
        print("Pin 3		-> (+++ ohne +++)")
        print("Pin 4		-> Pin 9  (GND)")
        print("Pin 5 (DI)	-> Pin 13 (GPIO 27)")
        print("Pin 6 (DO)	-> Pin 13 (GPIO 27)")
        print("Pin 7 (CLK)	-> Pin 12 (GPIO 18)")
        print("Pin 8 (VCC)	-> Pin 1  (3.3V)")
        print("")
        print("Sensor (beliebiger analoger Sensor")
        print("Sensor")
        print("---------------------------------------")
        print("Pin -		-> Pin 9  (GND)")
        print("Pin +		-> Pin 1  (3.3V)")
        print("Pin S		-> (+++Pin 2 ADC+++)")
        print("")
Exemple #6
0
def setup():
    ADC0832.setup()  # Setup ADC0832
    GPIO.setmode(GPIO.BOARD)  # Numbers GPIOs by physical location
    GPIO.setup(
        btn, GPIO.IN,
        pull_up_down=GPIO.PUD_UP)  # Setup button pin as input an pull it up
    global state
    state = ['--', 'UP', 'DN', 'LF', 'RH', 'PR']
Exemple #7
0
def setup():
    ADC0832.setup()  # Setup ADC0832
    GPIO.setmode(GPIO.BOARD)  # Numbers GPIOs by physical location
    GPIO.setup(
        btn, GPIO.IN,
        pull_up_down=GPIO.PUD_UP)  # Setup button pin as input an pull it up
    global state
    state = ['up', 'down', 'left', 'right']
Exemple #8
0
def sendResult():
    coordinates = {
        "x": ADC0832.getResult(0),
        "y": ADC0832.getResult(1),
        "z": (GPIO.input(btn) == 0)
    }
    print(coordinates)
    sock.sendto(json.dumps(coordinates).encode(), (UDP_IP, UDP_PORT))
Exemple #9
0
def joystickState():
	if ADC0832.getResult1() == 0:
		return 1		#up
	if ADC0832.getResult1() == 255:
		return 2		#down
	if ADC0832.getResult() == 0:
		return 3		#left
	if ADC0832.getResult() == 255:
		return 4		#right
Exemple #10
0
def subloop():
        while True:
                screen = i2c_lcd1602.Screen(bus=1, addr=0x27, cols=16, rows=2)
                line = "Personal Project"
                screen.enable_backlight()
                screen.clear()
                ADC0832.setup()
                line = sensor(line)
                return line
def joystickState():
	if ADC0832.getResult1() == 0:
		return 1		#up
	if ADC0832.getResult1() == 255:
		return 2		#down
	if ADC0832.getResult() == 0:
		return 3		#left
	if ADC0832.getResult() == 255:
		return 4		#right
Exemple #12
0
def readPhotoSens(chn=0):
    print "Reading light from channel: %d" % chn
    ADC0832.setup()
    photores = ADC0832.getResult(chn) - 80
    if photores < 0:
        photores = 0
    if photores > 100:
        photores = 100
    print 'Relative light = %d' % photores
    time.sleep(0.2)
Exemple #13
0
def readPhotoSens(chn=0):
  print "Reading light from channel: %d" % chn
  ADC0832.setup()
  photores = ADC0832.getResult(chn) - 80
  if photores < 0:
    photores = 0
  if photores > 100:
    photores = 100
  print 'Relative light = %d' % photores
  time.sleep(0.2)
def setup():
    ADC0832.setup()  # Setup ADC0832
    GPIO.setmode(GPIO.BOARD)  # Numbers GPIOs by physical location
    GPIO.setup(
        btn, GPIO.IN,
        pull_up_down=GPIO.PUD_UP)  # Setup button pin as input an pull it up
    GPIO.add_event_detect(btn,
                          GPIO.FALLING,
                          callback=button_pressed,
                          bouncetime=100)
    global state
    state = ['up', 'down', 'left', 'right']
def getResult():  #get joystick result
    x_axis = 0
    y_axis = 1
    x = ADC0832.getResult(x_axis)
    if x == 0:
        return 4
    elif x == 255:
        return 3
    y = ADC0832.getResult(y_axis)
    if y == 0:
        return 1
    elif y == 255:
        return 2
Exemple #16
0
def getResult():	#get joystick result
	if ADC0832.getResult1() == 0:
		return 1		#up
	if ADC0832.getResult1() == 255:
		return 2		#down

	if ADC0832.getResult() == 0:
		return 3		#left
	if ADC0832.getResult() == 255:
		return 4		#right

	if GPIO.input(btn) == 1:
		print 'Button is pressed!'		# Button pressed
Exemple #17
0
def getResult():  #get joystick result
    if ADC0832.getResult1() == 0:
        return 1  #up
    if ADC0832.getResult1() == 255:
        return 2  #down

    if ADC0832.getResult() == 0:
        return 3  #left
    if ADC0832.getResult() == 255:
        return 4  #right

    if GPIO.input(btn) == 1:
        print 'Button is pressed!'  # Button pressed
def getResult():	#get joystick result
	x_axis = 0
	y_axis = 1
	x = ADC0832.getResult(x_axis)	
	if x == 0:
		return 4
	elif x == 255: 
		return 3
	y = ADC0832.getResult(y_axis)
	if y == 0:
		return 1
	elif y == 255:
		return 2
Exemple #19
0
def get_light():
    try:
        ADC0832.setup()
        output_fromGPIO(pin, True)
        light = ADC0832.getResult(1) - 80
        print(light)
        if light < 0:
            light = 0
        return light
    except:
        ADC0832.destroy()
    finally:
        output_fromGPIO(pin, False)
Exemple #20
0
def get_moisture():
    try:
        ADC0832.setup()
        output_fromGPIO(pin, True)
        while True:
            moisture = ADC0832.getResult(0)
            if moisture != -1:
                return moisture
            sleep(1)
    except:
        ADC0832.destroy()
    finally:
        output_fromGPIO(pin, False)
Exemple #21
0
def printResult():  #get joystick result
    if ADC0832.getResult(1) == 0:
        print('up')  #up
    if ADC0832.getResult(1) == 255:
        print('down')  #down

    if ADC0832.getResult(0) == 0:
        print('left')  #left
    if ADC0832.getResult(0) == 255:
        print('right')  #right

    if GPIO.input(btn) == 0:
        print('Button is pressed!')  # Button pressed
Exemple #22
0
def setup():
    global LCDScreen
    global MAXRADIOCHANNEL
    global RadioDict

    GPIO.setmode(GPIO.BOARD)  # Numbers GPIOs by physical location
    #Rotary
    GPIO.setup(RoAPin, GPIO.IN)  # input mode
    GPIO.setup(RoBPin, GPIO.IN)
    GPIO.setup(RBtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.add_event_detect(RBtnPin, GPIO.FALLING, callback=btnResetChannel)

    #Potentiometer
    ADC0832.setup()
    Current_Volume_Value = Last_Volume_Value = ADC0832.getResult()

    #LCD Screen
    LCDScreen = Screen(bus=1, addr=0x3f, cols=16, rows=2)
    LCDScreen.enable_backlight()
    LCDScreen.clear()
    LCDScreen.display_data("Piper Radio", "")

    #BlueButton
    GPIO.setup(TweetBtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP
               )  # Set BtnPin's mode is input, and pull up to high level(3.3V)

    #credential setup
    if os.path.isfile("setenv.py"):
        print "running local"
        import setenv
    else:
        print "I must be in CF"

#initialize database
    initDB()
    MAXRADIOCHANNEL = getTotalStation()
    RadioDict = getListOfStation()

    #initialize polly
    initPolly()
    playWelcomeMsg()
    #delay 5 secodns before start
    sleep(5)

    #intialize radio
    initRadio(RadioDict["radioStationID:0"][1])

    #intialize ECS
    initECS()
Exemple #23
0
def readLuminosity():
    try:
        print("== IN READ LUMINOSITY IN THE BOX == ")
        luminosity = -100
        ADC0832.setup()
        GPIO.setup(16, GPIO.OUT)
        luminosity = ADC0832.getResult(0)
        print '## luminosity = %d' % luminosity
        GPIO.output(16, GPIO.HIGH)
        return luminosity

    except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program destroy() will be  executed.
        GPIO.output(pin, GPIO.LOW)
        GPIO.cleanup()  # Release resource
        return -100
Exemple #24
0
def getResult():
    #get joystick result
    global xFlag, yFlag
    if ADC0832.getResult(1) == 0:
        xFlag = 1  #up
    if ADC0832.getResult(1) == 255:
        xFlag = 2  #down

    if ADC0832.getResult(0) == 0:
        yFlag = 1  #left
    if ADC0832.getResult(0) == 255:
        yFlag = 2  #right

    if GPIO.input(btn) == 0:
        print 'Button is pressed!'  # Button pressed
Exemple #25
0
def loop():
	while True:
		t = ADC0832.getResult()
		vol = 5.0/255 * t
		vol = round(vol, 2)
		segment.numberDisplay_dec(vol)
		time.sleep(0.1)      
Exemple #26
0
def loop():
    while True:
        global digitalVal, analogVal
        analogVal = ADC0832.getResult(0)
        print 'Current analog value is %d' % analogVal
        GPIO.output(LedPin, GPIO.input(Flame_DO_Pin))
        time.sleep(0.2)
Exemple #27
0
def loop():
    while True:
        res = ADC0832.getResult()
        print 'res = %d' % res
        num = map(res, 0, 255, 0, 10)
        ledBarCtrl(num)
        time.sleep(0.2)
Exemple #28
0
def sensorData():
    analogVal = ADC0832.getResult()
    Vr = 5 * float(analogVal) / 255
    Rt = 10000 * Vr / (5 - Vr)
    temp = 1 / (((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25)))
    temp = temp - 273.15
    return temp
def loop():
    
    Rk = input("Input Known R-value: ")
    print
    print "Vc = ",Vc
    print "Rk = ",Rk
    
    while True:
                Rt = input("Input Unknown [Theoretical] R-value: ")
                print "Rt = ",Rt
        
                digOut = ADC0832.getResult()            #Get reading from ADC
                Io = (Vc/Rk)*digOut / 255               #calculate amps output if 255 equals .5 A
                
                if Io > 0:        
                    Ra = ( Vc / Io ) - Rk       #calculate resistance, subtract the 10 Ohm known resistor
                    print 'Ra = ', Ra
                    
                else:                           #avoid div by 0 error
                    Ra = 1000
                    print "Ra = infinite"
        
                #print 'Io = ', Io
                print 'Do = ', digOut
                print '%  = ', (Ra/Rt)*100,'%'
Exemple #30
0
def loop():
	while True:
		analogVal = ADC0832.getResult()
#		print 'temp analog= %d C' % analogVal
#		Vr = 5 * float(analogVal) / 255
#		Rt = 10000 * Vr / (5 - Vr)
#		temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15+25)))
#		temp = temp - 273.15
#		temp = float("{0:.2f}".format(temp))

		t = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
		if ARG_DISPLAY == 1:
#			print '%s Temperatur = %.2f C (Wartezeit: %ss)' % (t, temp, varWaitTime)
			print 'Rueckmeldung analoger Sensor: %s' % (analogVal)

		try:
			context = ssl._create_unverified_context()

			url = read_secret("json_push","url","/home/pi/ecg/")
#			print 'URL=%s' % url

			import json
			import urllib2

            SENSOR_FQN = SENSOR_QUALIFIER + "." + SENSOR_TYPE
            data = {
			         SENSOR_FQN: 1
            }
			req = urllib2.Request(url)
			req.add_header('Content-Type', 'application/json')

			response = urllib2.urlopen(req, json.dumps(data), context=context)
Exemple #31
0
def loop():
    global camera
    while True:

        ## ADC / LDR Section ##
        res = ADC0832.getResult() - 80
        if res < 0:
            res = 0
        if res > 100:
            res = 100
        print 'res = %d' % res
        time.sleep(0.2)
        ######

        if (res == 0):
            camera.stop_preview
        else:
            global ppl_cnt
            camera.start_preview()
            print_msg()
            #print("LDR Value: %.3f" % float(ldr.value))
            display(ppl_cnt)
            # tmp = int(raw_input('Please input a num(0~9999):'))
            # for i in range(500):
            # 	display(tmp)
            ppl_cnt += 1
            time.sleep(2)
def loop():
    while True:
        readSensors()

        res = ADC0832.getResult()
        moisture = 255 - res
        Msg2 = str('moisture %d' %(moisture))

        d = checkdist()
        df = "%0.2f" %d
        Msg3 = str('Distance %s' %df)

        d_date = datetime.datetime.now().date()
        d_time = datetime.datetime.now().time()
        d_time2 = d_time.strftime('%H:%M:%S') 
    
        if temperature >= temperature_alert:
            Msg6 = str(d_date) + ' ' + str(d_time2) + ' ' + str(temperature) + " : Be careful! The Temperature exceeds " + str(temperature_alert) + " degrees"
            print(Msg6)
            client.publish(Topic,Msg6)

        if moisture <= moisture_alert:
            Msg6 = str(d_date) + ' ' + str(d_time2) + ' ' + str(moisture) + " : Need Water! The Ammount of waters is low " + str(moisture_alert)
            print(Msg6)
            client.publish(Topic,Msg6)

        if d <= distance_alert:
            Msg6 = str(d_date) + ' ' + str(d_time2) + ' ' +": Our lady HANA is coming ! Let's enterain her. But it might be Gin !!"
            print(Msg6)
            client.publish(Topic,Msg6)
        time.sleep(10)
Exemple #33
0
def setup():
    GPIO.setmode(GPIO.BOARD)  #Number GPIOs by its physical location
    GPIO.setwarnings(False)
    for pin in pins:  # Setup 7 Seg pins
        GPIO.setup(pin, GPIO.OUT)  #set all pins' mode is output
        GPIO.output(pin, GPIO.HIGH)  #set all pins are high level(3.3V)

    ADC0832.setup()  # setup ADC

    # IR Sensor setup
    GPIO.setup(IR1Pin, GPIO.IN)
    GPIO.setup(IR2Pin, GPIO.IN)

    # Buzzer setup
    GPIO.setup(BZRPin, GPIO.OUT)  # Set pin mode as output
    GPIO.output(BZRPin, GPIO.LOW)
def get_temperature():
    analog_val = ADC0832.get_result()
    voltage = 5 * float(analog_val) / 255
    rt = 10000 * voltage / (5 - voltage)
    temp = 1 / (((math.log(rt / 10000)) / 3950) + (1 / (273.15 + 25)))
    temp = temp - 273.15
    return temp
def loop():
	while True:
		res = ADC0832.getResult()
		print 'res = %d' % res
		num = map(res, 0, 255, 0, 10)
		ledBarCtrl(num)
		time.sleep(0.2)
def loop():
	while True:
		analogVal = ADC.getResult(0)
		print 'adcval:', analogVal
		if analogVal > 0:
			print 'temp:', convert_to_temperature(analogVal)
		time.sleep(sleep_time)
Exemple #37
0
def photo():
    res = ADC0832.getResult() - 80
    if res < 0:
        res = 0
    if res > 100:
        res = 100
    return res
def loop():
	while True:
		analogVal = ADC.getResult(0)
		print 'adcval:', analogVal
		if analogVal > 200:
			beep()
		else:
			time.sleep(0.5)
def loop():
	p = GPIO.PWM(LedPin, 1000) # Set PWM Frequence to 1000Hz
	p.start(0)
	while True:
		res = ADC0832.getResult()
		if res > 100:
			res = 100
		p.ChangeDutyCycle(res)   # Change the duty cycle according to res
def loop():
	while True:
		res = ADC0832.getResult()
		if res < 0:
			res = 0
		if res > 100:
			res = 100
		print 'res = %d' % res
		time.sleep(0.2)
def loop():
	while True:
		analogVal = ADC0832.getResult()
		Vr = 5 * float(analogVal) / 255
		Rt = 10000 * Vr / (5 - Vr)
		temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15+25)))
		temp = temp - 273.15
		print 'temperature = %d C' % temp
		time.sleep(0.2)
def setup():
	GPIO.setmode(GPIO.BOARD)
	# Buzzer setup:
	GPIO.setup(Buzzer, GPIO.OUT)
	GPIO.output(Buzzer, 1)
	# RGB setup:
	GPIO.setup(LedRed, GPIO.OUT)
	GPIO.setup(LedGreen, GPIO.OUT)
	GPIO.setup(LedBlue, GPIO.OUT)
	GPIO.output(LedRed, 1)
	GPIO.output(LedGreen, 1)
	GPIO.output(LedBlue, 1)
	# DS18B20 setup:
	ds18b20Init()
	# Joystick setup:
	GPIO.setup(btn, GPIO.IN)
	GPIO.add_event_detect(btn, GPIO.FALLING, callback=joystickbtn, bouncetime=200)
	# ADC0832 setup:
	ADC0832.setup()
def loop():
	while True:
		rainVal = ADC0832.getResult(0)
		print GPIO.input(RAIN)
		if GPIO.input(RAIN) == 0:
			print '***************'
			print '* !!RAINING!! *'
			print '***************'
			print ''
		print rainVal
		time.sleep(0.5)
def loop():
	while True:
		analogVal = ADC.getResult(0)
		print "value =", analogVal
		illum = map(analogVal, 130, 255, 0, 100)
		if illum > 80:
			illum = 80
		if illum < 0:
			illum = 0
		p.ChangeDutyCycle(illum)
		print illum
		time.sleep(0.05)
def loop():
	while True:
		screen.cursorTo(0, 0)
		screen.println(line)
		t = ADC0832.getResult()
		vol = 5.0/255 * t
		vol = round(vol, 2)
		vol = '%f' %vol
		vol = vol[:4]
		screen.cursorTo(1, 0)
		screen.println(' Voltage: ' + vol + 'V ')
		screen.clear()
		time.sleep(0.2)      
def loop():
	while True:
		tmp = ADC0832.getResult()			# Get analog value from ADC0832
		print tmp							# Print analog value
		if tmp > TS :						# Beep when read value greater than threshold
			print '    ****************'
			print '    * !! DANGER !! *'
			print '    ****************'
			print ''
				
			GPIO.output(BEEP, GPIO.HIGH)	# (0, means detect danger gas)
			time.sleep(0.25)
			GPIO.output(BEEP, GPIO.LOW)
			time.sleep(0.25)
		else :
			time.sleep(0.5)					# Else delay printing.
Exemple #47
0
def setup():
	ADC0832.setup()				# Setup ADC0832
	GPIO.setmode(GPIO.BOARD)	# Numbers GPIOs by physical location
	GPIO.setup(btn, GPIO.IN, pull_up_down=GPIO.PUD_UP)	# Setup button pin as input an pull it up
	global state
	state = ['up', 'down', 'left', 'right']	
def init():
	GPIO.setmode(GPIO.BOARD)	
	GPIO.setup(MIC_DO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
	ADC0832.setup()
def loop():
	while True:
		analogVal = ADC.getResult(0)
		print 'Current Voltage :', analogVal*(5.0/255), 'V'
		time.sleep(0.4)
def adcInit():
	ADC0832.setup()
def loop():
	while True:
		res = ADC0832.getResult()
		moisture = 255 - res
		print 'analog value: %03d  moisture: %d' %(res, moisture)
		time.sleep(0.1)
def init():
	ADC0832.setup()
#!/usr/bin/env python
import ADC0832
import time

def init():
	ADC0832.setup()

def loop():
	while True:
		res = ADC0832.getResult()
		moisture = 255 - res
		print 'analog value: %03d  moisture: %d' %(res, moisture)
		time.sleep(0.1)

if __name__ == '__main__':
	init()
	try:
		loop()
	except KeyboardInterrupt: 
		ADC0832.destroy()
		print 'The end !'
def setup():
	ADC.setup()
def loop():
	while True:
		res = ADC0832.getResult()
		print 'res = %d' % res
		if res > 200:
			beep()
def ADC0832Init():
	ADC0832.setup()
def setup():
	ADC.setup()
	GPIO.setup(Beep, GPIO.OUT)
screen = i2c_lcd1602.Screen(bus=1, addr=0x27, cols=16, rows=2)

def destory():
	GPIO.cleanup()

def loop():
	while True:
		screen.cursorTo(0, 0)
		screen.println(line)
		t = ADC0832.getResult()
		vol = 5.0/255 * t
		vol = round(vol, 2)
		vol = '%f' %vol
		vol = vol[:4]
		screen.cursorTo(1, 0)
		screen.println(' Voltage: ' + vol + 'V ')
		screen.clear()
		time.sleep(0.2)      

if __name__ == '__main__':
	print 'www.adeept.com'
	line = " www.adeept.com "
	screen.enable_backlight()
	screen.clear()
	try:
		ADC0832.setup()
		loop()
	except KeyboardInterrupt:
		destory()
def loop():
	while True:
		res = ADC0832.getResult()
		v = res * (3.3 / 255)
		print 'Current voltage: %.2f V' % v
		time.sleep(0.2)