2 from periphery import GPIO
4 raise ImportError("Periphery Python bindings not found, please install and try again! Try running 'pip3 install python-periphery'")
6 # Pins dont exist in CPython so...lets make our own!
15 _CONSUMER = 'adafruit_blinka'
21 def __init__(self, pin_id):
23 if type(pin_id) is tuple:
24 self._num = int(pin_id[1])
25 self._chippath = "/dev/gpiochip{}".format(pin_id[0])
27 self._num = int(pin_id)
28 self._chippath = "/dev/gpiochip0"
34 def __eq__(self, other):
35 return self.id == other
37 def init(self, mode=IN, pull=None):
41 if self._line is not None:
43 self._line = GPIO(self._chippath, int(self._num), self.IN)
44 elif mode == self.OUT:
46 if self._line is not None:
48 self._line = GPIO(self._chippath, int(self._num), self.OUT)
50 raise RuntimeError("Invalid mode for pin: %s" % self.id)
53 if pull == self.PULL_UP:
54 raise NotImplementedError("Internal pullups not supported in periphery, use physical resistor instead!")
55 elif pull == self.PULL_DOWN:
56 raise NotImplementedError("Internal pulldowns not supported in periphery, use physical resistor instead!")
58 raise RuntimeError("Invalid pull for pin: %s" % self.id)
60 def value(self, val=None):
64 self._line.write(False)
65 elif val == self.HIGH:
67 self._line.write(True)
69 raise RuntimeError("Invalid value for pin")
71 return self.HIGH if self._line.read() else self.LOW