Python RPi.GPIO.PUD_UP Examples
The following are 30
code examples of RPi.GPIO.PUD_UP().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
RPi.GPIO
, or try the search function
.
Example #1
Source File: __init__.py From phat-beat with MIT License | 7 votes |
def setup(): global _is_setup if _is_setup: return True atexit.register(_exit) GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup([DAT, CLK], GPIO.OUT) GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP) for button in BUTTONS: GPIO.add_event_detect(button, GPIO.FALLING, callback=_handle_button, bouncetime=200) _is_setup = True
Example #2
Source File: sakshat.py From SAKS-tutorials with GNU General Public License v2.0 | 6 votes |
def saks_gpio_init(self): #print 'saks_gpio_init' GPIO.setwarnings(False) GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(PINS.BUZZER, GPIO.OUT) GPIO.output(PINS.BUZZER, GPIO.HIGH) for p in [PINS.IC_TM1637_DI, PINS.IC_TM1637_CLK, PINS.IC_74HC595_DS, PINS.IC_74HC595_SHCP, PINS.IC_74HC595_STCP]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.LOW) for p in [PINS.BUZZER, PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.HIGH) for p in [PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.IN, pull_up_down = GPIO.PUD_UP)
Example #3
Source File: sakshat.py From SAKS-SDK with GNU General Public License v2.0 | 6 votes |
def saks_gpio_init(self): #print 'saks_gpio_init' GPIO.setwarnings(False) GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(PINS.BUZZER, GPIO.OUT) GPIO.output(PINS.BUZZER, GPIO.HIGH) for p in [PINS.IC_TM1637_DI, PINS.IC_TM1637_CLK, PINS.IC_74HC595_DS, PINS.IC_74HC595_SHCP, PINS.IC_74HC595_STCP]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.LOW) for p in [PINS.BUZZER, PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.HIGH) for p in [PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.IN, pull_up_down = GPIO.PUD_UP)
Example #4
Source File: _button.py From ai-makers-kit with MIT License | 6 votes |
def __init__(self, channel, polarity=GPIO.FALLING, pull_up_down=GPIO.PUD_UP, debounce_time=0.08): if polarity not in [GPIO.FALLING, GPIO.RISING]: raise ValueError( 'polarity must be one of: GPIO.FALLING or GPIO.RISING') self.channel = int(channel) self.polarity = polarity self.expected_value = polarity == GPIO.RISING self.debounce_time = debounce_time GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(channel, GPIO.IN, pull_up_down=pull_up_down) self.callback = None
Example #5
Source File: _button.py From ai-makers-kit with MIT License | 6 votes |
def __init__(self, channel, polarity=GPIO.FALLING, pull_up_down=GPIO.PUD_UP, debounce_time=0.08): if polarity not in [GPIO.FALLING, GPIO.RISING]: raise ValueError( 'polarity must be one of: GPIO.FALLING or GPIO.RISING') self.channel = int(channel) self.polarity = polarity self.expected_value = polarity == GPIO.RISING self.debounce_time = debounce_time GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(channel, GPIO.IN, pull_up_down=pull_up_down) self.callback = None
Example #6
Source File: KY040.py From KY040 with MIT License | 6 votes |
def __init__(self, clockPin, dataPin, switchPin=None, rotaryCallback=None, switchCallback=None, rotaryBouncetime=250, switchBouncetime=300): # persist values self.clockPin = clockPin self.dataPin = dataPin self.switchPin = switchPin self.rotaryCallback = rotaryCallback self.switchCallback = switchCallback self.rotaryBouncetime = rotaryBouncetime self.switchBouncetime = switchBouncetime #setup pins GPIO.setup(clockPin, GPIO.IN) GPIO.setup(dataPin, GPIO.IN) if None != self.switchPin: GPIO.setup(switchPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Example #7
Source File: sakshat.py From SAKS-tutorials with GNU General Public License v2.0 | 6 votes |
def saks_gpio_init(self): #print 'saks_gpio_init' GPIO.setwarnings(False) GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(PINS.BUZZER, GPIO.OUT) GPIO.output(PINS.BUZZER, GPIO.HIGH) for p in [PINS.IC_TM1637_DI, PINS.IC_TM1637_CLK, PINS.IC_74HC595_DS, PINS.IC_74HC595_SHCP, PINS.IC_74HC595_STCP]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.LOW) for p in [PINS.BUZZER, PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.HIGH) for p in [PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.IN, pull_up_down = GPIO.PUD_UP)
Example #8
Source File: sakshat.py From SAKS-tutorials with GNU General Public License v2.0 | 6 votes |
def saks_gpio_init(self): #print 'saks_gpio_init' GPIO.setwarnings(False) GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(PINS.BUZZER, GPIO.OUT) GPIO.output(PINS.BUZZER, GPIO.HIGH) for p in [PINS.IC_TM1637_DI, PINS.IC_TM1637_CLK, PINS.IC_74HC595_DS, PINS.IC_74HC595_SHCP, PINS.IC_74HC595_STCP]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.LOW) for p in [PINS.BUZZER, PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.HIGH) for p in [PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.IN, pull_up_down = GPIO.PUD_UP)
Example #9
Source File: sakshat.py From SAKS-tutorials with GNU General Public License v2.0 | 6 votes |
def saks_gpio_init(self): #print 'saks_gpio_init' GPIO.setwarnings(False) GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(PINS.BUZZER, GPIO.OUT) GPIO.output(PINS.BUZZER, GPIO.HIGH) for p in [PINS.IC_TM1637_DI, PINS.IC_TM1637_CLK, PINS.IC_74HC595_DS, PINS.IC_74HC595_SHCP, PINS.IC_74HC595_STCP]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.LOW) for p in [PINS.BUZZER, PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.HIGH) for p in [PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.IN, pull_up_down = GPIO.PUD_UP)
Example #10
Source File: sakshat.py From SAKS-tutorials with GNU General Public License v2.0 | 6 votes |
def saks_gpio_init(self): #print 'saks_gpio_init' GPIO.setwarnings(False) GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(PINS.BUZZER, GPIO.OUT) GPIO.output(PINS.BUZZER, GPIO.HIGH) for p in [PINS.IC_TM1637_DI, PINS.IC_TM1637_CLK, PINS.IC_74HC595_DS, PINS.IC_74HC595_SHCP, PINS.IC_74HC595_STCP]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.LOW) for p in [PINS.BUZZER, PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.HIGH) for p in [PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]: GPIO.setup(p, GPIO.IN, pull_up_down = GPIO.PUD_UP)
Example #11
Source File: acceptor_test.py From LightningATM with MIT License | 6 votes |
def main(): global pulses ## We're using BCM Mode GPIO.setmode(GPIO.BCM) ## Setup coin interrupt channel GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP) # GPIO.setup(PIN_COIN_INTERRUPT,GPIO.IN) GPIO.add_event_detect(6, GPIO.FALLING, callback=coinEventHandler) while True: time.sleep(0.5) if (time.time() - lastImpulse > 0.5) and (pulses > 0): if pulses == 1: print("Coin 1") pulses = 0 GPIO.cleanup() # handle the coin event
Example #12
Source File: garage.py From GarageQTPi with MIT License | 6 votes |
def __init__(self, config): # Config self.relay_pin = config['relay'] self.state_pin = config['state'] self.id = config['id'] self.mode = int(config.get('state_mode') == 'normally_closed') self.invert_relay = bool(config.get('invert_relay')) # Setup self._state = None self.onStateChange = EventHook() # Set relay pin to output, state pin to input, and add a change listener to the state pin GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(self.relay_pin, GPIO.OUT) GPIO.setup(self.state_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(self.state_pin, GPIO.BOTH, callback=self.__stateChanged, bouncetime=300) # Set default relay state to false (off) GPIO.output(self.relay_pin, self.invert_relay) # Release rpi resources
Example #13
Source File: TipiWatchDogService.py From tipi with GNU General Public License v3.0 | 6 votes |
def __init__(self): self.__RESET = 26 GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(self.__RESET, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Do not proceed unless the reset signal has turned off # attempt to prevent restart storm in systemd print("waiting for reset to complete.") while GPIO.input(self.__RESET) != 1: time.sleep(0.100) pass GPIO.add_event_detect( self.__RESET, GPIO.FALLING, callback=onReset, bouncetime=100 ) print("GPIO initialized.")
Example #14
Source File: rodi.py From Aquamonitor with GNU Lesser General Public License v3.0 | 6 votes |
def Setup(): global logger logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) handler = logging.FileHandler('/var/log/rodi.log') handler.setLevel(logging.INFO) formatter = logging.Formatter('%(asctime)s - %(message)s',"%Y-%m-%d %H:%M:%S") handler.setFormatter(formatter) logger.addHandler(handler) GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(WATER_VALVE, GPIO.OUT) GPIO.setup(FLOATSW_HIGH_WL, GPIO.IN, pull_up_down=GPIO.PUD_UP) #, initial = GPIO.HIGH) if not sys.stdout.isatty(): sys.stderr = open('/var/log/rodi_stderr.log', 'a') sys.stdout = open('/var/log/rodi_stdout.log', 'a')
Example #15
Source File: pin.py From Adafruit_Blinka with MIT License | 6 votes |
def init(self, mode=IN, pull=None): """Initialize the Pin""" if mode is not None: if mode == self.IN: self._mode = self.IN GPIO.setup(self.id, GPIO.IN) elif mode == self.OUT: self._mode = self.OUT GPIO.setup(self.id, GPIO.OUT) else: raise RuntimeError("Invalid mode for pin: %s" % self.id) if pull is not None: if self._mode != self.IN: raise RuntimeError("Cannot set pull resistor on output") if pull == self.PULL_UP: GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP) elif pull == self.PULL_DOWN: GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) else: raise RuntimeError("Invalid pull for pin: %s" % self.id)
Example #16
Source File: button_and_led.py From EInk-Calendar with MIT License | 6 votes |
def __init__(self, controller: Controller, button_gpio: int = 26, led_gpio: int = 21) -> None: self.button_gpio = button_gpio self.controller = controller GPIO.setmode(GPIO.BCM) GPIO.setup(button_gpio, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(led_gpio, GPIO.OUT) self.led_gpio = led_gpio def call_back(channel: int) -> None: def new_thread(): self.controller.update_and_redraw() logger.info('Update of the screen due to button event') thread = threading.Thread(target=new_thread) thread.start() GPIO.add_event_detect(button_gpio, GPIO.FALLING, callback=call_back, bouncetime=500) self.led_off()
Example #17
Source File: 12_rotaryEncoder.py From SunFounder_Super_Kit_V3.0_for_Raspberry_Pi with GNU General Public License v2.0 | 5 votes |
def setup(): global counter global Last_RoB_Status, Current_RoB_Status GPIO.setmode(GPIO.BCM) GPIO.setup(RoAPin, GPIO.IN) GPIO.setup(RoBPin, GPIO.IN) GPIO.setup(RoSPin,GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set up a falling edge detect to callback clear GPIO.add_event_detect(RoSPin, GPIO.FALLING, callback=clear) # Set up a counter as a global variable counter = 0 Last_RoB_Status = 0 Current_RoB_Status = 0 # Define a function to deal with rotary encoder
Example #18
Source File: 14_dice.py From SunFounder_Super_Kit_V3.0_for_Raspberry_Pi with GNU General Public License v2.0 | 5 votes |
def setup(): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(SDI, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(RCLK, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(SRCLK, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(TouchPin, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.add_event_detect(TouchPin, GPIO.RISING, callback = randomISR, bouncetime = 20) # Shift the data to 74HC595
Example #19
Source File: 09_ne555.py From SunFounder_Super_Kit_V3.0_for_Raspberry_Pi with GNU General Public License v2.0 | 5 votes |
def setup(): GPIO.setmode(GPIO.BCM) # Numbers GPIOs by physical location GPIO.setup(SigPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set Pin's mode is input, and pull up to high level(3.3V) GPIO.add_event_detect(SigPin, GPIO.RISING, callback=count) # wait for rasing
Example #20
Source File: button.py From squid with MIT License | 5 votes |
def __init__(self, button_pin, debounce=0.05): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) self.BUTTON_PIN = button_pin self.DEBOUNCE = debounce GPIO.setup(self.BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Example #21
Source File: button.py From squid with MIT License | 5 votes |
def __init__(self, button_pin, debounce=0.05): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) self.BUTTON_PIN = button_pin self.DEBOUNCE = debounce GPIO.setup(self.BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Example #22
Source File: button.py From squid with MIT License | 5 votes |
def __init__(self, button_pin, debounce=0.05): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) self.BUTTON_PIN = button_pin self.DEBOUNCE = debounce GPIO.setup(self.BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Example #23
Source File: button.py From squid with MIT License | 5 votes |
def __init__(self, button_pin, debounce=0.05): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) self.BUTTON_PIN = button_pin self.DEBOUNCE = debounce print(debounce) GPIO.setup(self.BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Example #24
Source File: 08_mecury_switch.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 5 votes |
def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(Gpin, GPIO.OUT) # Set Green Led Pin mode to output GPIO.setup(Rpin, GPIO.OUT) # Set Red Led Pin mode to output GPIO.setup(MPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set BtnPin's mode is input, and pull up to high level(3.3V) GPIO.add_event_detect(MPin, GPIO.BOTH, callback=detect, bouncetime=200)
Example #25
Source File: 07_tilt_switch.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 5 votes |
def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(Gpin, GPIO.OUT) # Set Green Led Pin mode to output GPIO.setup(Rpin, GPIO.OUT) # Set Red Led Pin mode to output GPIO.setup(TiltPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set BtnPin's mode is input, and pull up to high level(3.3V) GPIO.add_event_detect(TiltPin, GPIO.BOTH, callback=detect, bouncetime=200)
Example #26
Source File: 34_tracking.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 5 votes |
def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(TrackPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led
Example #27
Source File: 27_rotary_encoder.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 5 votes |
def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(RoAPin, GPIO.IN) # input mode GPIO.setup(RoBPin, GPIO.IN) GPIO.setup(BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Example #28
Source File: 06_button.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 5 votes |
def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(Gpin, GPIO.OUT) # Set Green Led Pin mode to output GPIO.setup(Rpin, GPIO.OUT) # Set Red Led Pin mode to output GPIO.setup(BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set BtnPin's mode is input, and pull up to high level(3.3V) GPIO.add_event_detect(BtnPin, GPIO.BOTH, callback=detect, bouncetime=200)
Example #29
Source File: 08_vibration_switch.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 5 votes |
def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(Gpin, GPIO.OUT) # Set Green Led Pin mode to output GPIO.setup(Rpin, GPIO.OUT) # Set Red Led Pin mode to output GPIO.setup(VibratePin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set BtnPin's mode is input, and pull up to high level(3.3V)
Example #30
Source File: 17_switch_hall.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 5 votes |
def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(Gpin, GPIO.OUT) # Set Green Led Pin mode to output GPIO.setup(Rpin, GPIO.OUT) # Set Red Led Pin mode to output GPIO.setup(HallPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set BtnPin's mode is input, and pull up to high level(3.3V) GPIO.add_event_detect(HallPin, GPIO.BOTH, callback=detect, bouncetime=200)