コード例 #1
0
ファイル: dht11.py プロジェクト: young-mu/Wime
def readData(pin):
    hum = 0
    temp = 0
    crc = 0
    GPIO.pinMode(pin, 1)
    GPIO.digitalWrite(pin, 1)
    GPIO.digitalWrite(pin, 0)
    GPIO.delay(20)
    GPIO.digitalWrite(pin, 1)
    GPIO.pinMode(pin, 0)
    GPIO.delayMicroseconds(40)
    if GPIO.digitalRead(pin) == 0:
        untilHigh(pin)
        for i in range(16):
            hum <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            hum += GPIO.digitalRead(pin)
        for i in range(16):
            temp <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            temp += GPIO.digitalRead(pin)
        for i in range(8):
            crc <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            crc += GPIO.digitalRead(pin)
        return [True, hum, temp, crc]
    else:
        return [False, hum, temp, crc]
コード例 #2
0
ファイル: dht11.py プロジェクト: young-mu/RPi
def readData(pin):
    hum = 0
    temp = 0
    crc = 0
    GPIO.pinMode(pin, 1)
    GPIO.digitalWrite(pin, 1)
    GPIO.digitalWrite(pin, 0)
    GPIO.delay(20)
    GPIO.digitalWrite(pin, 1)
    GPIO.pinMode(pin, 0)
    GPIO.delayMicroseconds(40)
    if GPIO.digitalRead(pin) == 0:
        untilHigh(pin)
        for i in range(16):
            hum <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            hum += GPIO.digitalRead(pin)
        for i in range(16):
            temp <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            temp += GPIO.digitalRead(pin)
        for i in range(8):
            crc <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            crc += GPIO.digitalRead(pin)
        return [True, hum, temp, crc]
    else:
        return [False, hum, temp, crc]
コード例 #3
0
def get_data(channel):
    tl = []
    gpio.digitalWrite(channel, gpio.HIGH)  # 输出高电平
    gpio.delay(1)
    ###发开始指令,要求DHT11传输数据
    gpio.digitalWrite(channel, gpio.LOW)  # 拉低25ms开始指令
    gpio.delay(25)
    gpio.digitalWrite(channel, gpio.HIGH)  # 输出高电平,开始指令结束
    gpio.pinMode(channel, gpio.INPUT)  # 设针脚为输入状态
    ###开始指令发送完毕,把管脚设置为高电平,并等待DHT11拉低管脚。传输数据
    while (gpio.digitalRead(channel) == gpio.HIGH):
        pass  # 如果管脚一直是1,则一直等待。
    ###若被拉低,说明传输开始,应答信号+40位数据+结束标志共42位
    ###下边共循环45次,故意多循环几次看结果。
    ###开始接受数据,50us低 + 26-28us高=0,50us低 + 70us高 = 1
    for i in range(45):  # 测试每个数据周期的时间(包括40bit数据加一个发送开始标志
        tc = gpio.micros()  # 记下当前us数(从初始化开始算起,必要时重新初始化)
        '''
        一个数据周期,包括一个低电平,一个高电平,从DHT11第一次拉低信号线开始
        到DHT11发送最后一个50us的低电平结束(然后被拉高,一直维持高电平,所以
        最后的完成标志是一直为高,超过500us)
        '''
        while (gpio.digitalRead(channel) == gpio.LOW):
            pass  # 一位数据由一个低电平
        while (gpio.digitalRead(channel) == gpio.HIGH):  # 加一个高电平组成
            if gpio.micros() - tc > 500:  # 如果超过500us就结束了本次循环,传输结束后
                break  # 会被上拉电阻拉成高电平,防止进入死循环
        tl.append(gpio.micros() - tc)  # 记录每个周期时间的us数,存到tl这个列表
    print(tl)
    return tl
コード例 #4
0
ファイル: xbox_rf.py プロジェクト: rrity/xbox360_rf
def Init():
	wiringpi2.pinMode(data_pin, 0)
	wiringpi2.pinMode(clock_pin, 0)
	wiringpi2.wiringPiSetup()
	
	SendData(cmdlist["led_cmd"])
	wiringpi2.delay(50)
コード例 #5
0
def get_black_sw():
    if(wiringpi2.digitalRead(2) == 0):
        wiringpi2.delay(50)
        if(wiringpi2.digitalRead(2) == 1):
            return True
        elif(wiringpi2.digitalRead(2) == 0):
            return False
コード例 #6
0
def emitData():
    global tprec, T0
    # Délai nécessaire pour que le serveur ait le temps de démarrer
    wiringpi2.delay(5000)
    tprec = time.time()
    T0 = time.time()
    while True: loop() # appelle fonction loop sans fin
コード例 #7
0
def get_white_sw():
    if(wiringpi2.digitalRead(0) == 0):
        wiringpi2.delay(50)
        if(wiringpi2.digitalRead(0) == 1):
            return True
        elif(wiringpi2.digitalRead(0) == 0):
            return False
コード例 #8
0
ファイル: ttg.py プロジェクト: BenSchomp/Tic-Tac-GPIO
def winningAnimation(winningLine):
    # convert line to pins
    winningPins = winningLine
    if Turn == GREEN:
        for i in range(0, 3):
            winningPins[i] = winningLine[i] + 9

    wiringpi.delay(LONG_PAUSE)
    led.ledsOff(winningPins, MED_PAUSE)

    # flash all three
    for i in range(0, 2):
        led.ledsOnOff(winningPins, MED_PAUSE)

    led.ledsOn(winningPins, LONG_PAUSE)

    # flash one at a time
    for i in range(0, 2):
        led.ledsOff(winningPins, SHORT_PAUSE)
        for j in range(0, 3):
            led.ledOn(winningPins[j], MED_PAUSE)
        wiringpi.delay(SHORT_PAUSE)

    led.ledsOff(winningPins, SHORT_PAUSE)

    # flash all three again
    for i in range(0, 2):
        led.ledsOnOff(winningPins, SHORT_PAUSE)

    # turn back on for final board
    led.ledsOn(winningPins)
