def initGPIO(): for pin in range(0, 4): io.pinMode(sensorPins[pin], 0) # input io.pullUpDnControl(sensorPins[pin], 2) # activate pull ups io.pinMode(shutDownPin, 0) # input io.pullUpDnControl(shutDownPin, 2) # activate pull ups pixels.begin() # This initialises the NeoPixel library.
def __init__(self): wp.wiringPiSetup() #left 23017, for audio wp.mcp23017Setup( PB1,0x20) for pin in OUTPUT_PINS_1: wp.pinMode(pin,OUTPUT) for pin in INPUT_PINS_1: wp.pinMode(pin, INPUT) #right 23017 for 230v switching wp.mcp23017Setup( PB2,0x21) for pin in OUTPUT_PINS_2: wp.pinMode(pin,OUTPUT) for pin in INPUT_PINS_2: wp.pullUpDnControl(pin,PUD_UP) wp.pinMode(pin, INPUT) #display wp.digitalWrite(70,0) # write mode self.display1 = wp.lcdInit(2,16,8, 71,69,72,73,74,75,76,77,78,79) #connected to first expander wp.lcdClear(self.display1) #pwm driver self.pwm = PWM() self.pwm.setPWMFreq(200)
def initPorts(): # # define constants # INPUT = 0 OUTPUT = 1 PUD_UP = 2 # # use Broadcom GPIO pin scheme # gpio.wiringPiSetupGpio() # comparator output is PGOOD - needs pull-up # gpio.pinMode(PGOOD, INPUT) gpio.pullUpDnControl(PGOOD, PUD_UP) # # gpio.pinMode(CSb, OUTPUT) gpio.pinMode(UDb, OUTPUT) # # cs* -> 1 to deselect; USb is don't care # gpio.digitalWrite(CSb, 1) return
def initPorts(): # # define constants # INPUT = 0 OUTPUT = 1 PUD_UP = 2 # # use Broadcom GPIO pin scheme # gpio.wiringPiSetupGpio() # comparator output is PGOOD - needs pull-up # gpio.pinMode(PGOOD,INPUT) gpio.pullUpDnControl(PGOOD,PUD_UP) # # gpio.pinMode(CSb,OUTPUT) gpio.pinMode(UDb,OUTPUT) # # cs* -> 1 to deselect; USb is don't care # gpio.digitalWrite(CSb,1) return
def initGPIO(): try : io.wiringPiSetupGpio() except : print"start IDLE with 'gksudo idle' from command line" os._exit(1) for pin in range (0,len(pinList)): io.pinMode(pinList[pin],0) # make pin into an input io.pullUpDnControl(pinList[pin],2) # enable pull up
def initGPIO(): try: io.wiringPiSetupGpio() except: print "start IDLE with 'gksudo idle' from command line" os._exit(1) for pin in range(0, 4): io.pinMode(tiltPins[pin], 0) # mux pin to output io.pullUpDnControl(tiltPins[pin], 2) # input enable pull up
def Init(): global on, timeOfLastChange wiringpi.wiringPiSetupGpio() wiringpi.pinMode(27, 1) wiringpi.pullUpDnControl(27, 1) wiringpi.digitalWrite(27, 1) # switch on LEDs on = True timeOfLastChange = time.time() procComms.PrintLog('Switched on LEDs.')
def initGPIO(): try: io.wiringPiSetupGpio() except: print "start IDLE with 'gksudo idle' from command line" os._exit(1) for player in range(0, 2): for pin in range(0, 4): io.pinMode(ballPins[player][pin], 0) io.pullUpDnControl(ballPins[player][pin], 2) # input enable pull up
def setup(self): if wiringpi2.wiringPiSPISetup(0, 900000) == -1: return False # disable nss pullups wiringpi2.pullUpDnControl(self.ADC_NSS, wiringpi2.GPIO.PUD_OFF) # cycle NSS to ensure state in adc chip self._adc_deselect() self._adc_select() self._adc_deselect() return True
def __init__(self, startPin, startAction, stopPin, stopAction): wpi.wiringPiSetup() wpi.pinMode(startPin, wpi.GPIO.INPUT) wpi.pullUpDnControl(startPin, wpi.GPIO.PUD_UP) wpi.wiringPiISR(startPin, wpi.GPIO.INT_EDGE_FALLING, self.startTrigger) wpi.pinMode(stopPin, wpi.GPIO.INPUT) wpi.pullUpDnControl(stopPin, wpi.GPIO.PUD_UP) wpi.wiringPiISR(stopPin, wpi.GPIO.INT_EDGE_FALLING, self.stopTrigger) self.startAction = startAction self.stopAction = stopAction self.newEvent = False self.latestEvent = ''
def __init__(self): # button wiringpi2.pinMode(self.BUTTON_PIN, wiringpi2.GPIO.INPUT) wiringpi2.pullUpDnControl(self.BUTTON_PIN, wiringpi2.GPIO.PUD_UP) wiringpi2.wiringPiISR(self.BUTTON_PIN, wiringpi2.GPIO.INT_EDGE_BOTH, self.button_raw_press) self.button_callback = None # hardware PWM led wiringpi2.pinMode(self.LED_PIN, wiringpi2.GPIO.PWM_OUTPUT) self.thread_pwm_worker = Thread(target=self.pwm_worker) self.thread_pwm_worker.setDaemon(True) self.pwm_worker_working = False self.button_pressed = 0
def __init__(self): self.log = logging.getLogger(__name__) # Setup GPIO pins # This routine uses /sys/class/gpio for non-root access. # Attention: export all pins beforehand (done by launcher.sh at the moment) wiringpi2.wiringPiSetupSys() # Inputs for key, value in self.PINS.items(): self.log.debug('Setting up pin %d for "%s"', value, key) # Set input mode wiringpi2.pinMode(value, self.GPIO_INPUT) # Pull pin down to ground wiringpi2.pullUpDnControl(value, self.GPIO_PUD_DOWN)
def initGPIO(): try: io.wiringPiSetupGpio() except: print "start IDLE with 'gksudo idle' from command line" os._exit(1) for pin in range(0, 3): io.pinMode(muxPins[pin], 1) # mux pin to output io.pinMode(startPush, 0) # start / stop input io.pinMode(modePush, 0) # mode input io.pullUpDnControl(startPush, 2) # input enable pull up io.pullUpDnControl(modePush, 2) # input enable pull up io.mcp3002Setup(70, 0)
def RCTime(self,pin=11,wiring=True,short=False): duration=0 #not sure if the GPIO version of this translation works, #so keep using Wiringpi version if wiring==True: #initQTI() #make pin output wp.pinMode(pin,1) #set pin to high to discharge capacitor wp.digitalWrite(pin,1) #wait 1 ms time.sleep(0.001) #make pin Input wp.pinMode(pin,0) #turn off internal pullups #wp.digitalWrite(pin,0) wp.pullUpDnControl(pin,1) #print "here" if short == True: while wp.digitalRead(pin)==1 and duration < self.rightTail: #wait for the pin to go Low #print pin, wp.digitalRead(pin) #print 'not yet' duration+=1 else: while wp.digitalRead(pin)==1 and duration <self.cap: # while wp.digitalRead(pin)==1: #print "here" duration+=1 #print duration #wp.pinMode(pin,1) #wp.digitalWrite(pin,1) else: GPIO.setup(pin,GPIO.OUT) #set pin to high to discharge capacitor GPIO.output(pin,GPIO.LOW) #wait 1 ms time.sleep(0.1) #make pin Input GPIO.setup(pin,GPIO.IN) #GPIO.setup(pin,GPIO.IN,GPIO.PUD_DOWN) #turn off internal pullups while GPIO.input(pin)== GPIO.LOW: #wait for the pin to go Low #print GPIO.input(sensorIn) duration+=1 #print duration, pin return duration
def __init__(self, pinmap): try: import wiringpi2 self.gpio = wiringpi2.GPIO(wiringpi2.GPIO.WPI_MODE_GPIO) except: raise IOError("Could not export the GPIO pins. Make sure that you have the wiringpi2 library installed, run as root and are on a Raspberry Pi.") self.pinmap = dict([(key, value if type(value) in [list, tuple] else (value, False, 1)) for key, value in pinmap.iteritems()]) self.reverse_pinmap = dict([(value[0], key) for key, value in self.pinmap.iteritems()]) for name, pin_data in self.pinmap.iteritems(): pin, output, pullup = pin_data setattr(self, 'PIN_%s' % name, pin) self.gpio.pinMode(pin, self.gpio.OUTPUT if output else self.gpio.INPUT) if pullup != 0: wiringpi2.pullUpDnControl(pin, wiringpi2.PUD_UP if pullup > 0 else wiringpi2.PUD_DOWN)
def initGPIO(): global ledPins, pirPins ledPins = [4, 17, 27, 22] # left R, left G, right R, right G pirPins = [18, 23] # left / right try: io.wiringPiSetupGpio() except: print "start IDLE with 'gksudo idle' from command line" os._exit(1) for pin in range(0, 4): io.pinMode(ledPins[pin], 1) # led pin to output io.digitalWrite(ledPins[pin], 1) # turn off io.pinMode(pirPins[0], 0) # input left PIR sensor io.pinMode(pirPins[1], 0) # input right PIR sensor io.pullUpDnControl(pirPins[0], 2) # input enable pull up io.pullUpDnControl(pirPins[1], 2) # input enable pull up
def __init__(self): # $U3 = X # $U4 = Y #dir connected to pin 11(BCM17), step to pin 13(BCM27), enable to pin 15(BCM22) self.y = pololu.Pololu(pololu.Pins(enable=22, direction=17,step=27)) #dir connected to pin 16(BCM23), step to pin 18(BCM24), enable to pin 22(BCM25) self.x = pololu.Pololu(pololu.Pins(enable=25, direction=23,step=24)) self.x.speed = 120 self.y.speed = 120 self.xcoord = 0 self.ycoord = 0 self.Movement = Movements self.movement = Movements.NONE GPIO.setmode(GPIO.BCM) #GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP) #GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP) #GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP) #GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP) #interrupt GPIO.setup(19,GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(19, GPIO.FALLING, callback=self.callback) self.i2c = wp.I2C() self.dev = self.i2c.setup(i2c_addr) wp.wiringPiSetup() wp.mcp23016Setup(pinbase, i2c_addr) self.state =0 #wp.pinMode(19,0) #wp.pullUpDnControl(19,2) for i in range(65,73): wp.pinMode(i,1) wp.pullUpDnControl(i,2) for i in range(73,81): wp.pinMode(i,0)
def hello(): global timeCountSecurityOn if timeCountSecurityOn > -1: timeCountSecurityOn+=1 if timeCountSecurityOn > 300: slack = Slacker(slackbot_settings.API_TOKEN) slack.chat.post_message('general','現在警備中であります 特に異常なし (`・ω・́)ゝ ') timeCountSecurityOn = 0 else: timeCountSecurityOn = -1 buttonPin = 4 # GPIO初期化 w.wiringPiSetupGpio() # GPIOを出力モード(1)に設定 w.pinMode(buttonPin,0) # 端子に何も接続されていない場合の状態を設定 # 3.3Vの場合には「2」(プルアップ) # 0Vの場合は「1」と設定する(プルダウン) w.pullUpDnControl(buttonPin,2) global sensorCheck global sensorCheckOld if( w.digitalRead(buttonPin) == 0 ): print ("Switch ON") sensorCheck = 0 else: print ("Switch OFF ACTIVE ACTIVE") sensorCheck = 1 if (timeCountSecurityOn > -1) and (not sensorCheckOld == sensorCheck) and (sensorCheck == 1): slack = Slacker(slackbot_settings.API_TOKEN) slack.chat.post_message('general','センサー検知発生') sensorCheckOld = sensorCheck print("現在のスレッドの数: " + str(threading.activeCount())) print("[%s] helohelo!!" % threading.currentThread().getName()) t=threading.Timer(1,hello) t.start()
def read(self): wpi.pinMode(self.__pin, wpi.GPIO.OUTPUT) # send initial high self.__send_and_sleep(wpi.GPIO.HIGH, 0.05) # pull down to low self.__send_and_sleep(wpi.GPIO.LOW, 0.02) # change to input using pull up wpi.pinMode(self.__pin, wpi.GPIO.INPUT) wpi.pullUpDnControl(self.__pin, 2) # collect data into an array data = self.__collect_input() # parse lengths of all data pull up periods pull_up_lengths = self.__parse_data_pull_up_lengths(data) # if bit count mismatch, return error (4 byte data + 1 byte checksum) if len(pull_up_lengths) != 40: return DHT11Result(DHT11Result.ERR_MISSING_DATA, 0, 0) # calculate bits from lengths of the pull up periods bits = self.__calculate_bits(pull_up_lengths) # we have the bits, calculate bytes the_bytes = self.__bits_to_bytes(bits) # calculate checksum and check checksum = self.__calculate_checksum(the_bytes) if the_bytes[4] != checksum: return DHT11Result(DHT11Result.ERR_CRC, 0, 0) # ok, we have valid data, return it return DHT11Result(DHT11Result.ERR_NO_ERROR, the_bytes[2], the_bytes[0])
def initGPIOPins(): print "Init GPIO pins..." # Set up GPIO pins wiringpi.wiringPiSetup() # use wiringpi pin numbers wiringpi.pinMode(switch_1, 0) # input wiringpi.pullUpDnControl(switch_1, 2) wiringpi.pinMode(switch_2, 0) # input wiringpi.pullUpDnControl(switch_2, 2) wiringpi.pinMode(switch_3, 0) # input wiringpi.pullUpDnControl(switch_3, 2) wiringpi.pinMode(switch_4, 0) # input wiringpi.pullUpDnControl(switch_4, 2) # I couldnt seem to get at pin 252 for the backlight using the usual method above, # but this seems to work os.system("echo 252 > /sys/class/gpio/export") os.system("echo 'out' > /sys/class/gpio/gpio252/direction") os.system("echo '1' > /sys/class/gpio/gpio252/value")
def Main(): procComms.PrintLog('Initializing...') # init pins as pulled down inputs wiringpi.wiringPiSetupGpio() for pin in dataPins: wiringpi.pinMode(pin, 0) wiringpi.pullUpDnControl(pin, 1) wiringpi.pullUpDnControl(24, 2) for pin in addrPins: wiringpi.pinMode(pin, 0) wiringpi.pullUpDnControl(pin, 2) # init segment-to-number translators digits = [ SevenSeg(Seg(4,6), Seg(3,6), Seg(2,6), Seg(1,6), Seg(4,5), Seg(3,5), Seg(2,5)), SevenSeg(Seg(4,3), Seg(3,3), Seg(2,3), Seg(1,3), Seg(4,4), Seg(3,4), Seg(2,4)), SevenSeg(Seg(4,1), Seg(3,1), Seg(2,1), Seg(1,1), Seg(4,2), Seg(3,2), Seg(2,2))] # every sampling period, poll every digit samplingPeriod = 0.1 while keepRunning: time.sleep(samplingPeriod) # sample inputs for dig in digits: dig.Poll() depth = '' depth = digits[0].GetChar() + digits[1].GetChar() + digits[2].GetChar() procComms.PrintData(depth) # procComms.PrintLog('Depth ' + str(depth)) tmpStr = '' for dig in digits: tmpStr += str(dig.GetSegments())
return False # --------------------------------------------------------------------- # Init framebuffer/touchscreen environment variables os.putenv('SDL_VIDEODRIVER', 'fbcon') os.putenv('SDL_FBDEV' , '/dev/fb1') os.putenv('SDL_MOUSEDRV' , 'TSLIB') os.putenv('SDL_MOUSEDEV' , '/dev/input/touchscreen') # Set up GPIO pins wiringpi.wiringPiSetup() # use wiringpi pin numbers wiringpi.pinMode(switch_1,0) # input wiringpi.pullUpDnControl(switch_1, 2) wiringpi.pinMode(switch_2,0) # input wiringpi.pullUpDnControl(switch_2, 2) wiringpi.pinMode(switch_3,0) # input wiringpi.pullUpDnControl(switch_3, 2) wiringpi.pinMode(switch_4,0) # input wiringpi.pullUpDnControl(switch_4, 2) # Init pygame and screen pygame.init() pygame.mouse.set_visible(False) size = pygame.display.list_modes(16)[0] # get screen size #print "size: {}".format(size) #screen = pygame.display.set_mode(size, FULLSCREEN, 16)
self.state = state if __name__ == '__main__': GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP) instance = Callbacks() GPIO.add_event_detect(19, GPIO.FALLING, callback=instance.mycallback) #interrupt of mcp23016 is opendrain wp.wiringPiSetup() wp.mcp23016Setup(pinbase, i2c_addr) for i in range(65,81): wp.pinMode(i,1) wp.pullUpDnControl(i,2) wp.pinMode(73,0)#pin 0 input wp.pullUpDnControl(73,0)#pull none wp.pinMode(74,0)#input wp.pinMode(65, 1)#pin 65 output wp.digitalWrite(65, 1)#pin 65 high time.sleep(.5) #wp.pinMode(66, 0)#pin 66 input #wp.pullUpDnControl(66,2) while(1):
import wiringpi2 as wp2 from time import sleep wp2.wiringPiSetup() #initalize pin7 to output garagepin = 7 #bcm gpio4 #header7 wp2.digitalWrite(garagepin, 1) wp2.pinMode(garagepin, 1) magpin = 1 #bcm gpio18 #header12 wp2.pinMode(magpin, 0) wp2.pullUpDnControl(magpin, 2) def garagebutton(): global garagepin wp2.digitalWrite(garagepin, 0) sleep(1) wp2.digitalWrite(garagepin, 1) print "Button Pressed!") def relayon(): global garagepin wp2.digitalWrite(garagepin, 0) print "Relay On" def relayoff(): global garagepin wp2.digitalWrite(garagepin, 1) print "Relay Off" def checkstate():
def initGPIO(): for pin in range(0, len(pinList)): io.pinMode(pinList[pin], 0) io.pullUpDnControl(pinList[pin], 2) # input enable pull up
# # define some constants # INPUT = 0 INT_EDGE_FALLING = 1 PUD_UP = 2 # # use Broadcom GPIO pin scheme # gpio.wiringPiSetupGpio() # setup pins as input with pull-up # gpio.pinMode(D1m,INPUT) gpio.pullUpDnControl(D1m,PUD_UP) gpio.pinMode(D2m,INPUT) gpio.pullUpDnControl(D2m,PUD_UP) # # D2m is PowerApplied, D1m is Charging # #if gpio.digitalRead(D2m): # os.system('logger chargeStatus:PowerApplied is false') #else: # os.system('logger chargeStatus:PowerApplied is true') #if gpio.digitalRead(D1m): # os.system('logger chargeStatus:Charging is false') #else: # os.system('logger chargeStatus:Charging is true') #
def initGPIO(): GPIO.wiringPiSetup() GPIO.pullUpDnControl(DQ, PULL_UP)
def GPIOsetup(self): wiringpi2.wiringPiSetupPhys() for gpio in self.pins: wiringpi2.pinMode(gpio,IN) wiringpi2.pullUpDnControl(gpio,PULL_UP)
pinLedStripRed = 19 pinLedStripGreen = 21 pinLedStripBlue = 23 pinFan = 29 # gpio mode 21 out, gpio write 21 1 to shut them off pinWiringTaskSolved = 3 pin3CoinsInserted = 5 pinSpaceInvadersSolved = 7 pinBellTaskSolved = 11 # LOW is solved! # free communication to mega pin --> pin 13 pinReset = 15 #wire it with level converter #GPIO pin setup GPIO.pinMode(pinUp, 0) GPIO.pullUpDnControl(pinUp, 2) GPIO.pinMode(pinRight, 0) GPIO.pullUpDnControl(pinRight, 2) GPIO.pinMode(pinLeft, 0) GPIO.pullUpDnControl(pinLeft, 2) GPIO.pinMode(pinDown, 0) GPIO.pullUpDnControl(pinDown, 2) GPIO.pinMode(pinShoot, 0) GPIO.pullUpDnControl(pinShoot, 2) GPIO.pinMode(pinReady, 0) GPIO.pullUpDnControl(pinReady, 2) GPIO.pinMode(pinWiringTaskSolved, 0) GPIO.pullUpDnControl(pinWiringTaskSolved, 2) GPIO.pinMode(pinWiringDoorOcto, 0)
# along with this program. If not, see <http://www.gnu.org/licenses/>. # import wiringpi2 as wiringpi # Define constants INPUT, OUTPUT = LOW, HIGH = OFF, ON = [0, 1] BUTTONS = [0,1,2,3,4] PIN_BASE = 64 I2C_ADDR = 0x20 PUD_UP=2 # Initialize wiringpi to use mcp23017 GPIO expansion chip wiringpi.wiringPiSetup() wiringpi.mcp23017Setup(PIN_BASE,I2C_ADDR) for button in BUTTONS: wiringpi.pinMode(PIN_BASE + button,INPUT) wiringpi.pullUpDnControl(PIN_BASE + button,PUD_UP) # Main loop to capture button try: while 1: for index,button in enumerate(BUTTONS): button_state = wiringpi.digitalRead(PIN_BASE + button) if button_state == OFF: print "button (%d) %d = %d" % (PIN_BASE + button, index, button_state) wiringpi.delay(20) except KeyboardInterrupt: pass
import wiringpi2 wiringpi2.mcp23017Setup(100, 0x20) wiringpi2.mcp23017Setup(200, 0x21) wiringpi2.mcp23017Setup(300, 0x22) wiringpi2.mcp23017Setup(400, 0x23) wiringpi2.mcp23017Setup(500, 0x24) for i in range(100, 115+1): #print "setting input %s", str(i) wiringpi2.pinMode(i, 0) #0 = input wiringpi2.pullUpDnControl(i, 2) #2 = pull up for i in range(200, 208+1): #print "setting input %s", str(i) wiringpi2.pinMode(i, 0) #0 = input wiringpi2.pullUpDnControl(i, 2) #2 = pull up out = "" out2 = "" for i in range(100, 115+1): out += str(wiringpi2.digitalRead(i)) + " " out2 += str(i) + " " #out += "%s = %s" % ( i, wiringpi2.digitalRead(i) ) print out2 print out
def __init__(self): wp.wiringPiSetupGpio() wp.pinMode(22, 0) wp.pullUpDnControl(22, 2)
wiringpi2.wiringPiSetupGpio() wiringpi2.pinMode(LED_PIN, wiringpi2.GPIO.PWM_OUTPUT) # hardware PWM mode wiringpi2.pinMode(LIGHTS_PIN, wiringpi2.GPIO.PWM_OUTPUT) # hardware PWM mode count = 0 def button_raw_press(): # simple debounce with busy-waiting time.sleep(DEBOUNCE_MS // 1000) if not wiringpi2.digitalRead(BUTTON_PIN): global count count += 1 print("BUTTON PRESS: %d" % (count)) wiringpi2.pinMode(BUTTON_PIN, wiringpi2.GPIO.INPUT) wiringpi2.pullUpDnControl(BUTTON_PIN, wiringpi2.GPIO.PUD_UP) wiringpi2.wiringPiISR(BUTTON_PIN, wiringpi2.GPIO.INT_EDGE_BOTH, button_raw_press) try: while True: for i in xrange(LED_DUTY_MIN, LED_DUTY_MAX + 1, LED_DUTY_STEP): wiringpi2.pwmWrite(LED_PIN, i) wiringpi2.pwmWrite(LIGHTS_PIN,i) time.sleep(0.02) time.sleep(1.5) for i in xrange(LED_DUTY_MAX, LED_DUTY_MIN - 1, -LED_DUTY_STEP): wiringpi2.pwmWrite(LED_PIN, i) wiringpi2.pwmWrite(LIGHTS_PIN,i)
import wiringpi2 import sys PUD_UP = 1 PUD_DOWN = 2 PUD_OFF = 0 pin =1 INPUT = 0 #wiringpi2.wiringPiSetup() wiringpi2.wiringPiSetupPhys() #wiringpi2.pinMode(pin,OUTPUT) wiringpi2.pinMode(pin,INPUT) while 1: wiringpi2.pullUpDnControl (pin, PUD_UP); val = wiringpi2.digitalRead(pin) print 'xxxxx UP' print val wiringpi2.delay(1000) wiringpi2.pullUpDnControl (pin, PUD_DOWN); val = wiringpi2.digitalRead(pin) print 'xxxxx DOWN' print val wiringpi2.delay(1000) wiringpi2.pullUpDnControl (pin, PUD_UP); val = wiringpi2.digitalRead(pin) print 'xxxxx UP' print val wiringpi2.delay(1000) wiringpi2.pullUpDnControl (pin, PUD_OFF);
import wiringpi2 as wiringpi import time from time import sleep import datetime import sys wiringpi.wiringPiSetup() wiringpi.pullUpDnControl(16, 1) # Setup sensor input wiringpi.pinMode(1, 3) # Function for getting the current speed def getSpeed(): currentTime = int(time.time()) currentTime = currentTime + 2 nextTime = -1 r = 0 while currentTime != nextTime: if wiringpi.digitalRead(16): off = False while off == False: if wiringpi.digitalRead(16) == False: off = True if off == True: r = r + 1 nextTime = int(time.time()) r = r/4 distance = (r * (6.25 / 2)) / 63360 # (rotations * circumference) / inches in a mile speed = distance * 3600 return speed
pin_base = 65 # lowest available starting number is 65 i2c_addr = 0x20 # A0, A1, A2 pins all wired to GND wiringpi.wiringPiSetup() # initialise wiringpi wiringpi.mcp23017Setup(pin_base, i2c_addr) # set up the pins and i2c address MCP_LED_WHITE = 65 MCP_LED_GREEN = 66 MCP_LED_RED = 67 wiringpi.pinMode(MCP_LED_WHITE, 1) # sets GPA0 to output wiringpi.digitalWrite(MCP_LED_WHITE, 0) # sets GPA0 to 0 (0V, off) wiringpi.pinMode(MCP_LED_GREEN, 1) wiringpi.digitalWrite(MCP_LED_GREEN, 0) wiringpi.pinMode(MCP_LED_RED, 1) wiringpi.digitalWrite(MCP_LED_RED, 0) sleep(1) wiringpi.digitalWrite(MCP_LED_WHITE, 1) sleep(1) wiringpi.digitalWrite(MCP_LED_GREEN, 1) sleep(1) wiringpi.digitalWrite(MCP_LED_RED, 1) sleep(1) wiringpi.digitalWrite(MCP_LED_WHITE, 0) wiringpi.digitalWrite(MCP_LED_GREEN, 0) wiringpi.digitalWrite(MCP_LED_RED, 0) wiringpi.pinMode(72, 0) # sets GPA7 to input wiringpi.pullUpDnControl(72, 2) # set internal pull-up
# # define some constants # INPUT = 0 INT_EDGE_FALLING = 1 PUD_UP = 2 # # use Broadcom GPIO pin scheme # gpio.wiringPiSetupGpio() # setup pins as inut with pull-up # gpio.pinMode(REQ_OFFb,INPUT) gpio.pullUpDnControl(REQ_OFFb,PUD_UP) # # get state of REQ_OFFb # if gpio.digitalRead(REQ_OFFb): os.system('logger monitorPS:REQ_OFF* is high') else: os.system('logger monitorPS:REQ_OFF* is low') # # register the interrupt handler # # poll for REQ_OFFb going low # while gpio.digitalRead(REQ_OFFb): time.sleep(.200)
pinLedStripRed = 19 pinLedStripGreen = 21 pinLedStripBlue = 23 pinFan = 29 # gpio mode 21 out, gpio write 21 1 to shut them off pinWiringTaskSolved = 3 pinFirstGameLost = 5 # LOW is solved! pinSpaceInvadersSolved = 7 # LOW is solved! pinBellTaskSolved = 11 # LOW is solved! pinInfinityMirrorOn = 15 # LOW is solved! pinReset = 13 #wire it with level converter #GPIO pin setup GPIO.pinMode(pinUp, 0) # GPIO.pullUpDnControl(pinUp, 2) GPIO.pinMode(pinRight, 0) GPIO.pullUpDnControl(pinRight, 2) GPIO.pinMode(pinLeft, 0) GPIO.pullUpDnControl(pinLeft, 2) GPIO.pinMode(pinDown, 0) GPIO.pullUpDnControl(pinDown, 2) GPIO.pinMode(pinShoot, 0) GPIO.pullUpDnControl(pinShoot, 2) GPIO.pinMode(pinReady, 0) GPIO.pullUpDnControl(pinReady, 2) GPIO.pinMode(pinWiringDoorOcto, 0) GPIO.pinMode(pinWiringPlugA, 1) GPIO.pinMode(pinWiringPlugB, 1)
import wiringpi2 as wiringpi import time wiringpi.wiringPiSetup() wiringpi.pinMode(26, 0) # Pinmode input wiringpi.pullUpDnControl(26, 2) # Internal pullup last_prog_sw = None last_call = False def prog_sw(): return wiringpi.digitalRead(26) counter = 1 while True: sw_state = prog_sw() if sw_state != last_prog_sw: time.sleep(0.1) sw_state = prog_sw() if sw_state != last_prog_sw and sw_state == 1: print("Switch is on!" + str(counter)) counter += 1 else: print("Switch is off!" + str(counter)) counter += 1 last_prog_sw = sw_state time.sleep(0.05)
import wiringpi2 import sys PUD_UP = 1 PUD_DOWN = 2 PUD_OFF = 0 pin = 1 INPUT = 0 #wiringpi2.wiringPiSetup() wiringpi2.wiringPiSetupPhys() #wiringpi2.pinMode(pin,OUTPUT) wiringpi2.pinMode(pin, INPUT) while 1: wiringpi2.pullUpDnControl(pin, PUD_UP) val = wiringpi2.digitalRead(pin) print 'xxxxx UP' print val wiringpi2.delay(1000) wiringpi2.pullUpDnControl(pin, PUD_DOWN) val = wiringpi2.digitalRead(pin) print 'xxxxx DOWN' print val wiringpi2.delay(1000) wiringpi2.pullUpDnControl(pin, PUD_UP) val = wiringpi2.digitalRead(pin) print 'xxxxx UP' print val wiringpi2.delay(1000) wiringpi2.pullUpDnControl(pin, PUD_OFF)
BRIGHTNESS_MAX = 1024 # How long should the LED take to go from 0 to 1 FADE_DURATION = 5 # How long after motion is detected do we believe there's no motion? NO_MOTION_DURATION = 5 # How many times per second should we read the GPIO? FREQUENCY = 20 MAX_STATUSES = 200 BRIGHTNESS_RANGE = BRIGHTNESS_MAX - BRIGHTNESS_MIN STEP = BRIGHTNESS_RANGE/FREQUENCY/FADE_DURATION wiringpi2.pinMode(MOTION_PIN, INPUT) wiringpi2.pullUpDnControl(MOTION_PIN, PUD_DOWN) wiringpi2.pinMode(LED_PIN, PWM_OUTPUT) brightness = BRIGHTNESS_MIN notifiedBrightness = 0 motionDetected = 0 notified = 0 recording = False recording_process = None formatted_date = None statuses = [] def add_video(string): with open(WEB_DIR + "/videos.txt", "a") as myfile: myfile.write("%s\n" % (string))
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)
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)
ROW8 = 7 #rows = [ROW1,ROW2,ROW3,ROW4,ROW5,ROW6,ROW7,ROW8] rows = [ROW1,ROW2,ROW3] wiringpi.wiringPiSetup() wiringpi.mcp23017Setup(pinBase,i2cAddr) #Setup pin mode for LEDs AS OUTPUTS wiringpi.pinMode(LED1,OUT) wiringpi.pinMode(LED2,OUT) wiringpi.pinMode(LED3,OUT) wiringpi.pinMode(LED4,OUT) wiringpi.pinMode(LED5,OUT) wiringpi.pinMode(LED6,OUT) wiringpi.pinMode(LED7,OUT) wiringpi.pinMode(LED8,OUT) #pull ups wiringpi.pullUpDnControl(IN1,2) wiringpi.pullUpDnControl(IN2,2) wiringpi.pullUpDnControl(IN3,2) wiringpi.pullUpDnControl(IN4,2) wiringpi.pullUpDnControl(IN5,2) wiringpi.pullUpDnControl(IN6,2) wiringpi.pullUpDnControl(IN7,2) wiringpi.pullUpDnControl(IN8,2) #Set pin mode for ROWs as OUTPUT wiringpi.pinMode(ROW1,OUT) wiringpi.pinMode(ROW2,OUT) wiringpi.pinMode(ROW3,OUT) wiringpi.pinMode(ROW4,OUT) wiringpi.pinMode(ROW5,OUT) wiringpi.pinMode(ROW6,OUT) wiringpi.pinMode(ROW7,OUT)
# PUD_OFF 0 # PUD_DOWN 1 # PUD_UP 2 import wiringpi2 wiringpi2.wiringPiSetup() # For sequential pin numbering from array import * import time sequence = array('i', [262, 294, 330, 349, 392, 440, 494, 525, 0]) vbeep = [0.05, 0.05, 0.05, 0.2] onebeep = [0.05] twobeeps = [0.05, 0.05] wiringpi2.pinMode(0,0) # Pin 0 for switch, INPUT wiringpi2.pullUpDnControl(0, 1) # set pull UP resistor for pin 0 switch wiringpi2.pinMode(1,1) # Pin 1 for beeper, OUTPUT wiringpi2.softToneCreate(3) # initialize softTone on Pin 3 def beeper(beeps): "Beep all of the requested beeps in the beeps list" for i in beeps: wiringpi2.digitalWrite(1,1) # beep on time.sleep(i) # length of beep from beeps list wiringpi2.digitalWrite(1,0) # beep off time.sleep(0.025) # interval between beeps def gotButton(): "Double beeps after every button press from interrupt call" # beeper(twobeeps) print("Got a button press")
#!/usr/bin/env python # author: Michal Kostrzewa # [email protected] # # test input levels from OpAmp. Will 2v work? # import wiringpi2 as wiringpi import time wiringpi.wiringPiSetupGpio() wiringpi.pinMode(26, 0) wiringpi.pullUpDnControl(26, 0) out = wiringpi.digitalRead(26) print out time.sleep(2) # answer: yes
import wiringpi2 PIN_TO_SENSE = 23 def gpio_callback(): print "GPIO_CALLBACK!" wiringpi2.wiringPiSetupGpio() wiringpi2.pinMode(PIN_TO_SENSE, wiringpi2.GPIO.INPUT) wiringpi2.pullUpDnControl(PIN_TO_SENSE, wiringpi2.GPIO.PUD_UP) wiringpi2.wiringPiISR(PIN_TO_SENSE, wiringpi2.GPIO.INT_EDGE_BOTH, gpio_callback) while True: wiringpi2.delay(2000)
def initGPIO(): # set up the GPIO pins for pin in range (0,3): io.pinMode(pinList[pin],0) # make pin into an input io.pullUpDnControl(pinList[pin],2) # enable pull up
# # define some constants # INPUT = 0 INT_EDGE_FALLING = 1 PUD_UP = 2 # # use Broadcom GPIO pin scheme # gpio.wiringPiSetupGpio() # setup pins as inut with pull-up # gpio.pinMode(REQ_OFFb, INPUT) gpio.pullUpDnControl(REQ_OFFb, PUD_UP) # # get state of REQ_OFFb # if gpio.digitalRead(REQ_OFFb): os.system('logger monitorPS:REQ_OFF* is high') else: os.system('logger monitorPS:REQ_OFF* is low') # # register the interrupt handler # # poll for REQ_OFFb going low # while gpio.digitalRead(REQ_OFFb): time.sleep(.200)
#!/usr/bin/env python import json, sys, socket, time import wiringpi2 as wiringpi PORT = 50001 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # s.bind(('', 0)) # s.bind(('10.1.3.1', 0)) s.bind(('192.168.42.1', 0)) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) wiringpi.wiringPiSetup() wiringpi.wiringPiSetupGpio() wiringpi.pinMode(13, 0) wiringpi.pullUpDnControl(13, 2) wiringpi.pinMode(19, 0) wiringpi.pullUpDnControl(19, 2) wiringpi.pinMode(26, 0) wiringpi.pullUpDnControl(26, 2) light_index = int(sys.argv[1]) light_color = int(sys.argv[2]) button_pin = int(sys.argv[3]) state = 0 while True: if wiringpi.digitalRead(button_pin): state = 0 time.sleep(0.1) elif not wiringpi.digitalRead(button_pin):
def __init__(self, input_pin = 16): """default to digital input on pin 16 (GPIO pin 23)""" self.pin = input_pin wp.pinMode(self.pin, INPUT) wp.pullUpDnControl(self.pin, PUD_UP)
import wiringpi2 as odroid import time import os import glob import sys odroid.wiringPiSetup() Button = 3 odroid.pinMode(Button, 0) odroid.pullUpDnControl(Button, 1) #loop print("Program Running") while True: #loops forever till keyboard interupt (ctr + C) if odroid.digitalRead(Button) == False: #when button not pressed: sys.stderr.write(".") time.sleep(1) else: print("Button Pressed") # ------| photo & Bell |------ # #Get FileName now = time.strftime("Date%m-%d-%yTime%H-%M-%S") #Make command to run odroidC2.sh command = "bash odroidC2.sh " + str(now) # -- odroidC2.sh is an Shell script that # -- is responsible for taking the photo and # -- making the Doorbell Noise
received_signal = 0 #kill -SIGUSR1 13534 # https://docs.python.org/3/library/signal.html#signal.signal def signal_handler(signum, stack_frame): global received_signal print("*** signal_handler received:", signum) received_signal = signum print(time.strftime("%Y%m%d_%H%M%S"), "Set up signal_handler") signal.signal(signal.SIGUSR1, signal_handler) signal.signal(signal.SIGUSR2, signal_handler) print(time.strftime("%Y%m%d_%H%M%S"), "Set up green_button as input") wp2.pinMode(green_button, wp2.GPIO.INPUT) wp2.pullUpDnControl(green_button, wp2.GPIO.PUD_UP) print(time.strftime("%Y%m%d_%H%M%S"), "Set up roof closed and opened sensors as input") wp2.pinMode(roof_closed_sensor1, wp2.GPIO.INPUT) wp2.pinMode(roof_opened_sensor1, wp2.GPIO.INPUT) print(time.strftime("%Y%m%d_%H%M%S"), "Set up left and right relay as output") wp2.pinMode(roof_motor_start_relay1, wp2.GPIO.OUTPUT) wp2.pinMode(roof_motor_direction_relay2, wp2.GPIO.OUTPUT) def waitForButton(pin): global received_signal while True: while wp2.digitalRead(pin) == True and received_signal == 0: time.sleep(0.01) # signal ?
OUTPUT = 1 pwm = 2 HIGH = 1 LOW = 0 PUD_DOWN = 1 PUD_UP = 2 PUD_RESET = 0 # Turn first pin 0 as output and switch it off wiringpi.pinMode(LED, OUTPUT) wiringpi.digitalWrite(LED, LOW) # Turn first pin 1 as input wiringpi.pinMode(TILT, INPUT) wiringpi.pullUpDnControl(TILT, PUD_UP) #pull up to 3.3V,make tiltPin a stable lev try: while True: if not wiringpi.digitalRead(TILT): # If tilt detected wiringpi.digitalWrite(LED, HIGH) # switch on LED. else: wiringpi.digitalWrite(LED, LOW) # switch off LED. #wiringpi.delay(1) # delay 0.05s finally: # when you CTRL+C exit, we clean up wiringpi.digitalWrite(LED, LOW) # switch off LED. wiringpi.pinMode(LED, INPUT) # sets ledPin to Input # tiltswitchPin is already an input, so no need to change anything
DOOR_PIN = 4 # Switch on wiring pi pin 0 (GPIO 17) SPACE_PIN = 0 # How many times per second should we read the GPIO? FREQUENCY = 2 # Global variables detected = 0 notified = 0 spaceIsOpen = False firstLoop = True still = "" wiringpi2.pinMode(DOOR_PIN, INPUT) wiringpi2.pullUpDnControl(DOOR_PIN, PUD_UP) wiringpi2.pinMode(SPACE_PIN, INPUT) wiringpi2.pullUpDnControl(SPACE_PIN, PUD_UP) def say(msg): command = "echo {} | festival --tts".format(shlex.quote(msg)) cmd = subprocess.Popen(command, shell=True, preexec_fn=os.setsid) cmd.wait() def smib(msg): command = "echo {} | nc localhost 1337".format(shlex.quote(msg)) cmd = subprocess.Popen(command, shell=True, preexec_fn=os.setsid) cmd.wait()