Configure a pi Servo

Configure a pi servo to integrate a hobby servo controlled by general-purpose input/output (GPIO) pins on a Raspberry Pi board into your robot:

Navigate to the config tab of your robot’s page in the Viam app. Click on the Components subtab and navigate to the Create component menu. Enter a name for your servo, select the type servo, and select the pi model.

Click Create component:

An example configuration for a pi servo in the Viam app Config Builder.

Edit and fill in the attributes as applicable.

{
    "components": [
        {
            "name": "<your-servo-name>",
            "type": "servo",
            "model": "pi",
            "attributes": {
                "pin": "<your-pin-number>",
                "board": "<your-board-name>"
            }
        },
        ... // insert your board component config
    }
{
  "components": [
    {
        "name": "local",
        "type": "board",
        "model": "pi"
    }, 
    {
        "name": "my_servo",
        "type": "servo",
        "model": "pi",
        "attributes": {
            "pin": "16",
            "board": "local"
        }
    }
  ]
}

A servo JSON config with explanatory annotations for each attribute.

The following attributes are available for pi servos:

NameTypeInclusionDescription
pinstringRequiredThe pin number of the pin the servo’s control wire is wired to on the board.
boardstringRequiredname of the board the servo is wired to.
minfloatOptionalThe minimum angle in degrees that the servo can reach.
Default = 0.0
Range = [0.0, 180.0]
maxfloatOptionalThe maximum angle in degrees that the servo can reach.
Default = 180.0
Range = [0.0, 180.0]
starting_position_degsfloatOptionalStarting position of the servo in degrees.
Default = 0.0
Range = [0.0, 180.0]
hold_positionbooleanOptionalIf false, power down a servo if it has tried and failed to go to a position for a duration of 500 milliseconds.
Default = true
max_rotation_degintOptionalThe maximum angle the servo can rotate. Must be in between min and max.
Default = 180


Have questions, or want to meet other people working on robots? Join our Community Discord.