コード例 #9
0
def writedisplay(whattodisplay):
    for pos in range(0, 8):
        if 1 & pos <> 0:
            wiringpi.digitalWrite(A0, HIGH)
        else:
            wiringpi.digitalWrite(A0, LOW)
        if 2 & pos <> 0:
            wiringpi.digitalWrite(A1, HIGH)
        else:
            wiringpi.digitalWrite(A1, LOW)
        if 4 & pos <> 0:
            wiringpi.digitalWrite(A2, HIGH)
        else:
            wiringpi.digitalWrite(A2, LOW)

        wiringpi.digitalWrite(latch, LOW)
        wiringpi.shiftOut(SER, CLK, 1, ord(whattodisplay[pos]))
        wiringpi.digitalWrite(latch, HIGH)
        wiringpi.delay(1)
        wiringpi.digitalWrite(CE, LOW)
        wiringpi.delay(1)
        wiringpi.digitalWrite(WR, LOW)
        wiringpi.delay(1)
        wiringpi.digitalWrite(WR, HIGH)
        wiringpi.delay(1)
        wiringpi.digitalWrite(CE, HIGH)
        wiringpi.delay(1)
    return
コード例 #10
0
ファイル: multiPDSP.py プロジェクト: agallo/PDSPmulti
def writedisplay(whattodisplay):
    for pos in range(0, 8):
        if 1 & pos <> 0:
            wiringpi.digitalWrite(A0, HIGH)
        else:
            wiringpi.digitalWrite(A0, LOW)
        if 2 & pos <> 0:
            wiringpi.digitalWrite(A1, HIGH)
        else:
            wiringpi.digitalWrite(A1, LOW)
        if 4 & pos <> 0:
            wiringpi.digitalWrite(A2, HIGH)
        else:
            wiringpi.digitalWrite(A2, LOW)
        wiringpi.digitalWrite(latch, LOW)
        wiringpi.shiftOut(SER, CLK, 1, ord(whattodisplay[pos]))
        wiringpi.digitalWrite(latch, HIGH)
    wiringpi.delay(1)
    whichdisplay(255)
    wiringpi.delay(1)
    wiringpi.digitalWrite(WR, LOW)
    wiringpi.delay(1)
    wiringpi.digitalWrite(WR, HIGH)
    wiringpi.delay(1)
    whichdisplay(254)
    wiringpi.delay(1)
    return
コード例 #11
0
ファイル: sonar.py プロジェクト: Price47/JackalopeCapstone
    def get_distance(self, sensor):
        #wiringpi.digitalWrite(30,HIGH)
        wiringpi.digitalWrite(sensor.echo, LOW)
        wiringpi.delay(1000)
        wiringpi.digitalWrite(sensor.trigger, HIGH)
        wiringpi.delay(1)
        wiringpi.digitalWrite(sensor.trigger, LOW)
        #start = time.time()
	print "Trying to get distance of sensor " , sensor.position, "Trig: ", sensor.trigger, " Echo:", sensor.echo
	status = LOW
	while(wiringpi.digitalRead(sensor.echo) == LOW):
		status = LOW
	start = time.time()
	while(wiringpi.digitalRead(sensor.echo) == HIGH):
		status = LOW
	end = time.time()	

#	while status == LOW:
#	    feedback = wiringpi.digitalRead(sensor.echo)
#	    if(feedback == HIGH):
#		while(feedback == HIGH):
#		    status = LOW
#		end = time.time()
#		print("Time Elapsed: ", end-start)
#		status = HIGH
#	    if((time.time() - start) > 1):
#		end = time.time()
#		status = HIGH

        # Below divide by 340.29 for air distance, or divide by 1484 for water distance
        return (end - start)*(340.29/2)
コード例 #12
0
ファイル: drumserver.py プロジェクト: burningion/robotBongos
 def foo_callback(self, path, args):
     wiringpi2.digitalWrite(args[0],1)
     #sleep(0.03)
     scaled = args[1] / 127.0
     wiringpi2.delay(int(scaled*15 + 4)) # five is min, max is uhhh 20 ish?
     wiringpi2.digitalWrite(args[0],0)
     print("received message '%s' with arguments: %d, %d" % (path, args[0], args[1]))
コード例 #13
0
def lcd_write(dc, data):
  wiringpi.digitalWrite(PIN_DC, dc)
  wiringpi.digitalWrite(PIN_SCE, LOW)
  wiringpi.delay(SLOW_DOWN)
  #wiringpi.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data)
  slow_shift_out(PIN_SDIN, PIN_SCLK, data)
  wiringpi.digitalWrite(PIN_SCE, HIGH)
  wiringpi.delay(SLOW_DOWN)
コード例 #14
0
def lcd_write(dc, data):
    wiringpi.digitalWrite(PIN_DC, dc)
    wiringpi.digitalWrite(PIN_SCE, LOW)
    wiringpi.delay(SLOW_DOWN)
    #wiringpi.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data)
    slow_shift_out(PIN_SDIN, PIN_SCLK, data)
    wiringpi.digitalWrite(PIN_SCE, HIGH)
    wiringpi.delay(SLOW_DOWN)
コード例 #15
0
ファイル: bsp.py プロジェクト: mnowotka/epyper
def delayMs(ms):
    """   
       Delay specified number of milliseconds
       
       Params:
           [in] ms - number of milliseconds to delay
    
    """
    wiringpi2.delay(ms)
コード例 #16
0
def delayMs(ms):
    """   
       Delay specified number of milliseconds
       
       Params:
           [in] ms - number of milliseconds to delay
    
    """
    wiringpi2.delay(ms)
コード例 #17
0
def FlashDesk():
    for i in range(0, 5):
        for j in range(0, 100, STEP):
            wiringpi2.softPwmWrite(PIN_TO_PWM, j)
            wiringpi2.delay(50)

        for j in range(100, 0, (STEP * -1)):
            wiringpi2.softPwmWrite(PIN_TO_PWM, j)
            wiringpi2.delay(50)
