Python machine.Pin.OPEN_DRAIN Examples

The following are 19 code examples of machine.Pin.OPEN_DRAIN(). 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 machine.Pin , or try the search function .
Example #1
Source File: trigger.py    From ulnoiot-upy with MIT License 10 votes vote down vote up
def __init__(self, name, pin,
                 rising=False, falling=False,
                 pullup=True, on_change=None, report_change=True):
        if pullup:
            pin.init(Pin.IN, Pin.PULL_UP)
        else:
            pin.init(Pin.IN, Pin.OPEN_DRAIN)
        if rising and falling:
            trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
        elif not rising and falling:
            trigger = Pin.IRQ_FALLING
        else:  # also if both all false
            trigger = Pin.IRQ_RISING
        pin.irq(trigger=trigger, handler=self._cb)
        self.counter = 0
        self.report_counter = 0
        self.triggered = False
        Device.__init__(self, name, pin, on_change=on_change,
                        report_change=report_change)
        self.getters[""] = self.value 
Example #2
Source File: trigger.py    From ulnoiot-upy with MIT License 6 votes vote down vote up
def __init__(self, name, pin,
                 rising=False, falling=False,
                 pullup=True, on_change=None, report_change=True):
        if pullup:
            pin.init(Pin.IN, Pin.PULL_UP)
        else:
            pin.init(Pin.IN, Pin.OPEN_DRAIN)
        if rising and falling:
            trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
        elif not rising and falling:
            trigger = Pin.IRQ_FALLING
        else:  # also if both all false
            trigger = Pin.IRQ_RISING
        pin.irq(trigger=trigger, handler=self._cb)
        self.counter = 0
        self.report_counter = 0
        self.triggered = False
        Device.__init__(self, name, pin, on_change=on_change,
                        report_change=report_change)
        self.getters[""] = self.value 
Example #3
Source File: hcsr04.py    From uPySensors with Apache License 2.0 6 votes vote down vote up
def __init__(self, trigger_pin, echo_pin, echo_timeout_us=500*2*30):
        """
        trigger_pin: Output pin to send pulses
        echo_pin: Readonly pin to measure the distance. The pin should be protected with 1k resistor
        echo_timeout_us: Timeout in microseconds to listen to echo pin.
        By default is based in sensor limit range (4m)
        """
        self.echo_timeout_us = echo_timeout_us
        # Init trigger pin (out)
        self.trigger = Pin(trigger_pin, mode=Pin.OUT)
        self.trigger.value(0)
        # Init echo pin (in)
        if (uname().sysname == 'WiPy'):
            self.echo = Pin(echo_pin, mode=Pin.OPEN_DRAIN)
        else:
            self.echo = Pin(echo_pin, mode=Pin.IN) 
Example #4
Source File: sr_init.py    From micropython-async with MIT License 6 votes vote down vote up
def test():
    dout = Pin(Pin.board.Y5, Pin.OUT_PP, value = 0)   # Define pins
    ckout = Pin(Pin.board.Y6, Pin.OUT_PP, value = 0)  # Don't assert clock until data is set
    din = Pin(Pin.board.Y7, Pin.IN)
    ckin = Pin(Pin.board.Y8, Pin.IN)
    reset = Pin(Pin.board.Y4, Pin.OPEN_DRAIN)
    sig_reset = Signal(reset, invert = True)

    channel = SynCom(False, ckin, ckout, din, dout, sig_reset, 10000)

    loop = asyncio.get_event_loop()
    loop.create_task(heartbeat())
    loop.create_task(channel.start(initiator_task))
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        ckout.value(0) 
Example #5
Source File: trigger.py    From ulnoiot-upy with MIT License 6 votes vote down vote up
def __init__(self, name, pin,
                 rising=False, falling=False,
                 pullup=True, on_change=None, report_change=True):
        if pullup:
            pin.init(Pin.IN, Pin.PULL_UP)
        else:
            pin.init(Pin.IN, Pin.OPEN_DRAIN)
        if rising and falling:
            trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
        elif not rising and falling:
            trigger = Pin.IRQ_FALLING
        else:  # also if both all false
            trigger = Pin.IRQ_RISING
        pin.irq(trigger=trigger, handler=self._cb)
        self.counter = 0
        self.report_counter = 0
        self.triggered = False
        Device.__init__(self, name, pin, on_change=on_change,
                        report_change=report_change)
        self.getters[""] = self.value 
