def handle_open_gripper(req): servoPI = 17 GPIO.setMode(GPIO.BCM) GPIO.setup(servoPIN. GPIO.OUT) p= GPIO.PWM(servoPIN, 50) p.start(2.5) if req.command == 0: print "Stopping gripper" p.stop() GPIO.cleanup() elif req.command == 1: print "Opening gripper" while True: p.ChangeDutyCycle(12.5) time.sleep(0.5) else: print "Closing gripper" while True: p.ChangeDutyCycle(2.5) time.sleep(0.5) print "Request completed" return YargControlResponse(True)
def __init__(self): GPIO.setMode(GPIO.BCM) # Trigger and Echo Pins self.trigger = Constants.TRIGGER_PORT self.echo = Constants.ECHO_PORT # Setup trigger and echo ports GPIO.setup(self.trigger, GPIO.OUT) GPIO.setup(self.echo, GPIO.IN)
def setup(): global pwm global dc GPIO.setMode(GPIO.BCM) # use BCM Pin number GPIO.setup(pwmPin, GPIO.OUT) GPIO.setup(readPin, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.add_event_detect(readPin, GPIO.RISING, callback = handler) pwm = GPIO.PWM(pwm, dc) pwm.start(dc) print("pwmPin = %d" % pwmPin) print("Mode = OUT, duty cycle : %d" % dc) print("readPin = %d" % readPin) print("Mode = IN, PULL_UP")
def setup(): # use physical pin numbering GPIO.setMode(GPIO.BOARD) GPIO.setup(headlightButtonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(thrusterButtonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(nasaSoundsButtonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # define headlight pins to be output pins GPIO.setup(leftHeadlightLed, GPIO.OUT) GPIO.setup(rightHeadlightLed, GPIO.OUT) GPIO.setup(thruster1Led, GPIO.OUT) GPIO.setup(thruster2Led, GPIO.OUT) GPIO.setup(thruster3Led, GPIO.OUT) # set initial state of headlights to be low GPIO.output(leftHeadlightLed, GPIO.LOW) GPIO.output(rightHeadlightLed, GPIO.LOW) GPIO.output(thruster1Led, GPIO.LOW) GPIO.output(thruster2Led, GPIO.LOW) GPIO.output(thruster3Led, GPIO.LOW)
def __init__(self): self.mode = GPIO.getmode() # Left motor self.in1 = Constants.IN1_PORT self.in2 = Constants.IN2_PORT self.ena = Constants.ENA_PORT # Right motor self.in3 = Constants.IN3_PORT self.in4 = Constants.IN4_PORT self.enb = Constants.ENB_PORT GPIO.setMode(GPIO.BCM) self.left_motor = GPIO.PWM(self.ena, 1000) self.right_motor = GPIO.PWM(self.enb, 1000) # Initial Duty Cycle - 25% self.left_motor.start(25) self.right_motor.start(25) # Proportional constant self.kP = Constants.kP
cv2.imshow('Detected Circles', circle_img) cv2.waitKey(0) circle_file = open('circles_list.txt', 'w') circle_file.write('x ,\t y,\t Radius,\t Threshold \n') for i in range(len(circles)): circle_file.write(str(circles[i][0]) + ' , ' + str(circles[i][1]) + ' , ' + str(circles[i][2]) + ' , ' + str(circles[i][3]) + '\n') circle_file.close() if circle_img is not None: cv2.imwrite("circles_img.png", circle_img) servoPIN = 17 PWM = 50 # Servo section GPIO.setMode(GPIO.BCM) GPIO.setup(servoPIN, GPIO.OUT) p = GPIO.PWM(servoPIN, PWM) p.start(2.5) rotateDir = True rotateCounter = 2.5 for i in range(circleCount): if rotateDir: rotateCounter += 2.5 p.ChangeDutyCycle(rotateCounter) if rotateCounter == 12.5: rotateDir = False else:
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setMode(23, OUTPUT); GPIO.setMode(24, OUTPUT); GPIO.setMode(25, OUTPUT); GPIO.setMode(16, OUTPUT); // Setup input GPIO.setMode(17, INPUT); GPIO.setMode(27, INPUT); GPIO.setMode(22, INPUT)
import RPi.GPIO as GPIO import time import socket GPIO.setMode(GPIO.); pinA1 = 4 pinA2 = 5 pinB1 = 6 pinB2 = 7 enPin = 18 GPIO.setup(enPin,GPIO.OUT) GPIO.setup(pinA1,GPIO.OUT) GPIO.setup(pinA2,GPIO.OUT) GPIO.setup(pinB1,GPIO.OUT) GPIO.setup(pinB2,GPIO.OUT) GPIO.output(enPin,1) ip_addr = socket.gethostbyname(socket.gethostname()) port = 6000 server = socket.socket(socket.AF_INET,socket.SOCK_STREAM) server.bind((ip_addr,port)) server.listen(1) print "Server Listening" (client,address) = server.accept() print "Server Connected" while client:
#!/usr/bin/python3 import threading import time from tkinter import * import RPi.GPIO as GPIO GPIO.setMode(GPIO.BOARD) GPIO.setup(37, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(40, GPIO.IN, pull_up_down=GPIO.PUT_UP) root = Tk() def test(): q=1 print("im a fuchtion") while True: q=q def photo(): canvas = Canvas(root, width = 1280, height = 720) root.attributes("-fullscreen", True) canvas.pack() img = PhotoImage(file="onTheWay.gif") canvas.create_image(0,0, anchor=NW, image=img) mainloop() thread = threading.Thread(target=o, args=()) thread.start()
def initBoard(self): GPIO.setMode(GPIO.BOARD)