コード例 #18
0
ファイル: led.py プロジェクト: BenSchomp/Tic-Tac-GPIO
def spiral( duration ):
  trail = [0, 3, 6, 7, 8, 5, 2, 4, 1 ]
  for pin in trail:
    ledOn( pin, duration )

  wiringpi.delay( duration )

  trail.reverse()
  for pin in trail:
    ledOff( pin, duration )
コード例 #19
0
ファイル: lcd.py プロジェクト: SAAO/noon_time_for_pi
def clear(fd):
	type = False
	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delay(5)
	return
コード例 #20
0
def ushiro(radian):
    com.dSPIN_Move(hd.REV, int(radian))

    while (wp.digitalRead(hd.dSPIN_BUSYN) == wp.GPIO.LOW):
        pass
    com.dSPIN_SoftStop()

    while (wp.digitalRead(hd.dSPIN_BUSYN) == wp.GPIO.LOW):
        pass
    wp.delay(500)
コード例 #21
0
ファイル: xbox_rf.py プロジェクト: rrity/xbox360_rf
def Bruteforce(begin=0, end=255, ignore_known=True):
  while begin <= end:
	binstr = "00" + "{0:b}".format(begin)
	binstr = "0" * (7-(len(binstr)-3)) + binstr
	if binstr not in cmdlist.values() or ignore_known == False:
		SendData(binstr)
		print(binstr + " : " + str(begin))
	else:
		print(binstr + " : " + cmdlist_reversed[binstr])
	wiringpi2.delay(1000)
	begin += 1
コード例 #22
0
def softPwm():
	print "SoftPwm Mode"

	wiringpi2.wiringPiSetup()
	wiringpi2.pinMode(PIN_TO_PWM,SET_PWM)
	wiringpi2.pwmSetMode(PWM_MODE_MS)	
	#wiringpi2.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters
	#wiringpi2.softServoSettup()
	#softServoWrite()
	wiringpi2.pwmWrite(PIN_TO_PWM, 900) 	
	wiringpi2.delay(150)
	print "PWM is in NEUTRAL"
コード例 #23
0
def talk_to_badge(nfc_msg):
    name = nfc_msg[16:].split('\x00', 1)[0]
    mac = ':'.join((nfc_msg[10:12], nfc_msg[8:10], nfc_msg[6:8],
                    nfc_msg[4:6], nfc_msg[2:4], nfc_msg[0:2]))
    device_id = ''.join((nfc_msg[14:16], nfc_msg[12:14]))
    ipc = wall_ipc.WallIPC(mac)
    ipc.connect()
    ipc.send("Welcome %s!" % name)
    ipc.send("")
    ipc.send("Checking your score ...")
    print('Talking to %s' % mac)
    eligible = trinket_limit(mac)
    if not eligible:
        print('%s not eligible for more trinkets!' % mac)
        ipc.send("You have all the trinkets!")
        trinket_log(mac)    # Log extra attempts just for fun
    else:
        (score, lld) = get_badge_info(mac, device_id)
        if score is not None:
            score = int(score)
            lld = int(lld)
            print "GATT reported score=%d lld=%d" % (score, lld)
            if score is not None:
                ipc.send("Your score is %d" % score)
                if score < (lld+1)*250:
                    ipc.send("Try again when it reaches %d" % ((lld+1)*250))
                else:
                    ipc.send("Eligible for a trinket!")
                    if check_dispenser_idle():
                        pulse_dispenser()
                        if await_dispenser_start():
                            ipc.send("Here's a gift for you!")
                            if await_dispenser_done():
                                ipc.send("Please take your gift")
                                trinket_log(mac)
                                # put_badge_lld(lld+1)
                                if not badge_increment_lld(mac):
                                    ipc.send("Where did you go?")
                            else:
                                ipc.send("Oops, I'm broken!")
                                ipc.send("Please ask for help")
                        else:
                            ipc.send("Dispenser not responding")
                            ipc.send("Try again later")
                    else:
                        ipc.send("Dispenser busy!")
                        ipc.send("Try again later")
        else:
            ipc.send("Where did you go?")
            
    delay(window_close_delay_ms)
    ipc.close()
コード例 #24
0
def setup():

    ans = 0
    sup.dSPIN_init()

    print("Confug:" + ('%x' % hd.dSPIN_CONFIG))
    print("Status:" + ('%x' % hd.dSPIN_STATUS))
    print("config register = {0}".format(
        hex(com.dSPIN_GetParam(hd.dSPIN_CONFIG))))

    com.dSPIN_SetParam(hd.dSPIN_STEP_MODE, (not hd.dSPIN_SYNC_EN)
                       | hd.dSPIN_STEP_SEL_1_2 | hd.dSPIN_SYNC_SEL_1)

    print("step_mode = {0}".format(hex(com.dSPIN_GetParam(
        hd.dSPIN_STEP_MODE))))

    com.dSPIN_SetParam(hd.dSPIN_MAX_SPEED, sup.MaxSpdCalc(2000))
    print("max_speed = {0}".format(hex(com.dSPIN_GetParam(
        hd.dSPIN_MAX_SPEED))))

    com.dSPIN_SetParam(hd.dSPIN_FS_SPD, sup.FSCalc(400))
    print("fs_speed = {0}".format(hex(com.dSPIN_GetParam(hd.dSPIN_FS_SPD))))
    com.dSPIN_SetParam(hd.dSPIN_ACC, 0x05)
    print("acc = {0}".format(hex(com.dSPIN_GetParam(hd.dSPIN_ACC))))

    com.dSPIN_SetParam(hd.dSPIN_OCD_TH, hd.dSPIN_OCD_TH_3750mA)
    print("OCD_TH = {0}".format(hex(com.dSPIN_GetParam(hd.dSPIN_OCD_TH))))

    com.dSPIN_SetParam(
        hd.dSPIN_CONFIG, hd.dSPIN_CONFIG_PWM_DIV_2 | hd.dSPIN_CONFIG_PWM_MUL_1
        | hd.dSPIN_CONFIG_SR_290V_us
        | hd.dSPIN_CONFIG_OC_SD_DISABLE | hd.dSPIN_CONFIG_VS_COMP_ENABLE
        | hd.dSPIN_CONFIG_SW_USER | hd.dSPIN_CONFIG_INT_16MHZ)

    print("dSPIN_CONFIG = {0}".format(hex(com.dSPIN_GetParam(
        hd.dSPIN_CONFIG))))
    com.dSPIN_SetParam(hd.dSPIN_KVAL_RUN, 0xFF)
    print("KVAL_RUN = {0}".format(hex(com.dSPIN_GetParam(hd.dSPIN_KVAL_RUN))))

    print("Status code is:{0} See datasheet sec.9.1.22 to decode.".format(
        hex(com.dSPIN_GetStatus())))

    wp.delay(200)

    ans = com.dSPIN_GetStatus() & 0x0200
    print("ans = {0}".format(hex))
    print(hex(ans))
    while (ans == 0x0000):
        print("Undervoltage lockout is active:")
        print(com.dSPIN_GetStatus())
        ans = com.dSPIN_GetStatus() & 0x0200
        wp.delay(500)
