class Servo – 3-wire hobby servo driver — MicroPython latest documentation (original) (raw)

This is the documentation for the latest development branch of MicroPython and may refer to features that are not available in released versions.

If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

Servo objects control standard hobby servo motors with 3-wires (ground, power, signal). There are 4 positions on the pyboard where these motors can be plugged in: pins X1 through X4 are the signal pins, and next to them are 4 sets of power and ground pins.

Example usage:

import pyb

s1 = pyb.Servo(1) # create a servo object on position X1 s2 = pyb.Servo(2) # create a servo object on position X2

s1.angle(45) # move servo 1 to 45 degrees s2.angle(0) # move servo 2 to 0 degrees

move servo1 and servo2 synchronously, taking 1500ms

s1.angle(-60, 1500) s2.angle(30, 1500)

Note

The Servo objects use Timer(5) to produce the PWM output. You can use Timer(5) for Servo control, or your own purposes, but not both at the same time.

Constructors

class pyb.Servo(id)

Create a servo object. id is 1-4, and corresponds to pins X1 through X4.

Methods

Servo.angle([angle, _time=0_])

If no arguments are given, this function returns the current angle.

If arguments are given, this function sets the angle of the servo:

Servo.speed([speed, _time=0_])

If no arguments are given, this function returns the current speed.

If arguments are given, this function sets the speed of the servo:

Servo.pulse_width([_value_])

If no arguments are given, this function returns the current raw pulse-width value.

If an argument is given, this function sets the raw pulse-width value.

Servo.calibration([pulse_min, pulse_max, _pulse_centre_[, pulse_angle_90, _pulse_speed_100_]])

If no arguments are given, this function returns the current calibration data, as a 5-tuple.

If arguments are given, this function sets the timing calibration: