def pinMode(pin, mode): if pin < JET_PK1: #Set pin mode for Arduino pins if mode == OUTPUT_PIN: write_i2c_block(ard_address, pMode_cmd + [pin, 1, unused, unused, unused]) elif mode == INPUT_PIN: write_i2c_block(ard_address, pMode_cmd + [pin, 0, unused, unused, unused]) return 1 else: #reset the PH1 pin to the correct value. if pin == JET_PH1: pin = pin - 100 pin_name = "JET_" + str(pin) #Set pin mode for Jetson GPIO pins if mode == OUTPUT_PIN: globals()[pin_name] = Controller.alloc_pin(pin, OUTPUT) elif mode == INPUT_PIN: if (pin == (JET_PH1-100) or pin == JET_PK1 or pin == JET_PK2 or pin == JET_PK4): print ("You cannot set the output only jetson pins to inputs.") return -1 globals()[pin_name] = Controller.alloc_pin(pin, INPUT) return 1
def allocate(self, gpiopins, pressed_callback = None): ison = 1 if not self.__pullup else 0 def inputChanged(number,state): if state == ison: pressed_callback(number) for pin in gpiopins: Controller.alloc_pin(pin, INPUT, inputChanged if pressed_callback else None, BOTH)
def distanceSensor(): # Sensor pins Controller.available_pins = [38, 219] TRIG = Controller.alloc_pin(219, OUTPUT) ECHO = Controller.alloc_pin(38, INPUT) pulse_start = 0 pulse_end = 0 #Arm vehicle arm() #Change mode to MANUAL changeMode('MANUAL') while True: TRIG.reset() time.sleep(0.001) TRIG.set() time.sleep(0.001) TRIG.reset() begin = time.time() while ECHO.read()==0: pulse_start = time.time() if pulse_start - begin > 0.5: print "TIMEOUT" break while ECHO.read()==1: pulse_end = time.time() pulse_duration = pulse_end - pulse_start distance = pulse_duration * 17150 distance = round(distance, 2) #Set minimum distance to stop and turn around before the obstacle if distance <= 60: #STOP manualControl('NONE', 0, 'NONE', 0) print "HOLD",distance,"cm" #SPIN LEFT manualControl('NONE', 0, 'LEFT', 50) time.sleep(1) #STOP manualControl('NONE', 0, 'NONE', 0) else: #FORWARD manualControl('FORWARD', 50, 'NONE', 0) print "FORWARD:",distance,"cm"
def __init__(self, spi_port=0, spi_cs=192, spi_cs_gpio=BG_CS_FRONT_BCM): self.spi_cs_gpio = spi_cs_gpio self.spi_dev = spidev.SpiDev() self.spi_dev.open(spi_port, spi_cs) self.spi_dev.max_speed_hz = 400000 self.spi_dev.no_cs = True self.cs_pin = Controller.alloc_pin(self.spi_cs_gpio, OUTPUT) self.cs_pin.reset() time.sleep(0.05) self.cs_pin.set() self._write(REG_POWER_UP_RESET, 0x5a) time.sleep(0.02) for offset in range(5): self._read(REG_DATA_READY + offset) self._secret_sauce() product_id, revision = self.get_id() if product_id != 0x49 or revision != 0x00: raise RuntimeError( "Invalid Product ID or Revision for PMW3901: 0x{:02x}/0x{:02x}" .format(product_id, revision))
def __init__(self, pin_rs=165, pin_e=164, pins_db=[163, 162, 161, 160]): self.pin_rs = pin_rs self.pin_e = pin_e self.pins_db = pins_db Controller.available_pins = [pin_rs, pin_e] + pins_db pin_controllers = {} for pin in Controller.available_pins: pin_controllers[pin] = Controller.alloc_pin(pin, OUTPUT) self.pin_controllers = pin_controllers self.write4bits(0x33) # initialization self.write4bits(0x32) # initialization self.write4bits(0x28) # 2 line 5x7 matrix self.write4bits(0x0C) # turn cursor off 0x0E to enable cursor self.write4bits(0x06) # shift cursor right self.displaycontrol = self.LCD_DISPLAYON | self.LCD_CURSOROFF | self.LCD_BLINKOFF self.displayfunction = self.LCD_4BITMODE | self.LCD_1LINE | self.LCD_5x8DOTS self.displayfunction |= self.LCD_2LINE # Initialize to default text direction (for romance languages) self.displaymode = self.LCD_ENTRYLEFT | self.LCD_ENTRYSHIFTDECREMENT self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) # set the entry mode self.clear()
def speaker_gpio(gpio_pin): if gpio_pin == 0: print('Using DummyGPIO') class DummyGPIO: def set(self): pass def reset(self): pass yield DummyGPIO() print('Allocing pin {gpio_pin}.format(gpio_pin)', sys.stderr) gpio = Controller.alloc_pin(gpio_pin, OUTPUT) try: yield gpio finally: print('Deallocing pin {}'.format(gpio_pin), sys.stderr) gpio.reset() Controller.dealloc_pin(gpio_pin)
def __init__(self): pin_left_encoder = Controller.alloc_pin(186, INPUT, self.left_encoder, RISING) pin_right_encoder = Controller.alloc_pin(187, INPUT, self.right_encoder, RISING) pin_left_encoder.read() # Reads pin logic level pin_right_encoder.read() self.left_pub = rospy.Publisher("/encoder_left", Empty, queue_size=1) self.right_pub = rospy.Publisher("/encoder_right", Empty, queue_size=1) #print(dir(Controller)) rospy.on_shutdown(self.reactor_stop) try: reactor.run() except: pass
def allocate(self, gpiopins, pressed_callback=None, released_callback=None): ison = 1 if not self.__pullup else 0 def inputChanged(number, state): dt = time.time() if state == ison and dt > self.__bouncemap[ number] + self.__bouncetime: self.__bouncemap[number] = dt if pressed_callback: pressed_callback(number) elif state != ison and dt > self.__bouncemap[ number] + self.__bouncetime: self.__bouncemap[number] = dt if released_callback: released_callback(number) for pin in gpiopins: Controller.alloc_pin( pin, INPUT, inputChanged if pressed_callback or released_callback else None, BOTH) self.__bouncemap[pin] = time.time()
def __init__(self, brokerHost, brokerPort, rootTopic, gpioPins): self._rootTopic = rootTopic self._mqttClient = mqtt.Client(client_id='gpio', clean_session=False) self._mqttClient.on_connect = self._mqtt_on_connect self._mqttClient.on_message = self._mqtt_on_message self._brokerHost = brokerHost self._brokerPort = brokerPort Controller.available_pins = gpioPins self._gpioPins = { pin: Controller.alloc_pin(pin, INPUT) for pin in gpioPins } self._gpioValues = { pin: gpio.read() for pin, gpio in self._gpioPins.items() }
from sysfs.gpio import Controller, OUTPUT, INPUT, RISING Cap = cv2.VideoCapture(1) path = '/home/ubuntu/Kub_Dee/Python2_7' con = sq.connect(path + '/01_db/' + 'db_driver.conf') c = con.cursor() db_path = '/home/ubuntu/Kub_Dee/Python2_7/01_db' db_con = sq.connect(db_path + '/Data.conf') db_c = db_con.cursor() media_path = '/home/ubuntu/Kub_Dee/Python2_7/03_media' Controller.available_pins = [37, 186, 219] Vibra_pin = Controller.alloc_pin(37, OUTPUT) Button_pin = Controller.alloc_pin(186, INPUT) Shutdown_pin = Controller.alloc_pin(219, INPUT) Vibra_pin.set() _per_threshold_ = 0.9 _max_mar_threshold_ = 0.2 _min_mar_threshold_ = 0.15 _time_window_size_ = datetime.timedelta(seconds=3) _close_time_threshold_ = datetime.timedelta(seconds=2) _alarm_time_threshold_ = datetime.timedelta(seconds=3) _url_ = "https://meet.jit.si/Kub-Dee" class KubDeeApp(tk.Tk):
uuid = roslaunch.rlutil.get_or_generate_uuid(None, False) roslaunch.configure_logging(uuid) launch = roslaunch.parent.ROSLaunchParent( uuid, ["home/nvidia/EVObot/src/autonomous/launch/lanefollowergray.launch"]) Controller.available_pins = [388] def pin_input(number, state): # print("Pin '%d' changed to %d state" % (number, state)) if state == False: print("State: %d" % state) pin = Controller.alloc_pin(388, INPUT, pin_input, FALLING) while True: erg = pin.read() if len(entprellen) < 2: entprellen.append(erg) else: entprellen.append(erg) entprellen.pop(0) time.sleep(0.01) if entprellen[1] == False and entprellen[ 0] == True: # Entspricht falling edge counter = counter + 1 if counter == True:
Controller.available_pins = [2, 3] change_ts = datetime.now() def pin_changed(number, state): print("Pin '%d' changed to %d state" % (number, state)) global change_ts print(datetime.now() - change_ts) if (datetime.now() - change_ts) < timedelta(0, 10): return else: change_ts = datetime.now() print("Timedelta filter passed") if number == 2: # RIGHT urlopen("http://192.168.0.254:3000/RIGHT").read() else: # LEFT urlopen("http://192.168.0.254:3000/LEFT").read() Controller.alloc_pin(2, INPUT, pin_changed, FALLING) Controller.alloc_pin(3, INPUT, pin_changed, FALLING) if __name__ == '__main__': reactor.run()
def __init__(self): Controller.available_pins = [4] self.pin = Controller.alloc_pin(4, OUTPUT)
def output(self, pin, value): if value == 1: Controller.set_pin(pin) else: Controller.reset_pin(pin)
from sysfs.gpio import Controller, OUTPUT, INPUT, RISING cap = cv2.VideoCapture(1) path = '/home/ubuntu/Kub_Dee/Python2_7' con = sq.connect(path + '/01_db/' + 'db_driver.conf') c = con.cursor() db_path = '/home/ubuntu/Kub_Dee/Python2_7/01_db' db_con = sq.connect(db_path + '/Data.conf') db_c = db_con.cursor() media_path = '/home/ubuntu/Kub_Dee/Python2_7/03_media' Controller.available_pins = [37, 186] Vibra_pin = Controller.alloc_pin(37, OUTPUT) Button_pin = Controller.alloc_pin(186, INPUT) Vibra_pin.set() per_threshold = 0.9 time_window_size = datetime.timedelta(seconds=3) close_time_threshold = datetime.timedelta(seconds=2) alarm_time_threshold = datetime.timedelta(seconds=3) url = "https://meet.jit.si/Kub-Dee" class KubDeeApp(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.title_font = tkfont.Font(family='Helvetica',
def getState(self,number): state = Controller.get_pin_state(number) return state if not self.__pullup else not state
media_path = '/home/ubuntu/Kub_Dee/Python2_7/03_media' rc_path = '/media/ubuntu/Data/' + datetime.datetime.now().strftime( '%Y-%m-%d_%H-%M-%S') + '/' if not os.path.exists(rc_path): os.makedirs(rc_path) log_file = path + '/04_log/error_log_' + datetime.datetime.now().strftime( '%Y-%m-%d_%H-%M-%S') + '.log' ############################### #### GPIO Pin #### ############################### Controller.available_pins = [63, 184, 186] Vibra_pin = Controller.alloc_pin(184, OUTPUT) Button_pin = Controller.alloc_pin(63, INPUT) Shutdown_pin = Controller.alloc_pin(186, INPUT) Vibra_pin.set() ############################### #### Program Parameter #### ############################### _per_threshold_ = 0.8 _max_mar_threshold_ = 0.2 _min_mar_threshold_ = 0.15 _time_window_size_ = datetime.timedelta(seconds=3) _close_time_threshold_ = datetime.timedelta(seconds=2) _alarm_time_threshold_ = datetime.timedelta(seconds=3) _record_time_threshold_ = datetime.timedelta(minutes=10)
self.delayMicroseconds(1) # commands need > 37us to settle def message(self, text): """ Send string to LCD. Newline wraps to second line""" for char in text: if char == '\n': self.write4bits(0xC0) # next line else: self.write4bits(ord(char), True) def loop(): lcd = CharLCD() while True: lcd.clear() sleep(2) lcd.message(" TEST MODE !\n Whatup?") sleep(10) return lcd if __name__ == '__main__': try: lcd = loop() reactor.run() except: for pin in Controller.available_pins: Controller.dealloc_pin(pin) reactor.stop()
import os import subprocess import time from sysfs.gpio import Controller, OUTPUT, INPUT, RISING Controller.available_pins = [57] Button_pin = Controller.alloc_pin(57, INPUT) subprocess.Popen(['chromium-browser', 'www.arsenal.com', '--no-sandbox'], stdout=subprocess.PIPE) flag = 1 while flag: if Button_pin.read() == 0: subprocess.Popen(['pkill', 'chromium'], stdout=subprocess.PIPE) flag = 0 print 'it is f*****g work!!' i = 0 while i < 5: print '...' i += 1 time.sleep(3) subprocess.Popen(['chromium-browser', 'www.google.com', '--no-sandbox'], stdout=subprocess.PIPE)
def getState(self, number): state = Controller.get_pin_state(number) return state if not self.__pullup else not state
def setup(self, Pin, Mode): if Mode == 'out': Controller.alloc_pin(Pin, OUTPUT) elif Mode == 'in': Controller.alloc_pin(Pin, INPUT)
def __init__(self): Controller.available_pins = [self.PIN] self.pin_controller = Controller.alloc_pin(self.PIN, OUTPUT) self.pin_controller.set()
def read(self, pin): pin = Controller.alloc_pin(1, INPUT) return pin.read()
def destroy(self): self.pin_controller.set() Controller.dealloc_pin(self.PIN) reactor.stop()
# Import Twisted mainloop from twisted.internet import reactor # Import this package objects from sysfs.gpio import Controller, OUTPUT, INPUT, RISING # Refer to your chip GPIO numbers and set them this way Controller.available_pins = [1, 2, 3, 4] # Allocate a pin as Output signal pin = Controller.alloc_pin(1, OUTPUT) pin.set() # Sets pin to high logic level pin.reset() # Sets pin to low logic level pin.read() # Reads pin logic level # Allocate a pin as simple Input signal pin = Controller.alloc_pin(1, INPUT) pin.read() # Reads pin logic level # Allocate a pin as level triggered Input signal def pin_changed(number, state): print("Pin '%d' changed to %d state" % (number, state)) pin = Controller.alloc_pin(1, INPUT, pin_changed, RISING) pin.read() # Reads pin logic level