コード例 #25
0
 def fade(self, red, green, blue, delay=500, step=5):
     for i in range(0, delay, step):
         f = (0.0+i)/delay
         r = self.red   + (red  -self.red)   * f
         wiringpi2.softPwmWrite(self.r_pin, int(r))
         g = self.green + (green-self.green) * f
         wiringpi2.softPwmWrite(self.g_pin, int(g))
         b = self.blue  + (blue -self.blue)  * f
         wiringpi2.softPwmWrite(self.b_pin, int(b))
         wiringpi2.delay(step)
     self.red = red
     self.blue = blue
     self.green = green
コード例 #26
0
 def fade(self, red, green, blue, delay=500, step=5):
     for i in range(0, delay, step):
         f = (0.0 + i) / delay
         r = self.red + (red - self.red) * f
         wiringpi2.softPwmWrite(self.r_pin, int(r))
         g = self.green + (green - self.green) * f
         wiringpi2.softPwmWrite(self.g_pin, int(g))
         b = self.blue + (blue - self.blue) * f
         wiringpi2.softPwmWrite(self.b_pin, int(b))
         wiringpi2.delay(step)
     self.red = red
     self.blue = blue
     self.green = green
コード例 #27
0
ファイル: softPwm.py プロジェクト: masterky/Python-RCCarRepo
def softPwm():
	print "SoftPwm Mode"

	wiringpi2.wiringPiSetup()
	wiringpi2.pinMode(PIN_TO_PWM,OUTPUT)
	wiringpi2.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters

	for time in range(0,4):
        	for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on
                	wiringpi2.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle
                	wiringpi2.delay(10) # Delay for 0.2 seconds
        	for brightness in reversed(range(0,100)):
                	wiringpi2.softPwmWrite(PIN_TO_PWM,brightness)
                	wiringpi2.delay(10)
コード例 #28
0
ファイル: lcd.py プロジェクト: bblonder/flir_thermal_control
def lcd_check_buttons(delay):
	lbutton = 0
	rbutton = 0

	wiringpi2.delay(delay)
	if wiringpi2.digitalRead(5) == 0: # Left button
		print("left button pressed")
		lbutton = 1

	if wiringpi2.digitalRead(6) == 0: # Right button
		print("right button pressed")
		rbutton = 1

	return (lbutton, rbutton)
コード例 #29
0
def get_distance(sensor):
    #wiringpi.digitalWrite(30,HIGH)
    wiringpi.digitalWrite(sensor.echo, LOW)
    wiringpi.delay(1000)
    wiringpi.digitalWrite(sensor.trigger, HIGH)
    wiringpi.delay(1)
    wiringpi.digitalWrite(sensor.trigger, LOW)
    start = time.time()
    while wiringpi.digitalRead(sensor.echo) == LOW:
        wait = True
        #print( "Pin Echo: " + str(wiringpi.digitalRead(sensor.echo)))

    # Below divide by 340.29 for air distance, or divide by 1484 for water distance
    return (time.time() - start)*(340.29/2)
コード例 #30
0
ファイル: temp_gui.py プロジェクト: jowood4/temp_control
    def run(self):
	while self.run_temp_control:
		#time.sleep(0.001)
		wiringpi2.delay(100)
		if self.queue_set.empty() != True:
			temp = self.queue_set.get(0)
			if temp == -100:
				self.run_temp_control = 0
			else:
				self.temp_set = int(temp) 
		
		#self.temp_read = self.temp_set + 2
		self.temp_read = self.temp_controller.read_thermo_temp()
		self.temp_controller.regulate_temp(self.temp_set, self.temp_read)		
		wiringpi2.delay(100)
		self.queue_read.put(self.temp_read)
コード例 #31
0
ファイル: led.py プロジェクト: BenSchomp/Tic-Tac-GPIO
def animations():
  allOff()

  while 1:
    flashEach( 125 )
    flashRows( 150 )
    flashCols( 150 )
    snake( 100 )
    flatWipe( 200 )
    spiral( 75 )
    diagWipe( 150 )

    for i in range( 0, 3 ):
      flashAll( 125 )

    wiringpi.delay( 750 )
コード例 #32
0
ファイル: temp_gui.py プロジェクト: jowood4/temp_control
    def run(self):
        while self.run_temp_control:
            #time.sleep(0.001)
            wiringpi2.delay(100)
            if self.queue_set.empty() != True:
                temp = self.queue_set.get(0)
                if temp == -100:
                    self.run_temp_control = 0
                else:
                    self.temp_set = int(temp)

            #self.temp_read = self.temp_set + 2
            self.temp_read = self.temp_controller.read_thermo_temp()
            self.temp_controller.regulate_temp(self.temp_set, self.temp_read)
            wiringpi2.delay(100)
            self.queue_read.put(self.temp_read)