Example #6
Source File: trigger.py    From ulnoiot-upy with MIT License 6 votes vote down vote up
def __init__(self, name, pin,
                 rising=False, falling=False,
                 pullup=True, on_change=None, report_change=True):
        if pullup:
            pin.init(Pin.IN, Pin.PULL_UP)
        else:
            pin.init(Pin.IN, Pin.OPEN_DRAIN)
        if rising and falling:
            trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
        elif not rising and falling:
            trigger = Pin.IRQ_FALLING
        else:  # also if both all false
            trigger = Pin.IRQ_RISING
        pin.irq(trigger=trigger, handler=self._cb)
        self.counter = 0
        self.report_counter = 0
        self.triggered = False
        Device.__init__(self, name, pin, on_change=on_change,
                        report_change=report_change)
        self.getters[""] = self.value 
Example #7
Source File: sht1x.py    From upython-aq-monitor with MIT License 6 votes vote down vote up
def __init__(self, gnd, sck, data, vcc):
        self.gnd = gnd
        self.sck = sck
        self.data = data
        self.vcc = vcc

        self.gnd.mode(Pin.OUT)
        self.vcc.mode(Pin.OUT)
        self.sck.mode(Pin.OUT)
        self.data.mode(Pin.OPEN_DRAIN)

        self.gnd.pull(Pin.PULL_DOWN)
        self.vcc.pull(Pin.PULL_UP)
        self.sck.pull(Pin.PULL_DOWN)
        self.data.pull(None)

        self.sleep() 
Example #8
Source File: esp_8266Full.py    From python_banyan with GNU Affero General Public License v3.0 6 votes vote down vote up
def digital_write(self, payload):
        """
        Write to a digital gpio pin
        :param payload:
        :return:
        """
        pin = payload['pin']
        mode = Pin.OUT
        if 'drain' in payload:
            if not payload['drain']:
                mode = Pin.OPEN_DRAIN
        pin_object = Pin(pin, mode)
        pwm = PWM(pin_object)
        pwm.deinit()
        Pin(pin, mode, value=payload['value'])
        self.input_pin_objects[pin] = None 
Example #9
Source File: hcsr04.py    From ulnoiot-upy with MIT License 5 votes vote down vote up
def __init__(self, name, trigger_pin, echo_pin,
                 echo_timeout_us=30000, precision=10,
                 on_change=None, report_change=True,
                 filter=None):
        # trigger_pin: Output pin to send pulses
        # echo_pin: Readonly pin to measure the distance.
        #           The pin should be protected with 1k resistor
        # echo_timeout_us: Timeout in microseconds to listen to echo pin.
        # By default is based in sensor limit range (4m)
        self.current_value = 0
        self._last_measured = 0
        if type(trigger_pin) is not Pin:
            trigger_pin = Pin(trigger_pin)
        self.trigger_pin = trigger_pin
        if type(echo_pin) is not Pin:
            echo_pin = Pin(trigger_pin)
        self.echo_pin = echo_pin
        self.precision = precision
        trigger_pin.init(Pin.OUT)
        trigger_pin.off()
        echo_pin.init(Pin.IN)
        echo_pin.init(Pin.OPEN_DRAIN)
        self.echo_timeout_us = echo_timeout_us
        self.distance = -10000
        Device.__init__(self, name, (trigger_pin, echo_pin),
                        on_change=on_change,
                        report_change=report_change,
                        filter=filter) 
