Python RPi.GPIO 模块,PUD_DOWN 实例源码

我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用RPi.GPIO.PUD_DOWN

项目:red-phone    作者:mixmasteru    | 项目源码 | 文件源码
def __init__(self, ready):
        Thread.__init__(self)
        self.ready = ready
        self.picked_up = False
        self.on = True
        self._ringer1 = 11
        self._ringer2 = 13
        self._button = 7

        GPIO.setmode(GPIO.BOARD)
        GPIO.setwarnings(False)
        GPIO.setup(self._ringer1, GPIO.OUT)
        GPIO.output(self._ringer1, GPIO.LOW)
        GPIO.setup(self._ringer2, GPIO.OUT)
        GPIO.output(self._ringer2, GPIO.LOW)
        GPIO.setup(self._button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

        self._last_state = 0
        self._last_ts = time.time()
        self._last_check = time.time()
        self._ring = 1
        self.max_ring_cnt = 2
项目:JustBoom    作者:PiSupply    | 项目源码 | 文件源码
def __init__(self, clockPin, dataPin, buttonPin,
                 rotaryCallback, buttonCallback, rotaryType):
        # persist values
        self.clockPin = clockPin
        self.dataPin = dataPin
        self.buttonPin = buttonPin
        self.rotaryCallback = rotaryCallback
        self.buttonCallback = buttonCallback
        self.rotaryType = rotaryType

        # setup pins
        if self.rotaryType == "standard":
            GPIO.setup(clockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)  # All pins are pull up because both
            GPIO.setup(dataPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)  # the encoder and the button
        elif self.rotaryType == "keyes":
            GPIO.setup(clockPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)  # All pins are pull up because both
            GPIO.setup(dataPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)  # the encoder and the button

        GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)  # will be connected to Ground
项目:phony    作者:littlecraft    | 项目源码 | 文件源码
def _configure_input(self, name, configuration):
    pin = configuration['pin']

    self.log().debug('Pin %d -> %s' % (pin, name))

    if configuration['pull_up_down'] == 'up':
      pull_up_or_down = GPIO.PUD_UP
    else:
      pull_up_or_down = GPIO.PUD_DOWN

    if 'debounce' in configuration:
      debounce = configuration['debounce']
    else:
      debounce = 0

    GPIO.setup(pin, GPIO.IN, pull_up_down = pull_up_or_down)
    GPIO.add_event_detect(pin, GPIO.BOTH, callback = self._channel_changed, bouncetime = debounce)
项目:pi-mqtt-gpio    作者:flyte    | 项目源码 | 文件源码
def __init__(self, config):
        global DIRECTIONS, PULLUPS
        import RPi.GPIO as gpio
        self.io = gpio
        DIRECTIONS = {
            PinDirection.INPUT: gpio.IN,
            PinDirection.OUTPUT: gpio.OUT
        }

        PULLUPS = {
            PinPullup.OFF: gpio.PUD_OFF,
            PinPullup.UP: gpio.PUD_UP,
            PinPullup.DOWN: gpio.PUD_DOWN
        }

        gpio.setmode(gpio.BCM)
项目:StratoBalloon    作者:delattreb    | 项目源码 | 文件源码
def __init__(self, name = ''):
        self.importlib = GPIO
        self.logger = com_logger.Logger(name)
        # self.setwarnings(False)
        self.IN = GPIO.IN if GPIO is not None else None
        self.OUT = GPIO.OUT if GPIO is not None else None
        self.LOW = GPIO.LOW if GPIO is not None else None
        self.HIGH = GPIO.HIGH if GPIO is not None else None
        self.PUD_UP = GPIO.PUD_UP if GPIO is not None else None
        self.PUD_DOWN = GPIO.PUD_DOWN if GPIO is not None else None
        self.RISING = GPIO.RISING if GPIO is not None else None