コード例 #33
0
def mae(radian):
    print("Status code is:{0} See datasheet sec.9.1.22 to decode.".format(
        hex(com.dSPIN_GetStatus())))

    com.dSPIN_Move(hd.FWD, int(radian))
    print("command completed 'dSPIN_Move(FWD, 200);'\n")

    while (wp.digitalRead(hd.dSPIN_BUSYN) == wp.GPIO.LOW):
        pass

    print("no longer busy; sending next command")
    com.dSPIN_SoftStop()

    while (wp.digitalRead(hd.dSPIN_BUSYN) == wp.GPIO.LOW):
        pass
    wp.delay(500)
コード例 #34
0
def piglow_set_white(b):
    #global INTENSITY, saved_hue
    global saved_white
    delay = 2  #500/abs(b-saved_white)
    #INTENSITY=b
    #piglow_set_hue(saved_hue)

    if (b > saved_white):
        for i in range(saved_white, b):
            wpi.piGlowRing(WHITE, i)
            wpi.delay(delay)
    else:
        for i in reversed(range(b, saved_white)):
            wpi.piGlowRing(WHITE, i)
            wpi.delay(delay)

    saved_white = b
コード例 #35
0
ファイル: hello.py プロジェクト: bighead85/LivLight
def piglow_set_white(b):
	#global INTENSITY, saved_hue
	global saved_white
	delay = 2 #500/abs(b-saved_white)
	#INTENSITY=b
	#piglow_set_hue(saved_hue)
	
	if(b > saved_white):
		for i in range(saved_white,b):
			wpi.piGlowRing(WHITE,i)
			wpi.delay(delay)
	else:
		for i in reversed(range(b,saved_white)):
			wpi.piGlowRing(WHITE,i)
			wpi.delay(delay)

	saved_white = b
コード例 #36
0
def lcd_initialise():
    wiringpi.pinMode(PIN_BACKLIGHT, OUTPUT)
    wiringpi.digitalWrite(PIN_BACKLIGHT, HIGH)
    wiringpi.pinMode(PIN_SCE, OUTPUT)
    wiringpi.pinMode(PIN_RESET, OUTPUT)
    wiringpi.pinMode(PIN_DC, OUTPUT)
    wiringpi.pinMode(PIN_SDIN, OUTPUT)
    wiringpi.pinMode(PIN_SCLK, OUTPUT)
    wiringpi.digitalWrite(PIN_RESET, LOW)
    wiringpi.delay(SLOW_DOWN)
    wiringpi.digitalWrite(PIN_RESET, HIGH)
    wiringpi.delay(SLOW_DOWN)
    lcd_write(LCD_C, 0x21)  # LCD Extended Commands.
    lcd_write(LCD_C, 0xCC)  # Set LCD Vop (Contrast).
    lcd_write(LCD_C, 0x04)  # Set Temp coefficent. //0x04
    lcd_write(LCD_C, 0x14)  # LCD bias mode 1:48. //0x13
    lcd_write(LCD_C, 0x0C)  # LCD in normal mode.
    lcd_write(LCD_C, 0x20)
    lcd_write(LCD_C, 0x0C)
コード例 #37
0
ファイル: spkMusic.py プロジェクト: DEPlayground/GPIO.OLD
    def main(self):
        wiringpi2.pwmSetClock(int(self.divisor))

        for i, note in enumerate(Music.melody):
            if len(note) == 0:
                wiringpi2.pwmWrite(self.SPEAKER, 0)
            else:
                period, dutyCycle = self.calcParams(note)
                wiringpi2.pwmSetRange(period)
                wiringpi2.pwmWrite(self.SPEAKER, dutyCycle)

            wiringpi2.delay(Music.delay * (Music.beats[i] + 1))

            if note[len(note) - 1:] == ':':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
                wiringpi2.delay(Music.delay)

        curses.endwin()
        wiringpi2.pinMode(self.SPEAKER, 0)
コード例 #38
0
def lcd_initialise():
  wiringpi.pinMode(PIN_BACKLIGHT,OUTPUT)
  wiringpi.digitalWrite(PIN_BACKLIGHT, HIGH)
  wiringpi.pinMode(PIN_SCE, OUTPUT)
  wiringpi.pinMode(PIN_RESET, OUTPUT)
  wiringpi.pinMode(PIN_DC, OUTPUT)
  wiringpi.pinMode(PIN_SDIN, OUTPUT)
  wiringpi.pinMode(PIN_SCLK, OUTPUT)
  wiringpi.digitalWrite(PIN_RESET, LOW)
  wiringpi.delay(SLOW_DOWN)
  wiringpi.digitalWrite(PIN_RESET, HIGH)
  wiringpi.delay(SLOW_DOWN)
  lcd_write(LCD_C, 0x21 )  # LCD Extended Commands.
  lcd_write(LCD_C, 0xCC )  # Set LCD Vop (Contrast). 
  lcd_write(LCD_C, 0x04 )  # Set Temp coefficent. //0x04
  lcd_write(LCD_C, 0x14 )  # LCD bias mode 1:48. //0x13
  lcd_write(LCD_C, 0x0C )  # LCD in normal mode.
  lcd_write(LCD_C, 0x20 )
  lcd_write(LCD_C, 0x0C )
コード例 #39
0
ファイル: spkMusic.py プロジェクト: RaspberryLove/GPIO.OLD
    def main(self):
        wiringpi2.pwmSetClock(int(self.divisor))

        for i, note in enumerate(Music.melody):
            if len(note) == 0:
                wiringpi2.pwmWrite(self.SPEAKER, 0)
            else:
                period, dutyCycle = self.calcParams(note)
                wiringpi2.pwmSetRange(period)
                wiringpi2.pwmWrite(self.SPEAKER, dutyCycle)

            wiringpi2.delay(Music.delay*(Music.beats[i]+1))

            if note[len(note)-1:] == ':':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
                wiringpi2.delay(Music.delay)

        curses.endwin()
        wiringpi2.pinMode(self.SPEAKER, 0)
