Ejemplo n.º 1
0
def servoConnect(pwmPin=D23.PWM):
    #wires => Brown:GND, Red:5V, Orange: pwmPin
    servoMotor = servo.Servo(pwmPin,
                             min_width=1000,
                             max_width=2000,
                             default_width=1000)
    servoMotor.attach()
    print("Servo motor attached.")
    return servoMotor
Ejemplo n.º 2
0
def close():
    print("Ok, closing, actual pos: ", MyServo.getCurrentDegree())
    MyServo.moveToDegree(0)


#Ubidots parameters
device_label = "esp32"
variable_label = "ServoMotor"
token = "BBFF-FZEcZCMX7zB8mUz6dJjJzQzmMv8w0H"

streams.serial()

#Servomotor Marrone -> GND Rosso -> 5V  Arancione --> D25
MyServo = servo.Servo(D25.PWM,
                      min_width=1000,
                      max_width=2000,
                      default_width=1000)
MyServo.attach()

wifi_driver.auto_init()

print("Establishing connection..")
try:
    wifi.link("Vodafone-26184725", wifi.WIFI_WPA, "kfmu9axt2m9udca")
    print("Connected!")
except Exception as e:
    print("Something went wrong.. ", e)
    while True:
        sleep(1000)

Ejemplo n.º 3
0

from servo import servo
# WARNING! for this example to work the community floyd.animator must be installed!
from community.floyd.animator import animator
import streams

s=streams.serial()

# creates a list of points to be reached by the servo motor using tuples (position, millisecond)
# The first tuple has to be set with time=0: (desired_pos,0). This is the value from which the animation will start
# In this case servo motor positions in degrees are scheduled
pointList= [(0,0),(180,10000),(90,3000),(0,5000),(180,5000)] 

print("scheduled positions at times (ms):",pointList)

# create a servo motor attaching it to the pin D11. Specification of the PWM feature using the Zerynth pin mapping signature is required. 
# min max defaults in this case are selected for working with Hitech servomotors
MyServo=servo.Servo(D11.PWM,500,2500)

# create an animator that runs at 10Hz passing data to  MyServo.moveToDegree
# don't set too high frequency, 10-30 Hz are fine. The Servo is controlled with a period of 20ms, frequancy higher than 45Hz will block the motor! 
anim=animator.Animator(25,MyServo.moveToDegree)

# start the animations using the defined point list
anim.animate(pointList)
    
while True:
#just print the animator position and interpolated value
    print(anim.currentPosition())
    sleep(500)
Ejemplo n.º 4
0
################################################################################
# Servo Motor Basics
#
# Created by Zerynth Team 2015 CC
# Authors: D. Mazzei, G. Baldi,
###############################################################################

from servo import servo
import streams

s = streams.serial()

# create a servo motor attaching it to the pin D11. D11.PWM notation must be used.
# min max are left to defaults 500-2500. they need to be properly set to the servo specifications
# control signal period is left to default 20ms
MyServo = servo.Servo(D11.PWM)

while True:
    print("Servo ON")
    MyServo.attach()
    sleep(3000)

    print("Servo controlled in pulse width")
    for i in range(500, 2500, 10):
        MyServo.moveToPulseWidth(i)
        print(MyServo.getCurrentPulseWidth())
        # Very important: servo default control signal period is 20ms, don't update the controlling PWM faster than that!
        sleep(100)

    print("Servo controlled in degrees")
    for i in range(0, 180, 1):