项目:StratoBalloon    作者:delattreb    | 项目源码 | 文件源码
def pull(self, io_number):
        if self.importlib is not None:
            # self.logger.debug('pull')
            # Afin d'éviter de laisser flottante toute entrée, il est possible de connecter des résistances de pull-up ou de pull-down, au choix, en interne.
            # Pour information, une résistance de pull-up ou de pull-down a pour but d'éviter de laisser une entrée ou une sortie dans un état incertain, en
            # forçant une connexion à la # masse ou à un potentiel donné.
            GPIO.setup(io_number, GPIO.IN, pull_up_down = GPIO.PUD_UP)
            GPIO.setup(io_number, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
项目:nhl_goal_light    作者:arim215    | 项目源码 | 文件源码
def setup():
    """ Function to setup raspberry pi GPIO mode and warnings. PIN 7 OUT and PIN 11 IN """

    # Setup GPIO on raspberry pi
    GPIO.setmode(GPIO.BOARD)
    GPIO.setwarnings(False)
    GPIO.setup(7, GPIO.OUT, initial=GPIO.LOW) # Tell the program you want to use pin number 7 as output. Relay is ACTIVE LOW, so OFF is HIGH
    GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)  # Set GPIO 11 as a PULL DOWN switch
    GPIO.add_event_detect(11, GPIO.RISING, activate_goal_light, 5000)