コード例 #40
0
def analyze_with_kinect():
	gpio_down(18)
	response = subprocess.check_output(['bash','run.sh'])
	
	res = str(response[-2:])
	output = res[0]	
	print "python response: " + str(output)

	if int(output) == 1:
		print 'drowning'
		gpio_up(18)
		wiringpi.delay(5000)
		gpio_down(18)
		print 'drowning'
		return False
	elif int(output) == 0:
		print 'not drowning'
		return True
	else:
		print 'no kinect found'
コード例 #41
0
    def __init__(self, node_name="servo_control"):

        rospy.init_node(node_name)
        sub = rospy.Subscriber("deg_control", Int16, self.callback)

        signal.signal(signal.SIGINT, self.exit_handler)

        self.gp_out = 18
        wiringpi2.wiringPiSetupGpio()
        wiringpi2.pinMode(self.gp_out, wiringpi2.GPIO.PWM_OUTPUT)
        wiringpi2.pwmSetMode(wiringpi2.GPIO.PWM_MODE_MS)
        wiringpi2.pwmSetClock(375)

        self.RIGHT = 56
        self.CENTER = 76
        self.LEFT = 96

        self.current_deg = self.CENTER
        wiringpi2.pwmWrite(self.gp_out, self.current_deg)
        wiringpi2.delay(500)
コード例 #42
0
ファイル: xbox_rf.py プロジェクト: rrity/xbox360_rf
def SendData(command, delay = 0):
  wiringpi2.pinMode(data_pin,1)
  wiringpi2.digitalWrite(data_pin,0)

  prev = 1
  for i in range(len(command)):

    while prev == wiringpi2.digitalRead(clock_pin):
        pass

    prev = wiringpi2.digitalRead(clock_pin)
    wiringpi2.digitalWrite(data_pin, int(command[i]))

    while prev == wiringpi2.digitalRead(clock_pin):
        pass

    prev = wiringpi2.digitalRead(clock_pin)

  wiringpi2.digitalWrite(data_pin, 1)
  wiringpi2.pinMode(data_pin, 0)
  wiringpi2.delay(delay)
コード例 #43
0
ファイル: tempcontrol.py プロジェクト: chslion/raspy
    def run_event(self):
        time = self.time()

        temp = self._read_temp()
        if temp is None:
            self.loge("Failed to read CPU temperature")
            return False

        pidout = int(self._pid.compute(temp))

        if not self._autocontrol:
            self._fan_setpwm(self._userpwm)
        else:
            if self._ecomode:
                # should we leave eco mode?
                # yes if temp >= profile
                if temp >= self.get_profile():
                    self._ecomode = False
                    # turn on full speed
                    self._fan_fullspeed()
                    wiringpi2.delay(self.FAN_SPINUP)
                    self._fan_setpwm(pidout)
                else:
                    # turn(keep) fan off
                    self._fan_stop()
            else:
                # should we enter eco mode
                # yes if temp < profile - threshold
                if temp < (self.get_profile() - self.ECO_THRESHOLD):
                    self._ecomode = True
                    # turn off
                    self._fan_stop()
                else:
                    self._fan_setpwm(pidout)

        # log pwm as percent
        fanspeed = 100 * self._pwm / (self.PWM_RANGE - 1)
        self._speedlog.log(time.jstimestamp(), fanspeed)
        self._templog.log(time.jstimestamp(), temp)
        return True
コード例 #44
0
ファイル: RPiMusic.py プロジェクト: RaspberryLove/RPiMusic
    def _playLoop(self, freq, music):
        divisor = (19.2*(10**3))/freq
        Music = import_module(music)

        wiringpi2.pwmSetClock(int(divisor))

        for note, beat in Music.melody:
            if note == ' ':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
            else:
                period, dutyCycle = self._calcParams(note)
                wiringpi2.pwmSetRange(period)
                wiringpi2.pwmWrite(self.SPEAKER, dutyCycle)

            wiringpi2.delay(Music.tempo*beat)

            if note[len(note)-1:] == ':':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
                wiringpi2.delay(Music.tempo)
            elif note[len(note)-1:] == ';':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
                wiringpi2.delay(int(Music.tempo/2))

        # Make sure that music stop
        wiringpi2.pwmWrite(self.SPEAKER, 0)
コード例 #45
0
def dSPIN_init():
    err = 0;
    err = wp.wiringPiSetupGpio();
    wp.pinMode(hd.dSPIN_BUSYN, wp.GPIO.INPUT);
    wp.pinMode(hd.dSPIN_RESET, wp.GPIO.OUTPUT);
    wp.pinMode(hd.dSPIN_CS, wp.GPIO.OUTPUT);
    wp.digitalWrite(hd.dSPIN_CS, wp.GPIO.HIGH);

    if( err !=0):
        print("wiringPi Setup failed with Error"+err);
        return hd.dSPIN_STATUS_FATAL;
    wp.pinMode(hd.dSPIN_MOSI, wp.GPIO.OUTPUT);
    wp.pinMode(hd.dSPIN_MISO, wp.GPIO.INPUT);
    wp.pinMode(hd.dSPIN_CLK,  wp.GPIO.OUTPUT);

    # //SPI_MODE3 (clock idle high, latch data on rising edge of clock)
    wp.digitalWrite(hd.dSPIN_CLK, wp.GPIO.HIGH);

    # // reset the dSPIN chip. This could also be accomplished by
    # //  calling the "dSPIN_ResetDev()" function after SPI is initialized.
    wp.digitalWrite(hd.dSPIN_RESET, wp.GPIO.HIGH);
    wp.delay(2);
    wp.digitalWrite(hd.dSPIN_RESET, wp.GPIO.LOW);
    wp.delay(2);
    wp.digitalWrite(hd.dSPIN_RESET, wp.GPIO.HIGH);
    wp.delay(2);


    return 0;
