The Grove servomotor can be used to control rotary position within an 180-degree range.

Servo

Hardware

Even though your servo may have a label that says "analog servo", it must be plugged into a digital port on your Grove shield:

Digital ports on the Grove shield v2.0

Note that, due to the way the servomotor is wired, the digital pin number actually may not match the port number! Inspect the cable closely to be sure of which pin the servomotor’s wiring is connected to. For example, a servomotor plugged into port D7 may actually be connected to pin D8 — always inspect the physical connection to be sure.

Software

Functions that interact with the servomotor are prefixed with servo.

To control the servomotor, pass an angle (between 0 and 180 degrees) to the servo_set_angle function:

def servo_set_angle(pin, angle):
    """Move servo motor to given angle (in degrees)

    Parameters:
      pin (int):       Digital connection port
      angle (int):      Final servo position (range: [0, 180])
    """

To check the current position of the servo motor, call the servo_get_angle function:

def servo_set_angle(pin):
    """Check position of servo motor

    Parameters:
      pin (int):       Digital connection port

    Returns:         Servo motor position (0–180).
    """