2 import Jetson.GPIO as GPIO
3 sys.path.append("/opt/nvidia/jetson-gpio/lib/python")
4 sys.path.append("/opt/nvidia/jetson-gpio/lib/python/Jetson/GPIO")
6 GPIO.setwarnings(False) # shh!
8 # Each Jetson model uses different I2C busses
9 JETSON_I2C_BUS_DEFS = {
12 "JETSON_XAVIER": [8, 1],
16 model = GPIO.get_model()
17 I2C_BUS = JETSON_I2C_BUS_DEFS[model][0]
18 I2C_BUS_1 = JETSON_I2C_BUS_DEFS[model][1]
20 # Pins dont exist in CPython so...lets make our own!
34 def __init__(self, bcm_number):
40 def __eq__(self, other):
41 return self.id == other
43 def init(self, mode=IN, pull=None):
47 GPIO.setup(self.id, GPIO.IN)
48 elif mode == self.OUT:
50 GPIO.setup(self.id, GPIO.OUT)
52 raise RuntimeError("Invalid mode for pin: %s" % self.id)
54 if self._mode != self.IN:
55 raise RuntimeError("Cannot set pull resistor on output")
56 if pull == self.PULL_UP:
57 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
58 elif pull == self.PULL_DOWN:
59 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
61 raise RuntimeError("Invalid pull for pin: %s" % self.id)
63 def value(self, val=None):
67 GPIO.output(self.id, val)
68 elif val == self.HIGH:
70 GPIO.output(self.id, val)
72 raise RuntimeError("Invalid value for pin")
74 return GPIO.input(self.id)
76 def cleanup(self, channel=None):
82 raise RuntimeError("Invalid pin to cleanup")
130 (I2C_BUS, SCL, SDA), (I2C_BUS_1, SCL_1, SDA_1),