from gpiozero import Servo from time import sleep # Placeholder test code xServo = Servo(17) yServo = Servo(18) yServo.angle = 120 sleep(10) while True: for i in range(180): xServo.angle = i sleep(2) for i in range(180, 0, -1): xServo.angle = i
#!/usr/bin/env python3 from gpiozero import Servo from time import sleep servo = Servo(19) while True: print(servo.value) servo.mid() sleep(1) break
#!/usr/bin/env python # coding: Latin-1 # Load library functions we want import time import os import sys import pygame import ZeroBorg from gpiozero import Servo, LED tilt_servo = Servo(20) pan_servo = Servo(21) laser = LED(16) global joystick # Settings for the joystick laser_button = 1 # you may change this to use any button that you want tilt_axis = 5 # Joystick axis to tilt movement of 2DOF servo pan_axis = 2 # Joystick axis to pan movement of 2DOF servo axisR2 = 4 # Joystick axis to read for throttle acceleration axisL2 = 6 # Joystick axis to invert wheel rotation for reverse purpose axisUpDownInverted = True # Set this to True if up and down appear to be swapped axisLeftRight = 0 # Joystick axis to read for left / right position axisLeftRightInverted = True # Set this to True if left and right appear to be swapped buttonResetEpo = 3 # Joystick button number to perform an EPO reset (Start) buttonSlow = 6 # Joystick button number for driving slowly whilst held (L2) slowFactor = 0.5 # Speed to slow to when the drive slowly button is held, e.g. 0.5 would be half speed buttonFastTurn = 9 # Joystick button number for turning fast (R2) interval = 0.00 # Time between updates in seconds, smaller responds faster but uses more processor time TURN_MULTIPLIER = 0.4
from gpiozero import Servo from time import sleep #servo = Servo(17, min_pulse_width=0.55/1000, max_pulse_width=2.65/1000) servo1 = Servo(17, min_pulse_width=0.58/1000, max_pulse_width=2.70/1000, frame_width=40/1000) while True: servo1.min() sleep(1) # servo1.mid() servo1.value=-0.05 sleep(1) servo1.max() sleep(1)
from gpiozero import Servo import sys from time import sleep argc = len(sys.argv) if argc < 2: exit(argc) pin = -1 try: pin = int(sys.argv[1]) except ValueError: exit(pin) servo = Servo(pin) while True: servo.min() sleep(1) servo.mid() sleep(1) servo.max() sleep(1) servo.mid()
from picamera import PiCamera # use this custom pin-factory to fix servo jitter. # IMPORTANT: make sure pigpio deamon is running: 'sudo pigpiod' from gpiozero.pins.pigpio import PiGPIOFactory from gpiozero import Servo from time import sleep # create a custom pin-factory to fix servo jitter # more info here: https://gpiozero.readthedocs.io/en/stable/api_output.html#servo # and here: https://gpiozero.readthedocs.io/en/stable/api_pins.html pigpio_factory = PiGPIOFactory() servo = Servo(17, pin_factory=pigpio_factory) targariferimento = "FV-I81EX" camera = PiCamera() camera.resolution = (1024, 720) i = 0 while True: camera.capture("/home/pi/Desktop/timelapse/image{0:04d}.jpg".format(i)) img = cv2.imread( str("/home/pi/Desktop/timelapse/image{0:04d}.jpg".format(i)), cv2.IMREAD_COLOR) img = cv2.resize(img, (1024, 720))
#from gpiozero import import json import drop_box from gpiozero import DistanceSensor as US from gpiozero import LED, Servo from time import sleep import asyncio # LEDs scannerLed = LED(23) powerLed = LED(20) openLed = LED(16) # Servo latch = Servo(5) # US Sensors boxUS = US(trigger=27, echo=22) lidUS = US(trigger=13, echo=6) barUS = US(trigger=26, echo=19) # drop_box.upload("data_upload.json") def openLatch(): latch.min() def closeLatch(): latch.max() async def closeOnLid() {
from time import sleep from signal import pause from gpiozero.pins.pigpio import PiGPIOFactory #Calibrate Servos myCorrection = 0.5 maxPW = (2.0 + myCorrection) / 1000 minPW = (1.0 - myCorrection) / 1000 #Set Servo Pins myGPIO1 = 15 #back servo myGPIO2 = 18 #front sonar servo myGPIO3 = 23 #front camera servo #Create Servos back_servo = Servo(myGPIO1, min_pulse_width=minPW, max_pulse_width=maxPW, pin_factory=PiGPIOFactory()) f_sonar_servo = Servo(myGPIO2, min_pulse_width=minPW, max_pulse_width=maxPW, pin_factory=PiGPIOFactory()) f_cam_servo = Servo(myGPIO3, min_pulse_width=minPW, max_pulse_width=maxPW, pin_factory=PiGPIOFactory()) #Create Robot motors robot = Robot(left=(12, 16), right=(21, 20)) #Create Sonar devices front_sensor = DistanceSensor(7, 8)
""" Web : https://gpiozero.readthedocs.io/en/v1.3.1/api_output.html?highlight=servo#servo Usage : python servo_sg90_basic.py """ from gpiozero import Servo from time import sleep from sys import exit import signal try: gpio_pin_num = int(raw_input("Which gpio pin?")) except ValueError: print "Oops! That was no valid number. Try again.." exit() servo = Servo(gpio_pin_num, min_pulse_width=0.0005, max_pulse_width=0.0025) try: while True: servo.min() sleep(1) servo.mid() sleep(1) servo.max() sleep(1) servo.mid() sleep(1) except KeyboardInterrupt: pass finally: print("Handling Ctrl+C")
"""Test servo connections on a Pi3 via PiGPIOd. Ensure `sudo pigpiod` issued before running. This is the high-performance PWM route for GPIOZero, which allows at least 8 servos to be contrlled without unreasonable jitter. Useful for testing servo connections, and indeed individual servo function with 3.3V control signal.""" from gpiozero import Device, Servo from gpiozero.pins.pigpio import PiGPIOFactory from time import sleep Device.pin_factory = PiGPIOFactory() myservo = [ Servo(27), Servo(22), Servo(5), Servo(6), Servo(13), Servo(19), Servo(26), Servo(21) ] for i in range(8): myservo[i].min() # sleep(0.1) sleep(1)
#!/usr/bin/env python3 from gpiozero import Servo from time import sleep servo = Servo( 17, min_pulse_width=500 / 1000000, max_pulse_width=2400 / 1000000, frame_width=200 / 10000 #=20ms ) print(servo.min_pulse_width) print(servo.max_pulse_width) print(servo.frame_width) while True: servo.min() sleep(2) servo.max() sleep(2)
#!/usr/bin/env python3 """A demo of the Google CloudSpeech recognizer.""" import sys import aiy.audio import aiy.cloudspeech import aiy.voicehat from gpiozero import Servo from time import sleep myCorrection = 0 maxPW = (2.0 + myCorrection) / 1000 minPW = (1.0 + myCorrection) / 1000 servo1 = Servo(26, min_pulse_width=minPW, max_pulse_width=maxPW) def main(): while True: print('Press the button and speak') for value in range(0, 21): value2 = (float(value) - 10) / 10 servo1.value = value2 print(value2) sleep(0.5) if __name__ == '__main__': main()
#!/usr/bin/python3 from gpiozero import Servo from aiy.pins import PIN_A from aiy.pins import PIN_B import sys from threading import Timer steering = Servo(PIN_A) speed = Servo(PIN_B) DRIVE_FORWARD_SPEED = 0.20 DRIVE_BACK_SPEED = -0.41 STEERING_STRAIGHT = -0.11 last_back = False def drive_forward(): speed.value = DRIVE_FORWARD_SPEED steering.value = STEERING_STRAIGHT def drive_right(): speed.value = DRIVE_FORWARD_SPEED steering.min() def drive_left(): speed.value = DRIVE_FORWARD_SPEED steering.max()
from gpiozero import Servo # importamos los modulos necesarios from time import sleep servo = Servo(18) # definimos el servo conectado al gpio 18 while True: # bucle infinito servo.min() # posicion de un extremo sleep(2) # esperamos 2 segundos servo.mid() # posicion central sleep(2) # esperamos 2 segundos servo.max() # posicion del otro extremo sleep(2) # esperamos 2 segundos
time_start = time() seconds = 0 minutes = 0 currentRpm = 0 # pin for hardwares lcd = Adafruit_CharLCD(rs=26, en=19, d4=13, d5=6, d6=5, d7=11, cols=16, lines=2) led = PWMLED(17) servo = Servo(22) button = Button(4) # setup servo.max() # founctions to call in the futurei # stage 0 wait for starting def WaifForStart(): if stage == 0: lcd.clear() lcd.message("Press Button") # stage 1, spining
from gpiozero import Servo from gpiozero import LED from time import sleep servoPin = 17 #ledPin = 17 myservo = Servo(servoPin) #myled = LED(ledPin) while True: myservo.min() #myled.on() sleep(0.5) myservo.max() # myled.off() sleep(0.5)
from time import sleep from gpiozero import Button, LED, Servo import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) from threading import Thread import serial ser = serial.Serial('/dev/ttyACM0', 9600) beebutton = Button(26) GPIO.setup(17,GPIO.IN, pull_up_down=GPIO.PUD_DOWN) sunbutton = Button(21) servo = Servo(18) GPIO.setup(24,GPIO.OUT) shutdown = False #a variable to keep the treads running solved_bee = False #a variable to keep track if the bee puzzle has been solved solved_rain = False #a variable to keep track if the rain puzzle has been solved solved_sun = False #a variable to keep track if the sun puzzle has been solved count = 0 #to keep count of how many times the handle has been turned def watch_bee(): global shutdown, solved_bee #allows the global variables to be carried in and changed from within the function bb_on = False #starts the bounce handling while not shutdown: if beebutton.is_pressed and bb_on == False: #if button is pressed and hasn't been pressed before ('bb_on' variable = false) solved_bee = (solved_bee+1)%2
from gpiozero import Servo from time import sleep servoPan = Servo(26) servoTilt = Servo(6) def Pan(): servoPan.mid() sleep(1) def Tilt(): servoTilt.mid() sleep(1) while True: Pan() sleep(1) Tilt() sleep(1)
from gpiozero import Servo from time import sleep myGPIO=12 servo = Servo(myGPIO) while True: servo.mid() print("mid") sleep(2) servo.min() print("min") sleep(2) servo.mid() print("mid") sleep(2) servo.max() print("max") sleep(2)
def run(window, device, host, port): run_window = window factory = PiGPIOFactory(host=host, port=port) if device in (N_DigitalOutputDevice, N_LED, N_Buzzer): run_window.Layout(led_layout()) switch = False device_open = False while True: event, values = run_window.read() if event == '-pin-': if device_open: sg.popup_no_titlebar("Close device first!") if event == '-open-': if not device_open: if values['-pin-'] == 'Select pin': sg.popup_no_titlebar("Select your pin!") continue else: d = DigitalOutputDevice(values['-pin-'], pin_factory=factory) device_open = True run_window['-open-'].update(image_data=icon_close) else: device_open = False switch = False run_window['-open-'].update(image_data=icon_open) run_window['-switch-'].update(image_data=icon_switch_off) d.close() if event == '-switch-': if device_open: switch = not switch run_window['-switch-'].update(image_data=icon_switch_on if switch else icon_switch_off) d.on() if switch else d.off() else: sg.popup_no_titlebar("Open device first!") if event in (sg.WIN_CLOSED, 'Exit'): break elif device in (N_PWMOutputDevice, N_PWMLED): run_window.Layout(pwmled_layout()) device_open = False while True: event, values = run_window.read() if event in (sg.WIN_CLOSED, 'Exit'): break # if not exit-event, get param cycle = 0 if str(values['-cycle-']).startswith('Select') else values['-cycle-'] frequency = 100 if values['-frequency-'].startswith('Select') else int( values['-frequency-'].replace('Hz', '')) if event == '-pin-': if device_open: sg.popup_no_titlebar("Close device first!") if event == '-frequency-': if device_open: d.frequency = frequency if event == '-cycle-': if device_open: d.value = cycle if event == '-open-': if not device_open: if values['-pin-'] == 'Select pin': sg.popup_no_titlebar("Select your pin!") continue else: d = PWMOutputDevice(values['-pin-'], initial_value=cycle, frequency=frequency, pin_factory=factory) device_open = True run_window['-open-'].update(image_data=icon_close) else: device_open = False d.close() run_window['-open-'].update(image_data=icon_open) if event == '-pulse-': if device_open: d.pulse() else: sg.popup_no_titlebar("Open device first!") elif device == N_Servo: run_window.Layout(servo_layout()) device_open = False while True: event, values = run_window.read() if event in (sg.WIN_CLOSED, 'Exit'): break value = 0 if str(values['-value-']).startswith('Select') else values['-value-'] min_pulse_width = (1 if values['-min_pulse_width-'].startswith('Select') else float( values['-min_pulse_width-'].replace('ms', ''))) / 1000 max_pulse_width = (2 if values['-max_pulse_width-'].startswith('Select') else float( values['-max_pulse_width-'].replace('ms', ''))) / 1000 if event == '-pin-': if device_open: sg.popup_no_titlebar("Close device first!") if event == '-value-': if device_open: d.value = value if event in ('-min_pulse_width-', '-max_pulse_width-'): if device_open: sg.popup_no_titlebar('Pulse-width param only work before open!') if event == '-open-': if not device_open: if values['-pin-'] == 'Select pin': sg.popup_no_titlebar("Select your pin!") continue else: d = Servo(values['-pin-'], initial_value=value, min_pulse_width=min_pulse_width, max_pulse_width=max_pulse_width, pin_factory=factory) device_open = True run_window['-open-'].update(image_data=icon_close) else: device_open = False d.close() run_window['-open-'].update(image_data=icon_open) elif device == N_AngularServo: run_window.Layout(angularservo_layout()) device_open = False while True: event, values = run_window.read() if event in (sg.WIN_CLOSED, 'Exit'): break angle = 0 if str(values['-angle-']).startswith('Select') else values['-angle-'] min_angle = -90 if str(values['-min_angle-']).startswith('Select') else values['-min_angle-'] max_angle = 90 if str(values['-max_angle-']).startswith('Select') else values['-max_angle-'] min_pulse_width = (1 if values['-min_pulse_width-'].startswith('Select') else float( values['-min_pulse_width-'].replace('ms', ''))) / 1000 max_pulse_width = (2 if values['-max_pulse_width-'].startswith('Select') else float( values['-max_pulse_width-'].replace('ms', ''))) / 1000 if event == '-pin-': if device_open: sg.popup_no_titlebar("Close device first!") if event == '-angle-': if device_open: d.angle = angle if event in ('-min_pulse_width-', '-max_pulse_width-', '-min_angle-', '-max_angle-'): if device_open: sg.popup_no_titlebar('Pulse-width param only work before open!') if event == '-open-': if not device_open: if values['-pin-'] == 'Select pin': sg.popup_no_titlebar("Select your pin!") continue else: d = AngularServo(values['-pin-'], initial_angle=angle, min_angle=min_angle, max_angle=max_angle, min_pulse_width=min_pulse_width, max_pulse_width=max_pulse_width, pin_factory=factory) device_open = True run_window['-open-'].update(image_data=icon_close) else: device_open = False d.close() run_window['-open-'].update(image_data=icon_open) elif device == N_PhaseEnableMotor: run_window.Layout(phaseenablemotor_layout()) device_open = False while True: event, values = run_window.read() if event in (sg.WIN_CLOSED, 'Exit'): break # if not exit-event, get param speed = 0 if str(values['-speed-']).startswith('Select') else values['-speed-'] if event == '-direction_pin-': if device_open: sg.popup_no_titlebar("Close device first!") if event == '-speed_pin-': if device_open: sg.popup_no_titlebar("Close device first!") if event == '-speed-': if device_open: d.value = speed if event == '-open-': if not device_open: select = 'Select direction pin' if values['-direction_pin-'] == select or values['-speed_pin-'] == select: sg.popup_no_titlebar("Select your pin!") continue else: d = PhaseEnableMotor(phase=values['-direction_pin-'], enable=values['-speed_pin-'], pin_factory=factory) d.value = 0 device_open = True run_window['-open-'].update(image_data=icon_close) else: device_open = False d.close() run_window['-open-'].update(image_data=icon_open) elif device == N_Button: run_window.Layout(button_layout()) device_open = False while True: event, values = run_window.read() if event in (sg.WIN_CLOSED, 'Exit'): break # if not exit-event, get param if event == '-pin-': if device_open: sg.popup_no_titlebar("Close device first!") if event == '-pull_up-': if device_open: sg.popup_no_titlebar('pull-up param only work before open!') if event == '-test-': if device_open: sg.popup_no_titlebar('Now you can test button!') d.wait_for_press() sg.popup_no_titlebar('Yuu pressed button!') d.wait_for_release() sg.popup_no_titlebar('Yuu released button!') else: sg.popup_no_titlebar("Open device first!") if event == '-open-': if not device_open: if values['-pin-'] == 'Select pin': sg.popup_no_titlebar("Select your pin!") continue else: pull_up = True if str(values['-pull_up-']).startswith('Select') else values['-pull_up-'] d = Button(values['-pin-'], pull_up=pull_up, bounce_time=0.1, pin_factory=factory) device_open = True run_window['-open-'].update(image_data=icon_close) else: device_open = False d.close() run_window['-open-'].update(image_data=icon_open) elif device in (N_LineSensor, N_MotionSensor, N_LightSensor): run_window.Layout(linesensor_layout()) device_open = False while True: event, values = run_window.read() if event in (sg.WIN_CLOSED, 'Exit'): break if event == '-pin-': if device_open: sg.popup_no_titlebar("Close device first!") if event == '-test-': if device_open: sg.popup_no_titlebar('Now you can test sensor!') d.wait_for_active() sg.popup_no_titlebar('device now is active!') d.wait_for_inactive() sg.popup_no_titlebar('device now is inactive, Test over!') else: sg.popup_no_titlebar("Open device first!") if event == '-open-': if not device_open: if values['-pin-'] == 'Select pin': sg.popup_no_titlebar("Select your pin!") continue else: d = eval(device)(pin=values['-pin-'], pin_factory=factory) device_open = True run_window['-open-'].update(image_data=icon_close) else: device_open = False d.close() run_window['-open-'].update(image_data=icon_open)
import RPi.GPIO as GPIO from gpiozero import Servo from time import sleep import readchar myCorrection = 0 maxPW = (2.0 + myCorrection) / 1000 minPW = (1.0 - myCorrection) / 1000 servo = Servo(26, min_pulse_width=minPW, max_pulse_width=maxPW) servo2 = Servo(21, min_pulse_width=minPW, max_pulse_width=maxPW) #right servo servoPINBase = Servo( 17, min_pulse_width=minPW, max_pulse_width=maxPW) # This is to control the base movement servoPINClaw = Servo(4, min_pulse_width=minPW, max_pulse_width=maxPW) # This is to control the claw basePos = 0 stdIncrement = .1 def baseRight(): global basePos global stdIncrement if (basePos < 1): basePos = basePos + stdIncrement base.value = basePos sleep(0.5) def baseLeft(): global basePos
# testing servo control with pwm gpio output from gpiozero import Servo from time import sleep servo = Servo(13, min_pulse_width=0.001, max_pulse_width=0.002) servo.min()
from gpiozero import Servo from time import sleep servo = Servo(16) while True: servo.min() print("0 derajat") sleep(2) servo.mid() print("90 derajat") sleep(2) servo.max() print("180 derajat") sleep(2)
import RPi.GPIO as IO import time import ast import firebase_admin import firebase_cred from firebase_admin import credentials from firebase_admin import firestore from gpiozero import Servo from time import sleep collection = firebase_cred.smart_lock_col PIN_IR = 25 PIN_SERVO = Servo(14) IO.setmode(IO.BCM) IO.setup(PIN_IR, IO.IN) while True: sensor_ref = collection.document(u'sensor') sensors = sensor_ref.get() sensors_string_dict = '{}'.format(sensors.to_dict()) sensors_dict = ast.literal_eval(sensors_string_dict) confirm = sensors_dict['confirm'] infrared = sensors_dict['infrared'] servo = sensors_dict['servo'] if infrared == 1: #sensor_ref.update({'infrared': 1}) #sensor_ref.update({'servo': 1}) print("Infrared Activated")
import RPi.GPIO as GPIO from gpiozero import Servo import random import time from PIL import Image from thermalprinter import * import subprocess GPIO.setmode(GPIO.BCM) servo = Servo(8) GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(9, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(7, GPIO.OUT) def water(): servo.max() time.sleep(1) GPIO.output(7, True) time.sleep(2) GPIO.output(7, False) time.sleep(0.5) servo.min() def insults(): with ThermalPrinter(port='/dev/ttyAMA0') as printer:
from gpiozero import Servo from time import sleep servo = Servo(17) while True: servo.min() sleep(0.5) servo.mid() sleep(0.5) servo.max() sleep(0.5)
from gpiozero import Servo from time import sleep from sys import argv, exit myGPIO = 17 myCorrection = 0.45 maxPW = (2.0 + myCorrection) / 1000 minPW = (1.0 - myCorrection) / 1000 myServo = Servo(myGPIO, min_pulse_width=minPW, max_pulse_width=maxPW) print("Different Jiggle") myServo.value = 0.35 sleep(1) myServo.value = -0.3 sleep(1) myServo.value = 0.35 sleep(1) myServo.value = -0.3 sleep(1) myServo.value = 0 sleep(0.3) exit()
tiltToPercentage(x) time.sleep(0.1) for x in range(100, -5, -5): panToPercentage(x) time.sleep(0.1) tiltToPercentage(50) panToPercentage(50) time.sleep(0.2) pan_servo.detach() tilt_servo.detach() global tilt_servo global pan_servo if __name__ == '__main__': tilt_servo = Servo(TILT_PIN, min_pulse_width=PULSE_MIN, max_pulse_width=PULSE_MAX, frame_width=PULSE_WIDTH) pan_servo = Servo(PAN_PIN, min_pulse_width=PULSE_MIN, max_pulse_width=PULSE_MAX, frame_width=PULSE_WIDTH) logging.info("Starting demo loop") while True: try: demo() time.sleep(10) pan_servo.detach() tilt_servo.detach() except KeyboardInterrupt: logging.info("interrupted, exiting") break pan_servo.detach() tilt_servo.detach() logging.debug("Done")
time2 = 0 cam = None vs = None window_name = "" elapsedtime = 0.0 g_plugin = None g_inferred_request = None g_heap_request = None g_inferred_cnt = 0 g_number_of_allocated_ncs = 0 LABELS = ["neutral", "happy", "sad", "surprise", "anger"] COLORS = np.random.uniform(0, 255, size=(len(LABELS), 3)) happyServo = Servo(12) sadServo = Servo(13) angreyServo = Servo(18) def camThread(LABELS, resultsEm, frameBuffer, camera_width, camera_height, vidfps, number_of_camera, mode_of_camera): global fps global detectfps global lastresults global framecount global detectframecount global time1 global time2 global cam global vs global window_name
#!/usr/bin/env python3 """Demonstrates simultaneous control of two servos on the hat. One servo uses the simple default configuration, the other servo is tuned to ensure the full range is reachable. """ from time import sleep from gpiozero import Servo from aiy.pins import PIN_A from aiy.pins import PIN_B # Create a default servo that will not be able to use quite the full range. simple_servo = Servo(PIN_A) # Create a servo with the custom values to give the full dynamic range. tuned_servo = Servo(PIN_B, min_pulse_width=.0005, max_pulse_width=.0019) # Move the Servos back and forth until the user terminates the example. while True: simple_servo.min() tuned_servo.max() sleep(1) simple_servo.mid() tuned_servo.mid() sleep(1) simple_servo.max() tuned_servo.min() sleep(1)