Python RPi.GPIO.FALLING Examples
The following are 30
code examples of RPi.GPIO.FALLING().
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: joystick.py From displayotron with MIT License | 7 votes |
def on(buttons, bounce=BOUNCE): """Handle a joystick direction or button push Decorator. Use with @joystick.on(joystick.UP) :param buttons: List, or single instance of joystick button constant :param bounce: Debounce delay in milliseconds: default 300 """ buttons = buttons if isinstance(buttons, list) else [buttons] def register(handler): for button in buttons: GPIO.remove_event_detect(button) GPIO.add_event_detect(button, GPIO.FALLING, callback=handler, bouncetime=bounce) return register
Example #2
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 #3
Source File: main.py From AlexaPiDEPRECATED with MIT License | 7 votes |
def start(): last = GPIO.input(button) while True: val = GPIO.input(button) GPIO.wait_for_edge(button, GPIO.FALLING) # we wait for the button to be pressed GPIO.output(lights[1], GPIO.HIGH) inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, device) inp.setchannels(1) inp.setrate(16000) inp.setformat(alsaaudio.PCM_FORMAT_S16_LE) inp.setperiodsize(500) audio = "" while(GPIO.input(button)==0): # we keep recording while the button is pressed l, data = inp.read() if l: audio += data rf = open(path+'recording.wav', 'w') rf.write(audio) rf.close() inp = None alexa()
Example #4
Source File: deskcycle_test.py From BlogCode with MIT License | 7 votes |
def event_loop(self): count =0 keys_per_rev=5 key_press_delay=0.05 inter_key_delay=0.1 last_time=0 current_time=0 GPIO.add_event_detect(DeskCycle.PIN, GPIO.FALLING, callback=self.pin_event,bouncetime=100) while True: if(self.hitCount >0): count+=1 print "Hit ",count self.hitCount-=1 time.sleep(0.01)
Example #5
Source File: __init__.py From picroft-google-aiy-voicekit-skill with GNU General Public License v3.0 | 6 votes |
def initialize(self): try: GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(LED, GPIO.OUT) GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(BUTTON, GPIO.FALLING, bouncetime = 500) except GPIO.error: self.log.warning("Can't initialize GPIO - skill will not load") self.speak_dialog("error.initialise") finally: self.schedule_repeating_event(self.handle_button, None, 0.1, 'GoogleAIY') self.add_event('recognizer_loop:record_begin', self.handle_listener_started) self.add_event('recognizer_loop:record_end', self.handle_listener_ended)
Example #6
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 #7
Source File: polapizero_09.py From polapi-zero with MIT License | 6 votes |
def haltSystem(): print 'Halt...' os.system("sudo halt") # GPIO.add_event_detect(HALT_PIN, GPIO.FALLING, callback = haltSystem, bouncetime = 2000)
Example #8
Source File: main.py From AlexaPi with MIT License | 6 votes |
def start(): last = GPIO.input(button) while True: val = GPIO.input(button) GPIO.wait_for_edge(button, GPIO.FALLING) # we wait for the button to be pressed GPIO.output(lights[1], GPIO.HIGH) inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, device) inp.setchannels(1) inp.setrate(16000) inp.setformat(alsaaudio.PCM_FORMAT_S16_LE) inp.setperiodsize(500) audio = "" while(GPIO.input(button)==0): # we keep recording while the button is pressed l, data = inp.read() if l: audio += data rf = open(path+'recording.wav', 'w') rf.write(audio) rf.close() inp = None alexa()
Example #9
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 #10
Source File: __init__.py From OctoPrint-Enclosure with GNU General Public License v3.0 | 6 votes |
def start_filament_detection(self): self.stop_filament_detection() try: for filament_sensor in list(filter( lambda item: item['input_type'] == 'gpio' and item['action_type'] == 'printer_control' and item[ 'printer_action'] == 'filament', self.rpi_inputs)): edge = GPIO.RISING if filament_sensor['edge'] == 'rise' else GPIO.FALLING if GPIO.input(self.to_int(filament_sensor['gpio_pin'])) == (edge == GPIO.RISING): self._printer.pause_print() self._logger.info("Started printing with no filament.") else: self.last_filament_end_detected.append(dict(index_id=filament_sensor['index_id'], time=0)) self._logger.info("Adding GPIO event detect on pin %s with edge: %s", filament_sensor['gpio_pin'], edge) GPIO.add_event_detect(self.to_int(filament_sensor['gpio_pin']), edge, callback=self.handle_filamment_detection, bouncetime=200) except Exception as ex: self.log_error(ex)
Example #11
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 #12
Source File: GPIOKY040.py From calvin-base with Apache License 2.0 | 6 votes |
def init(self, switch_pin=None, clock_pin=None, data_pin=None, **kwargs): _log.info("setup") self._switch_pin = switch_pin self._clock_pin = clock_pin self._data_pin = data_pin gpio.setmode(gpio.BCM) if self._switch_pin: _log.info("Setting up button pin") gpio.setup(self._switch_pin, gpio.IN, gpio.PUD_UP) gpio.add_event_detect(self._switch_pin, gpio.BOTH, callback=self._switch_cb, bouncetime=2) if self._data_pin: _log.info("Setting up data pin") gpio.setup(self._data_pin, gpio.IN) if self._clock_pin: gpio.setup(self._clock_pin, gpio.IN, gpio.PUD_UP) gpio.add_event_detect(self._clock_pin, gpio.FALLING, callback=self._knob_cb, bouncetime=2) self._values = [] _log.info("Systems are go")
Example #13
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 #14
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 #15
Source File: GPIOSR04.py From calvin-base with Apache License 2.0 | 6 votes |
def _trigger(self): try : self._detection = True self._t0 = time.time() gpio.output(self._trigger_pin, gpio.HIGH) time.sleep(0.00005) gpio.output(self._trigger_pin, gpio.LOW) pin = gpio.wait_for_edge(self._echo_pin, gpio.FALLING, timeout=1000) self._elapsed = time.time() - self._t0 if pin is None: _log.debug("echo timeout exceeded") # self._detection = None async.call_from_thread(self.scheduler_wakeup) except Exception as e: _log.warning("Failed sonar triggering: {}".format(e))
Example #16
Source File: main.py From GassistPi with GNU General Public License v3.0 | 6 votes |
def pushbutton(self): if GPIOcontrol: while mutestopbutton: time.sleep(.1) if GPIO.event_detected(stoppushbutton): GPIO.remove_event_detect(stoppushbutton) now = time.time() count = 1 GPIO.add_event_detect(stoppushbutton,GPIO.RISING) while time.time() < now + 1: if GPIO.event_detected(stoppushbutton): count +=1 time.sleep(.25) if count == 2: self.buttonsinglepress() GPIO.remove_event_detect(stoppushbutton) GPIO.add_event_detect(stoppushbutton,GPIO.FALLING) elif count == 3: self.buttondoublepress() GPIO.remove_event_detect(stoppushbutton) GPIO.add_event_detect(stoppushbutton,GPIO.FALLING) elif count == 4: self.buttontriplepress() GPIO.remove_event_detect(stoppushbutton) GPIO.add_event_detect(stoppushbutton,GPIO.FALLING)
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: listui.py From opc with MIT License | 5 votes |
def initgpio(): print "Initializing GPIO" #Initialize GPIO GPIO.setmode(GPIO.BCM) #GPIO.setup(key['key1'], GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key['key2'], GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key['key3'], GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key['left'], GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key['up'], GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key['press'], GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key['down'], GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(key['right'], GPIO.IN, pull_up_down=GPIO.PUD_UP) #LIPO LOW BATTERY GPIO.setup(lowBat, GPIO.IN,pull_up_down=GPIO.PUD_UP) #GPIO.add_event_detect(key['key1'], GPIO.FALLING) GPIO.add_event_detect(key['key2'], GPIO.FALLING,bouncetime=300) GPIO.add_event_detect(key['key3'], GPIO.FALLING,bouncetime=300) GPIO.add_event_detect(key['left'], GPIO.FALLING,bouncetime=300) GPIO.add_event_detect(key['up'], GPIO.FALLING,bouncetime=300) GPIO.add_event_detect(key['press'], GPIO.FALLING,bouncetime=300) GPIO.add_event_detect(key['down'], GPIO.FALLING,bouncetime=300) GPIO.add_event_detect(key['right'], GPIO.FALLING,bouncetime=300) # SYSTEM UTILITIES
Example #19
Source File: io_raspberry.py From foos with GNU General Public License v3.0 | 5 votes |
def __init__(self, bus, pin_number, team): self.bus = bus self.pin = pin_number self.team = team if self.pin: #GPIO.setup(self.pin, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.setup(self.pin, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.add_event_detect(self.pin, GPIO.FALLING, callback=self.on_goal, bouncetime=10) else: logger.warn("Cannot init GoalDetector {0}, pin not specified".format(self.team))
Example #20
Source File: 27_rotary_encoder.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 5 votes |
def loop(): global globalCounter tmp = 0 # Rotary Temperary GPIO.add_event_detect(BtnPin, GPIO.FALLING, callback=btnISR) while True: rotaryDeal() if tmp != globalCounter: print ('globalCounter = %d' % globalCounter) tmp = globalCounter
Example #21
Source File: main.py From GassistPi with GNU General Public License v3.0 | 5 votes |
def ircommands(self): if irreceiver!=None: try: print("IR Sensor Started") while True: time.sleep(.1) #print("Listening for IR Signal on GPIO "+irreceiver) GPIO.wait_for_edge(irreceiver, GPIO.FALLING) code = on_ir_receive(irreceiver) if code: if self.can_start_conversation == True: for codenum, usercode in enumerate(configuration['IR']['Codes']): if usercode==code: if 'custom' in (configuration['IR']['Commands'][codenum]).lower(): self.custom_command((configuration['IR']['Commands'][codenum]).lower()) elif 'start conversation' in (configuration['IR']['Commands'][codenum]).lower(): self.assistant.start_conversation() elif 'mute' in (configuration['IR']['Commands'][codenum]).lower(): self.buttonsinglepress() else: self.assistant.send_text_query(configuration['IR']['Commands'][codenum]) break except KeyboardInterrupt: pass except RuntimeError: pass print("Stopping IR Sensor")
Example #22
Source File: interrupt.py From alertR with GNU Affero General Public License v3.0 | 5 votes |
def initializeSensor(self) -> bool: self.hasLatestData = False self.changeState = True # get the value for the setting if the gpio is pulled up or down if self.pulledUpOrDown == 0: pulledUpOrDown = GPIO.PUD_DOWN elif self.pulledUpOrDown == 1: pulledUpOrDown = GPIO.PUD_UP else: logging.critical("[%s]: Value for pulled up or down setting not known." % self.fileName) return False # configure gpio pin and get initial state GPIO.setmode(GPIO.BOARD) GPIO.setup(self.gpioPin, GPIO.IN, pull_up_down=pulledUpOrDown) # set initial state to not triggered self.state = 1 - self.triggerState self._internalState = 1 - self.triggerState # set edge detection if self.edge == 0: GPIO.add_event_detect(self.gpioPin, GPIO.FALLING, callback=self._interruptCallback) elif self.edge == 1: GPIO.add_event_detect(self.gpioPin, GPIO.RISING, callback=self._interruptCallback) else: logging.critical("[%s]: Value for edge detection not known." % self.fileName) return False return True
Example #23
Source File: 09_ir_receiver.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 5 votes |
def loop(): GPIO.add_event_detect(IrPin, GPIO.FALLING, callback=cnt) # wait for falling while True: pass # Don't do anything
Example #24
Source File: RPiGPIOPin.py From calvin-base with Apache License 2.0 | 5 votes |
def init(self, pin, direction, pull=None, edge=None, bouncetime=None, **kwargs): self.values = [] self.pin = pin self.direction = direction self.edge = edge GPIO.setmode(GPIO.BCM) if direction == "IN": if pull is not None: if pull == "UP": GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP) elif pull == "DOWN": GPIO.setup(pin, GPIO.IN, GPIO.PUD_DOWN) else: raise Exception("Uknown pull configuration") else: GPIO.setup(pin, GPIO.IN) if edge is not None: if edge == "RISING": GPIO.add_event_detect(self.pin, GPIO.RISING, callback=self.edge_cb, bouncetime=bouncetime) elif edge == "FALLING": GPIO.add_event_detect(self.pin, GPIO.FALLING, callback=self.edge_cb, bouncetime=bouncetime) elif edge == "BOTH": GPIO.add_event_detect(self.pin, GPIO.BOTH, callback=self.edge_cb, bouncetime=bouncetime) else: raise Exception("Unknown edge configuration") elif direction == "OUT": GPIO.setup(pin, GPIO.OUT) else: raise Exception("Unknown direction")
Example #25
Source File: AIWIBoardContext.py From RPiNWR with GNU General Public License v3.0 | 5 votes |
def reset_radio(self): """ Reset the Si4707 chip """ # Ref https://github.com/AIWIndustries/Pi_4707/blob/master/firmware/NWRSAME_v2.py if self.gpio_started: gpio.cleanup() self.gpio_started = True gpio.setmode(gpio.BCM) # Use board pin numbering gpio.setup(17, gpio.OUT) # Setup the reset pin gpio.output(17, gpio.LOW) # Reset the Si4707. sleep(0.4) gpio.output(17, gpio.HIGH) gpio.setup(23, gpio.IN, pull_up_down=gpio.PUD_UP) gpio.add_event_detect(23, gpio.FALLING) # Initialize the onboard relays for pin in self.relay_gpio_pins: gpio.setup(pin, gpio.OUT) # setup gpio pin for relay gpio.output(pin, gpio.LOW) # boot to disabled state # set up the LED # https://www.reddit.com/r/raspberry_pi/comments/3641ug/blinking_an_onboard_led_on_the_pi_2_model_b/ # http://raspberrypi.stackexchange.com/questions/697/how-do-i-control-the-system-leds-using-my- # sudo echo none >/sys/class/leds/led0/trigger # GPIO 16 LOW is on, HIGH is off gpio.setup(16, gpio.OUT) gpio.output(16, gpio.HIGH) sleep(1.5)
Example #26
Source File: control.py From mudpi-core with MIT License | 5 votes |
def __init__(self, pin, name='Control',key=None, resistor=None, edge_detection=None, debounce=None): self.pin = pin self.name = name self.key = key.replace(" ", "_").lower() if key is not None else self.name.replace(" ", "_").lower() self.gpio = GPIO self.debounce = debounce if debounce is not None else None if resistor is not None: if resistor == "up" or resistor == GPIO.PUD_UP: self.resistor = GPIO.PUD_UP elif resistor == "down" or resistor == GPIO.PUD_DOWN: self.resistor = GPIO.PUD_DOWN else: self.resistor = resistor if edge_detection is not None: if edge_detection == "falling" or edge_detection == GPIO.FALLING: self.edge_detection = GPIO.FALLING elif edge_detection == "rising" or edge_detection == GPIO.RISING: self.edge_detection = GPIO.RISING elif edge_detection == "both" or edge_detection == GPIO.BOTH: self.edge_detection = GPIO.BOTH else: self.edge_detection = None return
Example #27
Source File: rfid.py From pi-rc522 with MIT License | 5 votes |
def __init__(self, bus=0, device=0, speed=1000000, pin_rst=def_pin_rst, pin_ce=0, pin_irq=def_pin_irq, pin_mode = def_pin_mode): self.pin_rst = pin_rst self.pin_ce = pin_ce self.pin_irq = pin_irq self.spi = SPIClass() self.spi.open(bus, device) if board == RASPBERRY: self.spi.max_speed_hz = speed else: self.spi.mode = 0 self.spi.msh = speed if pin_mode is not None: GPIO.setmode(pin_mode) if pin_rst != 0: GPIO.setup(pin_rst, GPIO.OUT) GPIO.output(pin_rst, 1) GPIO.setup(pin_irq, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(pin_irq, GPIO.FALLING, callback=self.irq_callback) if pin_ce != 0: GPIO.setup(pin_ce, GPIO.OUT) GPIO.output(pin_ce, 1) self.init()
Example #28
Source File: acc_manager.py From autopi-core with Apache License 2.0 | 5 votes |
def start(**settings): try: if log.isEnabledFor(logging.DEBUG): log.debug("Starting accelerometer manager with settings: {:}".format(settings)) # Give process higher priority - this can lead to process starvation on RPi Zero (single core) psutil.Process(os.getpid()).nice(settings.get("process_nice", -2)) # Setup interrupt GPIO pin gpio.setwarnings(False) gpio.setmode(gpio.BOARD) gpio.setup(gpio_pin.ACC_INT1, gpio.IN) gpio.add_event_detect(gpio_pin.ACC_INT1, gpio.FALLING, callback=lambda ch: interrupt_event.set()) # Initialize MMA8X5X connection conn.init(settings["mma8x5x_conn"]) # Initialize and run message processor edmp.init(__salt__, __opts__, hooks=settings.get("hooks", []), workers=settings.get("workers", []), reactors=settings.get("reactors", [])) edmp.run() except Exception: log.exception("Failed to start accelerometer manager") raise finally: log.info("Stopping accelerometer manager") if conn.is_open(): try: conn.close() except: log.exception("Failed to close MMA8X5X connection")
Example #29
Source File: deskcycle_btkclient.py From BlogCode with MIT License | 5 votes |
def event_loop(self): self.keyDown=False self.hitCount=0 keys_per_rev=5 key_press_delay=0.2 inter_key_delay=0.001 self.last_hit_time=0 self.current_hit_time=0 self.rev_time=0.5 GPIO.add_event_detect(DeskCycle.PIN, GPIO.FALLING, callback=self.pin_event,bouncetime=250) while True: if(self.hitCount >0): if(not self.keyDown): print "On" self.state[4]=DeskCycle.KEYCODE self.send_key_state() self.keyDown=True self.hitCount=0 else: if(self.keyDown): if(time.time()-self.last_hit_time > 1): print "Off" self.state[4]=0 self.send_key_state() self.keyDown=False time.sleep(0.001)
Example #30
Source File: polapizero_08.py From polapi-zero with MIT License | 5 votes |
def haltSystem(): print 'Halt...' os.system("sudo halt") # GPIO.add_event_detect(HALT_PIN, GPIO.FALLING, callback = haltSystem, bouncetime = 2000)