コード例 #46
0
ファイル: RPiMusic.py プロジェクト: DEPlayground/RPiMusic
    def _playLoop(self, freq, music):
        divisor = (19.2 * (10**3)) / freq
        Music = import_module(music)

        wiringpi2.pwmSetClock(int(divisor))

        for note, beat in Music.melody:
            if note == ' ':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
            else:
                period, dutyCycle = self._calcParams(note)
                wiringpi2.pwmSetRange(period)
                wiringpi2.pwmWrite(self.SPEAKER, dutyCycle)

            wiringpi2.delay(Music.tempo * beat)

            if note[len(note) - 1:] == ':':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
                wiringpi2.delay(Music.tempo)
            elif note[len(note) - 1:] == ';':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
                wiringpi2.delay(int(Music.tempo / 2))

        # Make sure that music stop
        wiringpi2.pwmWrite(self.SPEAKER, 0)
コード例 #47
0
    def callback(self, disconfort):
        if disconfort.data == 1:
            """
            if self.rest_counter < 200:
                return

            rospy.wait_for_service("serv_off")
            try:
                soff = rospy.ServiceProxy("serv_off", Empty)
                soff()
            except rospy.ServiceException, e:
                print "Service call failed: %s" % e
                
                
            self.hit_sound.play()
            """
            wiringpi2.pwmWrite(self.gp_out, self.LEFT)
            wiringpi2.delay(500)
            wiringpi2.pwmWrite(self.gp_out, self.RIGHT)
            wiringpi2.delay(500)
            wiringpi2.pwmWrite(self.gp_out, self.CENTER)
            wiringpi2.delay(500)

            try:
                son = rospy.ServiceProxy("serv_on", Empty)
                son()
            except rospy.ServiceException, e:
                print "Service call failed: %s" % e

            self.rest_counter = 0
コード例 #48
0
def unlock():
	print "Unlock Key"
	param = sys.argv
	setdegree = int(90)
	print setdegree

	wiringpi2.wiringPiSetupGpio()
	wiringpi2.pinMode(servopin,2)
	wiringpi2.pwmSetMode(wiringpi2.GPIO.PWM_MODE_MS)
	wiringpi2.pwmSetClock(375)

	wiringpi2.pwmWrite(servopin,133)
	for i in range(133,73-1,1):
	  print i
	  wiringpi2.pwmWrite(servopin, i)
	  wiringpi2.delay(500)
	
	

	wiringpi2.pwmWrite(servopin,26)
	wiringpi2.delay(500)
	wiringpi2.pwmWrite(servopin,74)
コード例 #49
0
def slow_shift_out(data_pin, clock_pin, data):
  for bit in bin(data).replace('0b','').rjust(8,'0'):
    wiringpi.digitalWrite(clock_pin,LOW)
    wiringpi.delay(SLOW_DOWN)
    wiringpi.digitalWrite(data_pin,int(bit))
    wiringpi.delay(SLOW_DOWN)
    wiringpi.digitalWrite(clock_pin,HIGH)
    wiringpi.delay(SLOW_DOWN)
コード例 #50
0
def slow_shift_out(data_pin, clock_pin, data):
    for bit in bin(data).replace('0b', '').rjust(8, '0'):
        wiringpi.digitalWrite(clock_pin, LOW)
        wiringpi.delay(SLOW_DOWN)
        wiringpi.digitalWrite(data_pin, int(bit))
        wiringpi.delay(SLOW_DOWN)
        wiringpi.digitalWrite(clock_pin, HIGH)
        wiringpi.delay(SLOW_DOWN)
コード例 #51
0
def arduinoListen():
  global wiringpi2
  global arduinoIn
  global arduino

  wiringpi2.wiringPiSetup()
  arduino = wiringpi2.serialOpen("/dev/ttyACM0", 9600)
  wiringpi2.delay(250)
  wiringpi2.pinMode(0,1)
  wiringpi2.digitalWrite(0, 1)

  arduinoInReady.acquire()
  arduinoListenerReady.set()
  while(True):
    while(True):
      if(wiringpi2.serialDataAvail(arduino) > 0):
        arduinoIn = chr(wiringpi2.serialGetchar(arduino))
        arduinoInReady.release()
        time.sleep(0.5)
        break
      else:
        time.sleep(0.5)
    arduinoInReady.acquire()
コード例 #52
0
    def _genimage(*img):

        inputt = img[1]

        a = mpimg.imread(inputt)
        a = 1 * (a > 0)
        #     for i in range(0,len(a)):
        #         pin=65
        #         for j in range(0,32):
        #             print ( pin ,'=',a[i,j,1])
        #             pin+=1

        # print len(a)
        for i in range(0, len(a)):
            pin = 65
            for j in range(0, 32):
                wiringpi2.digitalWrite(pin, int(a[i, j, 1]))
                pin = pin + 1
            wiringpi2.delay(65)

        for pin in range(65, 97):
            wiringpi2.digitalWrite(pin, 0)
        wiringpi2.delay(800)
コード例 #53
0
ファイル: ttg.py プロジェクト: BenSchomp/Tic-Tac-GPIO
def gameTiedAnimation():
    wiringpi.delay(LONG_PAUSE)

    # flip the colors back and forth
    for i in range(0, 3):
        drawBoard(True)
        wiringpi.delay(MED_PAUSE)

        drawBoard()
        wiringpi.delay(MED_PAUSE)
コード例 #54
0
ファイル: tempcontrol.py プロジェクト: chslion/raspy
    def _find_minspeed(self):
        # get idle load
        self._fan_stop()
        wiringpi2.delay(self.FAN_SPINUP)

        # find minimum
        self._idleload = self._read_fanload()

        # get full speed load
        self._fan_fullspeed()
        wiringpi2.delay(self.FAN_SPINUP)
        self._maxload = self._read_fanload() - self._idleload

        # find lowest pwm
        # 50% of maxload
        load_min = self._maxload * self.FAN_THRESHOLD
        # from highest to lowest
        minpwm = self.PWM_RANGE - 1
        while minpwm != 0:
            self._fan_setpwm(minpwm)
            wiringpi2.delay(500)
            load = self._read_fanload() - self._idleload
            if load < load_min:
                break
            minpwm -= self.FAN_RECAL_PWM

        # turn fan off again
        self._fan_stop()

        if minpwm >= self.FAN_DEAD_PWM:
            self.loge("RIP FAN. It seems to be dead!")
            return False

        # update controller
        self._pid.set_coeff(self.PID_P, self.PID_I, self.PID_D)
        self._pid.set_limit(minpwm, self.PWM_RANGE - 1)

        # update minspeed
        self._minpwm = minpwm
        self._minspeed = 100 * minpwm / (self.PWM_RANGE - 1)
        self._caltime = self.time().jstimestamp()
        return True
