def __init__(self, i2c):
        s = servo.Servos(i2c)
        servo_list = []
        for n in range(16):
            servo_list.append(Servo9686(s, n))
        servo_list.append(ServoDirect(Pin(0)))
        servo_list.append(ServoDirect(Pin(2)))

        # Set them all to 90 degrees
        for n in range(18):
            servo_list[n].position(90)
        self.servo_list = servo_list
Пример #2
0
import machine
import servo
import time

# GPIO->PIN
pin = [16, 5, 4, 0, 2, 14, 12, 13, 15, 3, 1, 9, 10]

# Initialize I2C
dis_i2c = machine.I2C(sda=machine.Pin(pin[7]), scl=machine.Pin(pin[6]))
servos = servo.Servos(dis_i2c)

# Main program
servos.position(0, degrees=180)
time.sleep(3)
servos.position(0, degrees=0)
Пример #3
0
# Handle if these were reversed...
tmp = max(STEERING_SERVO_MIN_US, STEERING_SERVO_MAX_US)
STEERING_SERVO_MIN_US = min(STEERING_SERVO_MIN_US, STEERING_SERVO_MAX_US)
STEERING_SERVO_MAX_US = tmp

device = None

if ARDUINO_SERVO_CONTROLLER:
    device = pyb.UART(3, 19200, timeout_char=1000)

if NATIVE_SERVO_CONTROLLER:
    import servo
    import machine
    device = servo.Servos(machine.I2C(sda=machine.Pin("P5"),
                                      scl=machine.Pin("P4")),
                          address=0x40,
                          freq=50)

if NATIVE_MOTOR_CONTROLLER:
    from pyb import Pin, Timer

    # these are motor driver pins, which set the direction of each motor
    pinADir0 = pyb.Pin('P0', pyb.Pin.OUT_PP, pyb.Pin.PULL_NONE)
    pinADir1 = pyb.Pin('P1', pyb.Pin.OUT_PP, pyb.Pin.PULL_NONE)
    pinBDir0 = pyb.Pin('P2', pyb.Pin.OUT_PP, pyb.Pin.PULL_NONE)
    pinBDir1 = pyb.Pin('P3', pyb.Pin.OUT_PP, pyb.Pin.PULL_NONE)

    # Dir0/1 must be not equal to each other for forward or backwards
    # operation. If they are equal then that's a brake operation.
    # If they are not equal then the motor will spin one way other the
    # other depending on its hookup and the value of channel 0.
from machine import I2C, Pin
import servo

i2c = I2C(2)
ser = servo.Servos(i2c)
while True:

    ser.position(
        11, us=1500
    )  # 11 is your servo channel, us is servo position, usually the value is from 0.5ms to 2.5ms
    pyb.delay(1000)
    ser.position(11, us=2000)
    pyb.delay(1000)
Пример #5
0
from microbit import sleep, button_a
import radio
import PCA9685
import servo


def playnote(sc, smap, note, numticks, ticklength):
    sc.position(smap.index(note), 30)  # move servo enough to hit glass
    sleep(100)  # give it time to move that far
    sc.position(smap.index(note), 0)  # move it back
    sleep(100)
    sc.release(smap.index(note))
    sleep((ticklength * numticks) - 200)  # rest for the length of the note


radio.on()
sc = servo.Servos()
# http://www.musicnotes.com/SheetMusic/mtd.asp?ppn=MN0127456
swt = ('a4:2', 'b4:2', 'g4', 'a4:2', 'c5:2', 'd5:2', 'b4', 'c5:2', 'b4:2')
smap = ('g4', 'a4', 'b4', 'c5', 'd5')

while True:
    incoming = radio.receive()
    if incoming == 'dingdong' or button_a.was_pressed():
        for _ in range(5):
            for x in swt:
                y = x.split(':')
                playnote(sc, smap, y[0], len(y) > 1 and int(y[1]) or 1, 200)
Пример #6
0
# servo_max = 600  # Max pulse length out of 4096

# Set frequency to 60hz, good for servos.
# pwm.set_pwm_freq(60)

# print('Moving servo on channel 0, press Ctrl-C to quit...')

# # Move servo on channel O between extremes.
# pwm.set_pwm(3, 0, servo_min)
# sleep(1000)
# pwm.set_pwm(3, 0, servo_max)
# sleep(1000)

# 驱动舵机
# Use servo helper class to move channel 0 by degrees
s0 = servo.Servos(i2c)
s0.Servo360(2, 1, 90)
sleep(2000)
s0.Servo360(2, 2, 90)
sleep(2000)
s0.Servo360(2, 3, 90)
sleep(2000)
#s0.Servo270(1, 0)
#sleep(2000)
#s0.Servo270(1, 90)
#sleep(2000)
#s0.Servo270(1, 180)
#sleep(2000)
#s0.Servo270(1, 270)
#sleep(2000)
#s0.Servo270(1, 180)
Пример #7
0
import ps2x_controller
import time
import math
import bloc_calculator
import ujson
import os

if "config.json" in os.listdir():
    f = open("config.json", "r")
    config = ujson.loads(f.read())
    f.close()
else:
    print("no config file")

i2c = machine.I2C(sda=machine.Pin(21), scl=machine.Pin(22))
s1 = servo.Servos(i2c, address=0x40)
s2 = servo.Servos(i2c, address=0x41)
s = [s1, s2]

controller = ps2x_controller.Controller()


def calibrate():
    global config
    s = {"0x40": s1, "0x41": s2}
    servos = ["inner", "coxa", "outer"]
    offsets = {"inner": config, "coxa": 0, "outer": 0}
    sticks = {"inner": "PSS_LX", "coxa": "PSS_RX", "outer": "PSS_RY"}
    for leg in range(6):
        sc = s[config["servos"]["leg_address"][leg]]
        for servo in servos:
Пример #8
0
#   *
###############################################################################

from machine import Pin, I2C
import time

# Imports for the servo FeatherWing
import pca9685
import servo

# Construct an I2C bus
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)

# Define the servos instance
# In the case of the feather it will contain 8 possible servos
servos = servo.Servos(i2c)

# We'll just be controlling servo number 0 here
SERVO_NUMBER = 0

# Move the servo in position 80deg
# 80 deg was actually center on the servo I was testing on
# The default possible range is 0-180. However, note that most servos, even
# if advertised as having that range, do not. +/-60 deg around the center
# is much more reliable. +/-45deg around center is even better.
servos.position(SERVO_NUMBER, 80)
time.sleep(1)

# Now, move to 50deg
servos.position(SERVO_NUMBER, 50)
time.sleep(1)
Пример #9
0
import servo
from machine import I2C, Pin
import time

i2c = I2C(-1, scl=Pin(22), sda=Pin(21))

# Create a simple PCA9685 class instance.
servo = servo.Servos(i2c)

servo.position(0, degrees=100)