项目:rpi-film-capture    作者:jphfilm    | 项目源码 | 文件源码
def __init__(self, triggerpin):
    GPIO.setup(triggerpin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    self.pin = triggerpin
项目:rpi-film-capture    作者:jphfilm    | 项目源码 | 文件源码
def __init__(self):
        GPIO.setmode(GPIO.BCM)
        self.light = lightControl(self.light_pin, True)
        self.redled = lightControl(self.red_pin)
        self.yellowled = lightControl(self.yellow_pin)
        self.motor = stepperControl()
        GPIO.setup(self.trigger_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        self.motorstate = 0
        self.smart_motor = False
        self.smart_headroom = 25
        self.triggertime = 0
        self.qlen = 5
        self.triggertimes = collections.deque([],self.qlen)
        self.phototimes = collections.deque([],self.qlen)
项目:52-Weeks-of-Pi    作者:grantwinney    | 项目源码 | 文件源码
def initialize_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(Gmail.PIN, GPIO.OUT)
    GPIO.setup(CHECK_NOW_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.add_event_detect(CHECK_NOW_PIN, GPIO.RISING, callback=check_mail_now, bouncetime=1000)
项目:52-Weeks-of-Pi    作者:grantwinney    | 项目源码 | 文件源码
def initialize_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup([R,G], GPIO.OUT, initial=GPIO.LOW)
    GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.add_event_detect(BUTTON, GPIO.FALLING, fan_the_flame, 250)
项目:52-Weeks-of-Pi    作者:grantwinney    | 项目源码 | 文件源码
def initialize_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(LIGHTS, GPIO.OUT, initial=GPIO.LOW)
    GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    for i in range(4):
        GPIO.add_event_detect(BUTTONS[i], GPIO.FALLING, verify_player_selection, 400 if use_sounds else 250)
项目:photobooth    作者:maduck    | 项目源码 | 文件源码
def _init_gpio(self):
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.config.getint("SWITCH_PIN"), GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        GPIO.setup(self.config.getint("LED_PIN"), GPIO.OUT)
        self.enable_led(False)
项目:BlogCode    作者:yaptb    | 项目源码 | 文件源码
def __init__(self):


            print "setting up GPIO"

            GPIO.setmode(GPIO.BOARD)
            GPIO.setup(DeskCycle.PIN,GPIO.IN,pull_up_down=GPIO.PUD_UP)

            self.hitCount=0

            pin2=38
            GPIO.setup(pin2,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
            GPIO.add_event_detect(pin2, GPIO.FALLING, callback=self.pin_2_event,bouncetime=100)
项目:openadms-node    作者:dabamos    | 项目源码 | 文件源码
def init_gpio(self) -> None:
        """Initializes the GPIO interface."""
        # Set SoC as reference.
        GPIO.setmode(GPIO.BCM)
        # Set pin as input and activate pull-down resistor.
        GPIO.setup(self._pin,
                   GPIO.IN,
                   pull_up_down=GPIO.PUD_DOWN)
        # Add interrupt event.
        GPIO.add_event_detect(self._pin,
                              GPIO.RISING,
                              callback=self._interrupt,
                              bouncetime=self._bounce_time)
项目:telewall    作者:synox    | 项目源码 | 文件源码
def setup(self):
        """ setup GPIO pins and install GPIO event handler    """
        from RPi import GPIO
        GPIO.setup(self.pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

        GPIO.add_event_detect(self.pin, GPIO.RISING,
                              callback=self._onrising, bouncetime=1000)
项目:LoRaWAN    作者:jeroennijhof    | 项目源码 | 文件源码
def setup():
        """ Configure the Raspberry GPIOs
        :rtype : None
        """
        GPIO.setmode(GPIO.BCM)
        # LED
        GPIO.setup(BOARD.LED, GPIO.OUT)
        GPIO.output(BOARD.LED, 0)
        # switch
        GPIO.setup(BOARD.SWITCH, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 
        # DIOx
        for gpio_pin in [BOARD.DIO0, BOARD.DIO1, BOARD.DIO2, BOARD.DIO3]:
            GPIO.setup(gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        # blink 2 times to signal the board is set up
        BOARD.blink(.1, 2)
项目:coffee-billing    作者:weissekat    | 项目源码 | 文件源码
def __init__(self):
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        for column in self.columns:
            GPIO.setup(column, GPIO.OUT)
        for row in self.rows:
            GPIO.setup(row, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
项目:picraftzero    作者:WayneKeenan    | 项目源码 | 文件源码
def __init__(self, pin):
        self.handle_pressed = None
        self.handle_released = None
        self.handle_changed = None
        self.has_callback = False
        if self.type == 'Button':
            GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        else:
            GPIO.setup(pin, GPIO.IN)

        super(Input, self).__init__(pin)
项目:pi_power    作者:craic    | 项目源码 | 文件源码
def user_shutdown_setup(shutdown_pin):
    # setup the pin to check the shutdown switch - use the internal pull down resistor
    GPIO.setup(shutdown_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    # create a trigger for the shutdown switch
    GPIO.add_event_detect(shutdown_pin, GPIO.RISING, callback=user_shutdown, bouncetime=1000)

# User has pressed shutdown button - initiate a clean shutdown
项目:homeassistant    作者:NAStools    | 项目源码 | 文件源码
def setup_input(port, pull_mode):
    """Setup a GPIO as input."""
    import RPi.GPIO as GPIO
    GPIO.setup(port, GPIO.IN,
               GPIO.PUD_DOWN if pull_mode == 'DOWN' else GPIO.PUD_UP)
项目:RaspberryPi-MPD-CharDisplay    作者:bill6300gp    | 项目源码 | 文件源码
def __init__(self, type=0, pull='UP', *vartuple):
    # ButtonEncoder(SWtype, pullLevel, PinSW)
    # ButtonEncoder(SWtype, pullLevel, PinSW, PinA, PinB)
    # ** SWtype: 1=Button, 2=Incremental Encoder
    #    [Usage] ButtonEncoder(1, pullLevel, PinSW)
    #            ButtonEncoder(2, pullLevel, [PinSW, PinA, PinB])
    #            ButtonEncoder(2, pullLevel, PinSW, PinA, PinB)
    # ** pull: Internal pull up/down resistor: UP, DOWN >> default: UP
    # ** Pin suggestion : 04(Pin-07), 17(Pin-11), 27(Pin-13), 22(Pin-15), 05(Pin-29), 06(Pin-31), 13(Pin-33), 26(Pin-37),
    #    BCM no.(Pin no.) 23(Pin-16), 24(Pin-18), 25(Pin-22), 12(Pin-32)
    #                     * Pin=0 to skip GPIO setup, but avoid setting PinA=0 and PinB=0 when SWtype is Encoder!
    if type==1 or type==2:
      self.__SWtype=type

      GPIO.setmode(GPIO.BCM)
      GPIO.setwarnings(False)
      if self.__SWtype==1 and (len(vartuple)==1 and isinstance(vartuple[0], int)):
        self.__PinSW=vartuple[0]
        if pull.upper().find('UP')>=0:
          GPIO.setup(self.__PinSW, GPIO.IN, pull_up_down=GPIO.PUD_UP)
          self.__Nlevel=True
        if pull.upper().find('DOWN')>=0:
          GPIO.setup(self.__PinSW, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
          self.__Nlevel=False
      elif self.__SWtype==2:
        if len(vartuple)==1 and (isinstance(vartuple[0], list) and len(vartuple[0])==3 and isinstance(vartuple[0][0], int) and isinstance(vartuple[0][1], int) and isinstance(vartuple[0][2], int)):
          self.__PinSW=vartuple[0][0]
          self.__PinA =vartuple[0][1]
          self.__PinB =vartuple[0][2]
        elif len(vartuple)==3 and (isinstance(vartuple[0], int) and isinstance(vartuple[1], int) and isinstance(vartuple[2], int)): 
          self.__PinSW=vartuple[0]
          self.__PinA =vartuple[1]
          self.__PinB =vartuple[2]
        else:
          self.__SWtype=0
          return None

        if pull.upper().find('UP')>=0:
          if self.__PinSW!=0:
            GPIO.setup(self.__PinSW, GPIO.IN, pull_up_down=GPIO.PUD_UP)
          if self.__PinA !=0:
            GPIO.setup(self.__PinA , GPIO.IN, pull_up_down=GPIO.PUD_UP)
          if self.__PinB !=0:
            GPIO.setup(self.__PinB , GPIO.IN, pull_up_down=GPIO.PUD_UP)
          self.__Nlevel=True
        if pull.upper().find('DOWN')>=0:
          if self.__PinSW!=0:
            GPIO.setup(self.__PinSW, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
          if self.__PinA !=0:
            GPIO.setup(self.__PinA , GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
          if self.__PinB !=0:
            GPIO.setup(self.__PinB , GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
          self.__Nlevel=False
      else:
        self.__SWtype=0
        return None
项目:OctoPrint-PSUControl    作者:kantlivelong    | 项目源码 | 文件源码
def _configure_gpio(self):
        if not self._hasGPIO:
            self._logger.error("RPi.GPIO is required.")
            return

        self._logger.info("Running RPi.GPIO version %s" % GPIO.VERSION)
        if GPIO.VERSION < "0.6":
            self._logger.error("RPi.GPIO version 0.6.0 or greater required.")

        GPIO.setwarnings(False)

        for pin in self._configuredGPIOPins:
            self._logger.debug("Cleaning up pin %s" % pin)
            try:
                GPIO.cleanup(self._gpio_get_pin(pin))
            except (RuntimeError, ValueError) as e:
                self._logger.error(e)
        self._configuredGPIOPins = []

        if GPIO.getmode() is None:
            if self.GPIOMode == 'BOARD':
                GPIO.setmode(GPIO.BOARD)
            elif self.GPIOMode == 'BCM':
                GPIO.setmode(GPIO.BCM)
            else:
                return

        if self.sensingMethod == 'GPIO':
            self._logger.info("Using GPIO sensing to determine PSU on/off state.")
            self._logger.info("Configuring GPIO for pin %s" % self.senseGPIOPin)

            if self.senseGPIOPinPUD == 'PULL_UP':
                pudsenseGPIOPin = GPIO.PUD_UP
            elif self.senseGPIOPinPUD == 'PULL_DOWN':
                pudsenseGPIOPin = GPIO.PUD_DOWN
            else:
                pudsenseGPIOPin = GPIO.PUD_OFF

            try:
                GPIO.setup(self._gpio_get_pin(self.senseGPIOPin), GPIO.IN, pull_up_down=pudsenseGPIOPin)
                self._configuredGPIOPins.append(self.senseGPIOPin)
            except (RuntimeError, ValueError) as e:
                self._logger.error(e)

        if self.switchingMethod == 'GPIO':
            self._logger.info("Using GPIO for On/Off")
            self._logger.info("Configuring GPIO for pin %s" % self.onoffGPIOPin)
            try:
                if not self.invertonoffGPIOPin:
                    initial_pin_output=GPIO.LOW
                else:
                    initial_pin_output=GPIO.HIGH
                GPIO.setup(self._gpio_get_pin(self.onoffGPIOPin), GPIO.OUT, initial=initial_pin_output)
                self._configuredGPIOPins.append(self.onoffGPIOPin)
            except (RuntimeError, ValueError) as e:
                self._logger.error(e)
项目:radio-hackbox    作者:SySS-Research    | 项目源码 | 文件源码
def __init__(self):
        """Initialize the nRF24 radio and the Raspberry Pi"""

        self.state = IDLE                            # current state
        self.lcd = None                              # LCD
        self.radio = None                            # nRF24 radio
        self.address = None                          # address of Cherry keyboard (CAUTION: Reversed byte order compared to sniffer tools!)
        self.channel = 6                             # used ShockBurst channel (was 6 for all tested Cherry keyboards)
        self.payloads = []                           # list of sniffed payloads
        self.kbd = None                              # keyboard for keystroke injection attacks

        try:
            # disable GPIO warnings
            GPIO.setwarnings(False)

            # initialize LCD
            self.lcd = CharLCD(cols=16, rows=2, pin_rs=15, pin_rw=18, pin_e=16, pins_data=[21, 22, 23, 24])
            self.lcd.clear()
            self.lcd.home()
            self.lcd.write_string(APP_NAME)
            self.lcd.cursor_pos = (1, 0)
            self.lcd.write_string(SYSS_BANNER)

            # use Raspberry Pi board pin numbers
            GPIO.setmode(GPIO.BOARD)

            # set up the GPIO pins
            GPIO.setup(RED_LED, GPIO.OUT, initial = GPIO.LOW)
            GPIO.setup(GREEN_LED, GPIO.OUT, initial = GPIO.LOW)
            GPIO.setup(BLUE_LED, GPIO.OUT, initial = GPIO.LOW)
            GPIO.setup(RECORD_BUTTON, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
            GPIO.setup(REPLAY_BUTTON, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
            GPIO.setup(ATTACK_BUTTON, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
            GPIO.setup(SCAN_BUTTON, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

            # set callcack functions
            GPIO.add_event_detect(RECORD_BUTTON, GPIO.RISING, callback = self.buttonCallback, bouncetime = 250)
            GPIO.add_event_detect(REPLAY_BUTTON, GPIO.RISING, callback = self.buttonCallback, bouncetime = 250)
            GPIO.add_event_detect(ATTACK_BUTTON, GPIO.RISING, callback = self.buttonCallback, bouncetime = 250)
            GPIO.add_event_detect(SCAN_BUTTON, GPIO.RISING, callback = self.buttonCallback, bouncetime = 250)

            # initialize radio
            self.radio = nrf24.nrf24()

            # enable LNA
            self.radio.enable_lna()

            # show startup info for some time with blinkenlights
            self.blinkenlights()

            # start scanning mode
            self.setState(SCAN)
        except:
            # error when initializing Radio Hack Box
            self.lcd.clear()
            self.lcd.home()
            self.lcd.write_string(u"Error: 0xDEAD")
            self.lcd.cursor_pos = (1, 0)
            self.lcd.write_string(u"Please RTFM!")