Example #10
Source File: hcsr04.py    From ulnoiot-upy with MIT License 5 votes vote down vote up
def __init__(self, name, trigger_pin, echo_pin,
                 echo_timeout_us=30000, precision=10,
                 on_change=None, report_change=True,
                 filter=None):
        # trigger_pin: Output pin to send pulses
        # echo_pin: Readonly pin to measure the distance.
        #           The pin should be protected with 1k resistor
        # echo_timeout_us: Timeout in microseconds to listen to echo pin.
        # By default is based in sensor limit range (4m)
        self.current_value = 0
        self._last_measured = 0
        if type(trigger_pin) is not Pin:
            trigger_pin = Pin(trigger_pin)
        self.trigger_pin = trigger_pin
        if type(echo_pin) is not Pin:
            echo_pin = Pin(trigger_pin)
        self.echo_pin = echo_pin
        self.precision = precision
        trigger_pin.init(Pin.OUT)
        trigger_pin.off()
        echo_pin.init(Pin.IN)
        echo_pin.init(Pin.OPEN_DRAIN)
        self.echo_timeout_us = echo_timeout_us
        self.distance = -10000
        Device.__init__(self, name, (trigger_pin, echo_pin),
                        on_change=on_change,
                        report_change=report_change,
                        filter=filter) 
Example #11
Source File: htu21d.py    From developer-badge-2018-apps with Apache License 2.0 5 votes vote down vote up
def __init__(self, scl, sda):
        """Initiate the HUT21D

        Args:
            scl (int): Pin id where the sdl pin is connected to
            sda (int): Pin id where the sda pin is connected to
        """
        self.i2c = I2C(scl=Pin(scl, Pin.OPEN_DRAIN, Pin.PULL_UP), sda=Pin(sda, Pin.OPEN_DRAIN, Pin.PULL_UP), freq=100000) 
Example #12
Source File: hcsr04.py    From ulnoiot-upy with MIT License 5 votes vote down vote up
def __init__(self, name, trigger_pin, echo_pin,
                 echo_timeout_us=30000, precision=10,
                 on_change=None, report_change=True,
                 filter=None):
        # trigger_pin: Output pin to send pulses
        # echo_pin: Readonly pin to measure the distance.
        #           The pin should be protected with 1k resistor
        # echo_timeout_us: Timeout in microseconds to listen to echo pin.
        # By default is based in sensor limit range (4m)
        self.current_value = 0
        self._last_measured = 0
        if type(trigger_pin) is not Pin:
            trigger_pin = Pin(trigger_pin)
        self.trigger_pin = trigger_pin
        if type(echo_pin) is not Pin:
            echo_pin = Pin(trigger_pin)
        self.echo_pin = echo_pin
        self.precision = precision
        trigger_pin.init(Pin.OUT)
        trigger_pin.off()
        echo_pin.init(Pin.IN)
        echo_pin.init(Pin.OPEN_DRAIN)
        self.echo_timeout_us = echo_timeout_us
        self.distance = -10000
        Device.__init__(self, name, (trigger_pin, echo_pin),
                        on_change=on_change,
                        report_change=report_change,
                        filter=filter) 
Example #13
Source File: hcsr04.py    From ulnoiot-upy with MIT License 5 votes vote down vote up
def __init__(self, name, trigger_pin, echo_pin,
                 echo_timeout_us=30000, precision=10,
                 on_change=None, report_change=True,
                 filter=None):
        # trigger_pin: Output pin to send pulses
        # echo_pin: Readonly pin to measure the distance.
        #           The pin should be protected with 1k resistor
        # echo_timeout_us: Timeout in microseconds to listen to echo pin.
        # By default is based in sensor limit range (4m)
        self.current_value = 0
        self._last_measured = 0
        if type(trigger_pin) is not Pin:
            trigger_pin = Pin(trigger_pin)
        self.trigger_pin = trigger_pin
        if type(echo_pin) is not Pin:
            echo_pin = Pin(trigger_pin)
        self.echo_pin = echo_pin
        self.precision = precision
        trigger_pin.init(Pin.OUT)
        trigger_pin.off()
        echo_pin.init(Pin.IN)
        echo_pin.init(Pin.OPEN_DRAIN)
        self.echo_timeout_us = echo_timeout_us
        self.distance = -10000
        Device.__init__(self, name, (trigger_pin, echo_pin),
                        on_change=on_change,
                        report_change=report_change,
                        filter=filter) 
Example #14
Source File: esp_8266.py    From python_banyan with GNU Affero General Public License v3.0 5 votes vote down vote up
def set_mode_digital_output(self,payload):
  pin=payload['pin']
  mode=Pin.OUT
  if 'drain' in payload:
   if not payload['drain']:
    mode=Pin.OPEN_DRAIN
  Pin(pin,mode,value=payload['value']) 
