示例#1
0
def new_execute():
    global recst
    global recbtn
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(recbtn, GPIO.IN)
    GPIO.add_event_detect(recbtn,
                          GPIO.FALLING,
                          callback=btn_th,
                          bouncetime=200)
    phpath = "./data/rec/"
    os.makedirs(phpath, exist_ok=True)

    # Left Camera
    camera0 = nano.Camera(device_id=0, flip=2, width=224, height=224, fps=60)
    # Right Camera
    camera1 = nano.Camera(device_id=1, flip=2, width=224, height=224, fps=60)
    # wait rec button
    print("REC wait ...")
    waitrec()
    # rec start
    print("REC START! ...")
    #    recloop_old(camera0, "./data/apex/", 0.1)
    #    recloopDual_old(camera0,camera1, phpathL,phpathR, 0.1)
    #    recloopStereo_old(camera0,camera1, phpathMx, phpathL,phpathR, 0.1)
    recloopDual(camera0, camera1, phpath, 0.05)
    # testloop()
    print("REC END!! ...")
    camera0.release()
    camera1.release()
    # finish
    del camera0
    GPIO.cleanup()
示例#2
0
    def getDistance(self):
        # pins setup
        GPIO.setup(self.trig, GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup(self.echo, GPIO.IN)

        # set Trigger to HIGH for 10 us
        GPIO.output(self.trig, GPIO.HIGH)
        time.sleep(0.00001)  # 10 us
        GPIO.output(self.trig, GPIO.LOW)

        # start counting time at Echo rising edge
        GPIO.wait_for_edge(self.echo, GPIO.RISING, timeout=100)  # 100 ms
        startTime = time.time()

        # stop counting time at Echo falling edge
        GPIO.wait_for_edge(self.echo, GPIO.FALLING, timeout=100)  # 100 ms
        elapsedTime = time.time() - startTime  # in seconds

        distance = -1
        # check if the measurement succeeded
        if elapsedTime < 0.1:
            # get the distance in cm using sonic speed (aprox. 34300 cm/s)
            distance = (elapsedTime * 34300) / 2

        GPIO.cleanup([self.trig, self.echo])
        return distance
示例#3
0
def main():
    # Pin Setup:
    GPIO.setmode(GPIO.BOARD)  # BOARD pin-numbering scheme
    # GPIO.setup([led_pin_1, led_pin_2], GPIO.IN)  # LED pins set as output
    GPIO.setup(12, GPIO.IN)  # button pin set as input
    #GPIO.setup(led_pin_2, GPIO.IN)

    # Initial state for LEDs:
    # GPIO.output(led_pin_1, GPIO.LOW)
    # GPIO.output(led_pin_2, GPIO.LOW)

    GPIO.add_event_detect(12, GPIO.RISING, callback=blink1, bouncetime=10)
    #GPIO.add_event_detect(led_pin_2, GPIO.RISING, callback=blink2, bouncetime=10)

    print("Starting demo now! Press CTRL+C to exit")
    try:
        while True:

            input1 = GPIO.input(led_pin_1)
            #input2 = GPIO.input(led_pin_2)
            # blink LED 1 slowly
            print("Value read from pin {} : {}\n".format(input1, ' pin_1 low'))
            time.sleep(2)
            #print("Value read from pin {} : {}\n".format(input2, '2down'))
            # time.sleep(1)
    finally:
        GPIO.cleanup()  # cleanup all GPIOs
示例#4
0
def main():
    GPIO.setwarnings(False)

    GPIO.setmode(GPIO.BOARD)

    # GPIO.setup([stop, rec, menu], GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup([stop, rec, menu], GPIO.IN)

    # # attach callbacks to events
    # GPIO.add_event_detect(stop, GPIO.RISING, callback=stop_cb, bouncetime=200)
    # GPIO.add_event_detect(rec, GPIO.RISING, callback=rec_cb, bouncetime=200)
    # GPIO.add_event_detect(menu, GPIO.RISING, callback=menu_cb, bouncetime=200)

    GPIO.add_event_detect(stop, GPIO.RISING)
    GPIO.add_event_detect(rec, GPIO.RISING)
    GPIO.add_event_detect(menu, GPIO.RISING)

    while True:
        try:
            if GPIO.event_detected(stop):
                stop_cb()
            if GPIO.event_detected(rec):
                rec_cb()
            if GPIO.event_detected(menu):
                menu_cb()
            pass
        except KeyboardInterrupt:
            GPIO.cleanup()
            sys.exit()
示例#5
0
def main():
    # Pin Setup:
    # Board pin-numbering scheme
    GPIO.setmode(GPIO.BOARD)
    # set pin as an output pin with optional initial state of LOW
    GPIO.setup(trig_output_pin, GPIO.OUT, initial=GPIO.LOW)
    GPIO.setup(echo_input_pin, GPIO.IN)
    #value = GPIO.input(echo_input_pin)
    #print("Value read from pin {} : {}".format(echo_input_pin,value_str))

    print("Starting Measure now! Press CTRL+C to exit")
    try:
        while True:
            # Toggle the output every second
            GPIO.output(trig_output_pin, GPIO.HIGH)
            time.sleep(0.00001)
            GPIO.output(trig_output_pin, GPIO.LOW)
         
            pulse_start = time.time()
            while GPIO.input(echo_input_pin)==0:
                    pulse_start = time.time()

                    pulse_end = time.time()
                    while GPIO.input(echo_input_pin)==1:
                            pulse_end = time.time()

                            pulse_duration = pulse_end - pulse_start
                            distance = pulse_duration * 17150
                            distance = round(distance, 2)

                            print ("Distance" , distance)
            
    finally:
        GPIO.cleanup()
示例#6
0
def terminate(signalNumber, frame):
    # i2c.write_byte(0x71, 0x76)
    TCPconnection.close()
    UDPconnection.close()
    if useHardware:
        GPIO.cleanup()
    exit(0)
示例#7
0
def main(argv):
    global output_pin, frequency, state_flag, perma_state, random_flag, random_size, times
    if len(argv) == 1:
        print(
            'Using default values of: Output Pin = Board 12, Frequency = 30 Hz'
        )
    try:
        opts, args = getopt.getopt(
            argv, "hs:r:f:t:", ["state=", "random=", "frequency=", "times="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            usage()
            sys.exit()
        elif opt in ('-s', '--state'):
            state_flag = True
            perma_state = get_perma_state(arg)
        elif opt in ('-f', '--freq'):
            frequency = int(arg)
        elif opt in ('-r', '--random'):
            random_flag = True
            random_size = int(arg)
        elif opt in ('-t', '--times'):
            times = int(arg)

    signal.signal(signal.SIGINT, interrupt_handler)

    if state_flag:
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(output_pin, GPIO.OUT, initial=perma_state)
        GPIO.output(output_pin, perma_state)
        print('Output set to permanent state: {0}'.format(perma_state))
        GPIO.cleanup(output_pin)
    elif random_flag:
        # logging config
        # ToDo: Change the filename here if in the future our datasets change
        logging.basicConfig(
            filename='DataLog/TXDATA/transmitter_{0}Hz_{1}_cycles-{2}_bits.log'
            .format(frequency, times, random_size),
            level=logging.INFO,
            format='%(asctime)s %(message)s')
        random_bits = generate_random_bitstream(random_size)
        logging.info("Generated bitstream: {0}".format(random_bits))
        transmission = create_transmission(random_bits, times)
        f = open(
            'DataLog/TXDATA/raw_bitsream_{0}Hz_{1}_cycles-{2}_bits.txt'.format(
                frequency, times, random_size), "w+")
        f.write(transmission)
        print("Transmitting")
        logging.info("Starting Transmission")
        transmit(transmission)
        logging.info("Transmisssion Ended")
    else:
        print('No flags set, exiting')
        GPIO.output(output_pin, GPIO.LOW)
        usage()
        sys.exit(0)
示例#8
0
 def __del__(self):
     self.set_motion(0, 90, Mode.STOP)
     if self.softpwm_a.run_flag:
         self.softpwm_a.stop()
     if self.softpwm_b.run_flag:
         self.softpwm_b.stop()
     GPIO.cleanup()    
示例#9
0
def init():
    global rows
    global columns
    global colors
    A, B, C = GPIO.gpio_pin_data.get_data()

    GPIO.cleanup()
    GPIO.setmode(GPIO.BCM)

    i2c = busio.I2C(board.SCL, board.SDA)

    try:
        i2c.scan()
    except RuntimeError:
        raise RuntimeError("wire configuration incorrect")

    lcd = character_lcd(i2c, COLUMNS, ROWS)  #, backlight_inverted=False)
    lcd.message = "testing!"

    time.sleep(1)
    lcd.clear()
    lcd.message = "Hi"
    rows = [16, 6, 12, 13]
    colors = [18, 23]
    columns = [19, 20, 21]

    for color in colors:
        GPIO.setup(color, GPIO.OUT)
    for row in rows:
        GPIO.setup(row, GPIO.OUT)
    for column in columns:
        GPIO.setup(column, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
示例#10
0
def output_operation(pin, state):
    """
    Perform the OUTPUT operation
    """
    GPIO.setup(pin, GPIO.OUT)
    GPIO.output(pin, state)
    GPIO.cleanup()
示例#11
0
def shutdown(sig):
    try:
        GPIO.cleanup()
    except:
        print("Shutdown of Jetson.GPIO failed.")
        pass
    sys.exit(0)
示例#12
0
    def _shutdown(self):
        """Shutdown the radio.

        Puts the radio to sleep and cleans up the GPIO connections.
        """
        self._setHighPower(False)
        self.sleep()
        GPIO.cleanup()
def main():
    server = TcpIp('192.168.0.101', 1998)
    try:
        server.run()
    except KeyboardInterrupt:
        print("Done!")
        camera.release()
        GPIO.cleanup()
示例#14
0
def remove_air_sprays(front_sprayer=None, back_sprayer=None, time_interval=8):

    try:
        # Quantity of sprayers
        sprayers = len(front_sprayer)

        # Setting initial values for sprayers
        GPIO.setup(front_sprayer, GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup(back_sprayer, GPIO.OUT, initial=GPIO.LOW)

        # Initiating spray from the last one until the closest to the bar

        print(
            f'[WEEDS] OPENING the pin {front_sprayer[-1]} of the blue sprayer')
        print(
            f'[WEEDS] OPENING the pin {back_sprayer[-1]} of the red sprayer\n')
        GPIO.output(front_sprayer[-1], GPIO.HIGH)
        GPIO.output(back_sprayer[-1], GPIO.HIGH)
        sleep(time_interval)

        for index in range(1, sprayers):

            print(
                f'[WEEDS] CLOSING the pin {front_sprayer[-index]} of the blue sprayer'
            )
            print(
                f'[WEEDS] CLOSING the pin {back_sprayer[-index]} of the red sprayer\n'
            )
            GPIO.output(front_sprayer[-index], GPIO.LOW)
            GPIO.output(back_sprayer[-index], GPIO.LOW)
            sleep(time_interval)

            print(
                f'[WEEDS] OPENING the pin {front_sprayer[-index - 1]} of the blue sprayer'
            )
            print(
                f'[WEEDS] OPENING the pin {back_sprayer[-index - 1]} of the red \n'
            )

            GPIO.output(front_sprayer[-index - 1], GPIO.HIGH)
            GPIO.output(back_sprayer[-index - 1], GPIO.HIGH)
            sleep(time_interval)

        print(
            f'[WEEDS] CLOSING the pin {front_sprayer[-sprayers]} of the blue sprayer'
        )
        print(
            f'[WEEDS] CLOSING the pin {back_sprayer[-sprayers]} of the red sprayer\n'
        )
        GPIO.output(front_sprayer[-sprayers], GPIO.LOW)
        GPIO.output(back_sprayer[-sprayers], GPIO.LOW)

    except KeyboardInterrupt:
        print("[WEEDS] Turning off the sprayers.")
        GPIO.output(front_sprayer, GPIO.LOW)
        GPIO.output(back_sprayer, GPIO.LOW)
        GPIO.cleanup()
        sys.exit()
def card_tap():
    try:
        while True:
            id, text = reader.read()
            return id
            sleep(5)
    except KeyboardInterrupt:
        GPIO.cleanup()
        raise
示例#16
0
def handler(_signalRecieved, _frame):
    print("exiting with grace")

    safeNumber = 7
    GPIO.output(safeNumber, GPIO.HIGH)

    GPIO.cleanup()

    sys.exit(0)
示例#17
0
def module_exit():
    print("spi end")
    spi.SYSFS_software_spi_end()

    print("close 5V, Module enters 0 power consumption ...")
    GPIO.output(RST_PIN, 0)
    GPIO.output(DC_PIN, 0)

    GPIO.cleanup()
示例#18
0
    def __blink(self):
        GPIO.setmode(self.__pin_type)
        GPIO.setup(self.__output_pin, GPIO.OUT, initial=GPIO.HIGH)

        curr_value = GPIO.HIGH
        try:
            GPIO.output(self.__output_pin, curr_value)
            curr_value ^= GPIO.HIGH
        finally:
            GPIO.cleanup()
示例#19
0
    def __del__(self):
        for pin in self.pinlist:
            if pin == SERVO:
                self.setServo(8)
                self.servo.stop()
            elif pin == WAVE_ECHO:
                pass
            else:
                GPIO.output(pin, GPIO.LOW)

        GPIO.cleanup()
示例#20
0
def talker():
    rospy.init_node('Relay_Switcher')
    GPIO.setmode(GPIO.BOARD)
    for relay_name, relay_pin in config.items():
        GPIO.setup(relay_pin, GPIO.OUT)
        rospy.Subscriber('/relay/' + relay_name, Bool, callback,
                         (relay_name, relay_pin))
    r = rospy.Rate(10)
    while not rospy.is_shutdown():
        r.sleep()
    GPIO.cleanup()
示例#21
0
def main(args=None):
    rclpy.init(args=args)
    try:
        enviro = EnviroBoard()
        rclpy.spin(enviro)
    except KeyboardInterrupt:
        enviro.get_logger().info("ctrl-C detected, shutting down")
    finally:
        enviro.destroy_node()
        rclpy.shutdown()
        GPIO.cleanup()
示例#22
0
def main():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(output_pin, GPIO.OUT, initial=GPIO.LOW)
    try:
        while True:
            time.sleep(2)
            GPIO.output(output_pin, GPIO.HIGH)
            time.sleep(1)
            GPIO.output(output_pin, GPIO.LOW)
    finally:
        GPIO.cleanup()
示例#23
0
def main():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(LED_Pin, GPIO.OUT, initial=GPIO.HIGH)

    try:
        while True:
            GPIO.output(LED_Pin, GPIO.HIGH)
            time.sleep(0.1)
            GPIO.output(LED_Pin, GPIO.LOW)
            time.sleep(0.1)
    finally:
        GPIO.cleanup()
示例#24
0
def turn_on_pumps(left_pump=0, right_punp=0):
    try:
        # Setting initial values for sprayers
        GPIO.setup(left_pump, GPIO.OUT, initial=GPIO.HIGH)
        GPIO.setup(right_punp, GPIO.OUT, initial=GPIO.HIGH)

    except KeyboardInterrupt:
        print("[WEEDS] Turning off the pumps.")
        GPIO.output(left_pump, GPIO.LOW)
        GPIO.output(right_punp, GPIO.LOW)
        GPIO.cleanup()
        sys.exit()
示例#25
0
def main():
	direction_pin = 17 # BOARD12, BCM17
	output_pin = 18  # BOARD pin 12, BCM pin 18
	GPIO.setmode(GPIO.BCM)
	GPIO.setup(output_pin, GPIO.OUT, initial=GPIO.HIGH)
	GPIO.setup(direction_pin, GPIO.OUT, initial=GPIO.HIGH)

	try:	
		print("pulse")
		pulse(0.0002, output_pin, direction_pin)
	finally:	
		print("cleanup")
		GPIO.cleanup()	
示例#26
0
def setup_button(channel):
    print("{}: RESET GPIO {} for push".format(time.time(), channel))
    GPIO.cleanup(channel)
    GPIO.remove_event_detect(channel)
    GPIO.setup(channel, GPIO.OUT)
    GPIO.output(channel, GPIO.LOW)
    GPIO.setup(
        channel, GPIO.IN, pull_up_down=GPIO.PUD_DOWN
    )  # Set pin 10 to be an input pin and set initial value to be pulled low (off)
    #can use GPIO.RISING / FALLING / BOTH
    GPIO.add_event_detect(channel,
                          GPIO.RISING,
                          callback=button_callback,
                          bouncetime=300)  # Setup event on pin 10 rising edge
示例#27
0
def input_operation(pin):
    """
    Perform the INPUT operation
    """
    GPIO.setup(pin, GPIO.IN)
    print("Ctrl+C to exit")
    while 1:
        try:
            value = GPIO.input(pin)
            print(f"GPIO_READ pin {pin}: {value}")
            time.sleep(1)
        except KeyboardInterrupt:
            break
    GPIO.cleanup()
示例#28
0
def alarm():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setwarnings(True)
    GPIO.setup(23, GPIO.OUT)
    try:
        print("LED on")
        GPIO.output(23, GPIO.HIGH)
        time.sleep(3)

        #print ("LED off")
        GPIO.output(23, GPIO.LOW)
        GPIO.cleanup()
    except:
        KeyboardInterrupt
示例#29
0
	def cleanup(self):
		'''
		Cleans up the motor controller node, stopping motors and killing all threads 

		no return value
		
		'''
		rospy.loginfo("Cleaning up the motor_controller node..")
		self._thread_lock = False
		self.kill_motors()
		self.set_estop(1)
		try:
			GPIO.cleanup()
		except:
			pass
def main():
    # Pin Setup:
    # Board pin-numbering scheme
    GPIO.setmode(GPIO.BOARD)
    # set pin as an output pin with optional initial state of HIGH
    GPIO.setup(output_pin, GPIO.OUT, initial=GPIO.LOW)
    p = GPIO.PWM(output_pin, 100)
    p.start(50)

    print("PWM running. Press CTRL+C to exit.")
    try:
        while True:
           time.sleep(.1)
    finally:
        p.stop()
        GPIO.cleanup()