servo — Servo driver function
Servo Class
- class servo.Servo(pin, min_us=750, max_us=2250, actuation_range=180)
Construct a Servo object. It uses the SG90 servo by default. Different servos have different pulse width parameters and angle ranges; set them yourself according to the servo model.
Hint
The Servo control pin must be a pin that supports PWM (analog output). For details on the pins of the mPython Board that support PWM, see mPython Board interface pin description.
Attention
You can set
actuation_rangeto correspond to the observed actual range of motion for the givenmin_usandmax_us.You can also extend the pulse width above and below these limits. The servo may stall, buzz, and draw extra current when stalled. Test carefully to find the safe minimum and maximum values.
Since the servo PWM period is 20ms, the response time is 20ms. When programming, note that the interval between two writes of the servo angle should be at least greater than 20ms.
pin- The servo PWM control signal pinmin_us- The minimum pulse width of the servo PWM signal, in microseconds. Default min_us=750max_us- The maximum pulse width of the servo PWM signal, in microseconds. Default max_us=2250actuation_range- The maximum rotation angle of the servo
- Servo.write_us(width)
Send a PWM signal to set the pulse width.
width- The pulse width, in microseconds.
- Servo.write_angle(angle)
Write the servo angle.
angle- The servo angle.
from mpython import *
from servo import Servo # Import the servo module
s=Servo(0)
while True:
for i in range(0,180,1):
s.write_angle(i)
sleep_ms(50)
for i in range(180,0,-1):
s.write_angle(i)
sleep_ms(50)