txgpio

Twisted-based asynchronous library for using GPIO.

MIT License

Stars
5

txgpio

Twisted-based asynchronous library for using GPIO (over Sysfs) implemented in pure python.

Reading

Define protocol

class SysfsGPIOProtocol(Protocol):

    def dataReceived(self, data):
        self.factory.on_receive(data)

Define factory

class SysfsGPIOFactory(Factory):
    protocol = SysfsGPIOProtocol

    def on_receive(self, data):
        log.msg('Read value: {}'.format(data))

Create instances

    factory = SysfsGPIOFactory()
    protocol = factory.buildProtocol(None)
    GPIO(protocol, reactor=reactor, gpio_no=21, edge='both')

Let the reactor run

reactor.run()

See examples/ directory for reader & writer applications.