servo — Servo driver function

Servo class

class servo.Servo(pin, min_us=750, max_us=2250, actuation_range=180)

Construct Servo object, use SG90 servo by default. Different servos have different pulse width parameters and angle ranges, which can be set according to the servo model.


Servo control pin must be a pin that supports PWM (analog output). mPython Board supports PWM pins, for details, see Pin description of the mPython Board interface


  • Set actuation_range to apply the actual motion values observed for min_us and max_us .
  • To extend the pulse width above and below these limits. The servo may stop, buzz, and absorb additional current when stopped. Test carefully to find the safe minimum and maximum.
  • Because the servo PWM cycle is 20ms, the response time is 20ms. When programming, pay attention to the interval between writing the servo angle twice should be at least greater than 20ms。
  • pin - Servo PWM control signal pin
  • min_us - The minimum width of the pulse width of the servo PWM signal, in microseconds. Default min_us=750
  • max_us - The maximum pulse width of the servo PWM signal, in microseconds. Default max_us=2250
  • actuation_range - Maximum turning angle of servo

Send PWM signal with set pulse width。

  • width -Pulse width in microseconds.

Write servo angle

  • angle - servo angle.
from mpython import *
from servo import Servo                 #import servo module


while True:
        for i in range(0,180,1):
        for i in range(180,0,-1):