コード例 #55
0
ファイル: HardPwm.py プロジェクト: masterky/Python-RCCarRepo
def softPwm():
	print "SoftPwm Mode"

	wiringpi2.wiringPiSetup()
	wiringpi2.pinMode(PIN_TO_PWM,SET_PWM)
	wiringpi2.pwmSetMode(PWM_MODE_MS)	
	#wiringpi2.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters
	#wiringpi2.softServoSettup()
	#softServoWrite()
	while True:
		for i in range(900, 1000):
			wiringpi2.pwmWrite(PIN_TO_PWM, i) 	
			wiringpi2.delay(150)
			print "Write to PWM: ", i
		for k in reversed(range(800, 1000)):
			wiringpi2.pwmWrite(PIN_TO_PWM, k) 	
			wiringpi2.delay(150)
			print "Write to PWM: ", k
		for i in range(800, 900):
			wiringpi2.pwmWrite(PIN_TO_PWM, i) 	
			wiringpi2.delay(150)
			print "Write to PWM: ", i
コード例 #56
0
ファイル: pwm.py プロジェクト: tomxue/Pi___LED-control
# softPwm uses a fixed frequency
import wiringpi2

OUTPUT = 1

# GPIO17 = GPIO_GEN0 = P1.11, connecting a red led
PIN_TO_PWM = 0

wiringpi2.wiringPiSetup()
wiringpi2.pinMode(PIN_TO_PWM,OUTPUT)
wiringpi2.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters

for time in range(0,4):
        for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on
                wiringpi2.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle
                wiringpi2.delay(10) # Delay for 0.2 seconds
        for brightness in reversed(range(0,100)):
                wiringpi2.softPwmWrite(PIN_TO_PWM,brightness)
                wiringpi2.delay(10)
コード例 #57
0
def emitData():
    # Délai nécessaire pour que le serveur ait le temps de démarrer
    wiringpi2.delay(5000)
    while True: loop() # appelle fonction loop sans fin
コード例 #58
0
ファイル: pwm_clk.py プロジェクト: Dzenik/WiringCB-python
import wiringpi2
import sys
pin = 31

#wiringpi2.wiringPiSetup()
#wiringpi2.wiringPiSetupSys()
#wiringpi2.wiringPiSetupGpio()
wiringpi2.wiringPiSetupPhys()
wiringpi2.pinMode(pin,2)  #PWM_OUTPUT

while 1:
	#wiringpi2.pwmWrite(pin,128)
	print "===== set clock"
	wiringpi2.pwmSetClock(0) # 24M/120 * 256 = 781HZ 
	wiringpi2.delay(1000)
	wiringpi2.pwmSetClock(1);# 24M/180 * 256 = 520.8HZ 
	wiringpi2.delay(1000)
	wiringpi2.pwmSetClock(2);# 24/240 * 256 = 390HZ
	wiringpi2.delay(1000)
	#wiringpi2.pwmSetRange(255);
#	wiringpi2.pwmWrite(pin,1);
#	wiringpi2.delay(1000)
#	wiringpi2.pwmWrite(pin,128);
#	wiringpi2.delay(1000)
#	wiringpi2.pwmWrite(pin,255)
#	wiringpi2.delay(1000)
#	print "================>>>>"
#	pwmSetMode(0);
	#wiringpi2.pwmWrite(pin,128)
コード例 #59
0
import wiringpi2 as wiringpi
INPUT = 0
OUTPUT = 1
LOW = 0
HIGH = 1
BUTTONS = [13, 12, 10, 11]
LEDS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
PUD_UP = 2

wiringpi.wiringPiSetup()

for button in BUTTONS:
    wiringpi.pinMode(button, INPUT)
    wiringpi.pullUpDnControl(button, PUD_UP)

for led in LEDS:
    wiringpi.pinMode(led, OUTPUT)

while 1:
    for index, button in enumerate(BUTTONS):
        button_state = wiringpi.digitalRead(button)
        first_led = LEDS[index * 2]
        second_led = LEDS[(index * 2) + 1]
        #print str(button) + ' ' + str(button_state)
        wiringpi.digitalWrite(first_led, 1 - button_state)
        wiringpi.digitalWrite(second_led, 1 - button_state)
    wiringpi.delay(20)
コード例 #60
0
ファイル: spkTST-DMA.py プロジェクト: RaspberryLove/GPIO.OLD
# 4) Divisor do clock
# divisor = clock base / frequencia de afinação
# Tendo que o clock base do pwm é 19.2mhz:
# divisor = (19.2x1000)/440
# divisor = 43.6363636364

divisor = (19.2*(10**3))/440
wiringpi2.pwmSetClock(int(divisor))

def calcParams(freq):
   period = (1/freq)*(10**6)
   dutyCycle = period/2
   return (int(period), int(dutyCycle))

try:
    while True:
        for freq in range(500, 1001, 1):
            period, dutyCycle = calcParams(freq)
            wiringpi2.pwmSetRange(period)
            wiringpi2.pwmWrite(SPEAKER, dutyCycle)
            wiringpi2.delay(1)
        for freq in range(1000, 499, -1):
            period, dutyCycle = calcParams(freq)
            wiringpi2.pwmSetRange(period)
            wiringpi2.pwmWrite(SPEAKER, dutyCycle)
            wiringpi2.delay(1)
except KeyboardInterrupt:
    wiringpi2.pwmWrite(SPEAKER, 0)
    wiringpi2.pinMode(SPEAKER, 0)
    exit(0)