1 import RPi.GPIO as GPIO
2 GPIO.setmode(GPIO.BCM) # Use BCM pins D4 = GPIO #4
3 GPIO.setwarnings(False) # shh!
5 # Pins dont exist in CPython so...lets make our own!
19 def __init__(self, bcm_number):
25 def __eq__(self, other):
26 return self.id == other
28 def init(self, mode=IN, pull=None):
32 GPIO.setup(self.id, GPIO.IN)
33 elif mode == self.OUT:
35 GPIO.setup(self.id, GPIO.OUT)
37 raise RuntimeError("Invalid mode for pin: %s" % self.id)
39 if self._mode != self.IN:
40 raise RuntimeError("Cannot set pull resistor on output")
41 if pull == self.PULL_UP:
42 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
43 elif pull == self.PULL_DOWN:
44 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
46 raise RuntimeError("Invalid pull for pin: %s" % self.id)
48 def value(self, val=None):
52 GPIO.output(self.id, val)
53 elif val == self.HIGH:
55 GPIO.output(self.id, val)
57 raise RuntimeError("Invalid value for pin")
59 return GPIO.input(self.id)
83 SCLK = Pin(11) # Raspberry Pi naming
84 SCK = Pin(11) # CircuitPython naming
133 # ordered as spiId, sckId, mosiId, misoId
134 spiPorts = ((0, SCLK, MOSI, MISO), (1, SCLK_1, MOSI_1, MISO_1), (2, SCLK_2, MOSI_2, MISO_2))
136 # ordered as uartId, txId, rxId
142 (3, SCL, SDA), (1, SCL, SDA), (0, D1, D0), # both pi 1 and pi 2 i2c ports!