Example #15
Source File: hcsr04.py    From ulnoiot-upy with MIT License 5 votes vote down vote up
def __init__(self, name, trigger_pin, echo_pin,
                 echo_timeout_us=30000, precision=10,
                 on_change=None, report_change=True,
                 filter=None):
        # trigger_pin: Output pin to send pulses
        # echo_pin: Readonly pin to measure the distance.
        #           The pin should be protected with 1k resistor
        # echo_timeout_us: Timeout in microseconds to listen to echo pin.
        # By default is based in sensor limit range (4m)
        self.current_value = 0
        self._last_measured = 0
        if type(trigger_pin) is not Pin:
            trigger_pin = Pin(trigger_pin)
        self.trigger_pin = trigger_pin
        if type(echo_pin) is not Pin:
            echo_pin = Pin(trigger_pin)
        self.echo_pin = echo_pin
        self.precision = precision
        trigger_pin.init(Pin.OUT)
        trigger_pin.off()
        echo_pin.init(Pin.IN)
        echo_pin.init(Pin.OPEN_DRAIN)
        self.echo_timeout_us = echo_timeout_us
        self.distance = -10000
        Device.__init__(self, name, (trigger_pin, echo_pin),
                        on_change=on_change,
                        report_change=report_change,
                        filter=filter) 
Example #16
Source File: esp_8266.py    From python_banyan with GNU Affero General Public License v3.0 5 votes vote down vote up
def digital_write(self,payload):
  pin=payload['pin']
  mode=Pin.OUT
  if 'drain' in payload:
   if not payload['drain']:
    mode=Pin.OPEN_DRAIN
  pin_object=Pin(pin,mode)
  pwm=PWM(pin_object)
  pwm.deinit()
  Pin(pin,mode,value=payload['value'])
  self.input_pin_objects[pin]=None 
Example #17
Source File: hcsr04.py    From ulnoiot-upy with MIT License 5 votes vote down vote up
def __init__(self, name, trigger_pin, echo_pin,
                 echo_timeout_us=30000, precision=10,
                 on_change=None, report_change=True,
                 filter=None):
        # trigger_pin: Output pin to send pulses
        # echo_pin: Readonly pin to measure the distance.
        #           The pin should be protected with 1k resistor
        # echo_timeout_us: Timeout in microseconds to listen to echo pin.
        # By default is based in sensor limit range (4m)
        self.current_value = 0
        self._last_measured = 0
        if type(trigger_pin) is not Pin:
            trigger_pin = Pin(trigger_pin)
        self.trigger_pin = trigger_pin
        if type(echo_pin) is not Pin:
            echo_pin = Pin(trigger_pin)
        self.echo_pin = echo_pin
        self.precision = precision
        trigger_pin.init(Pin.OUT)
        trigger_pin.off()
        echo_pin.init(Pin.IN)
        echo_pin.init(Pin.OPEN_DRAIN)
        self.echo_timeout_us = echo_timeout_us
        self.distance = -10000
        Device.__init__(self, name, (trigger_pin, echo_pin),
                        on_change=on_change,
                        report_change=report_change,
                        filter=filter) 
Example #18
Source File: digitalio.py    From Adafruit_Blinka with MIT License 5 votes vote down vote up
def drive_mode(self, mod):
        self.__drive_mode = mod
        if mod is DriveMode.OPEN_DRAIN:
            self._pin.init(mode=Pin.OPEN_DRAIN)
        elif mod is DriveMode.PUSH_PULL:
            self._pin.init(mode=Pin.OUT) 
Example #19
Source File: esp_8266Full.py    From python_banyan with GNU Affero General Public License v3.0 5 votes vote down vote up
def set_mode_digital_output(self, payload):
        """
        Set pin as a digtal output
        :param payload:
        :return:
        """
        pin = payload['pin']
        mode = Pin.OUT
        if 'drain' in payload:
            if not payload['drain']:
                mode = Pin.OPEN_DRAIN
        Pin(pin, mode, value=payload['value'])