Configure a pi Servo
Info
Unlike other servo models, pi
servos are implemented as part of the pi
board component.
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 click Create component.
Select the servo
type, then select the pi
model.
Enter a name for your servo and click Create.

Copy and paste the following attribute template into your servo’s Attributes box. Then remove and fill in the attributes as applicable to your servo, according to the table below.
{
"pin": "<your-pin-number>",
"board": "<your-board-name>",
"min": <float>,
"max": <float>,
"starting_position_deg": <float>,
"hold_position": <int>,
"max_rotation_deg": <int>
}
{
"pin": "16",
"board": "local"
}
{
"components": [
{
"name": "<your-servo-name>",
"model": "pi",
"type": "servo",
"namespace": "rdk",
"attributes": {
"pin": "<your-pin-number>",
"board": "<your-board-name>",
"min": <float>,
"max": <float>,
"starting_position_deg": <float>,
"hold_position": <int>,
"max_rotation_deg": <int>
}
}
}
{
"components": [
{
"name": "local",
"model": "pi",
"type": "board",
"namespace": "rdk"
},
{
"name": "my_servo",
"model": "pi",
"type": "servo",
"namespace": "rdk",
"attributes": {
"pin": "16",
"board": "local"
}
}
]
}
The following attributes are available for pi
servos:
Name | Type | Inclusion | Description |
---|---|---|---|
pin | string | Required | The pin number of the pin the servo’s control wire is wired to on the board. |
board | string | Required | name of the board the servo is wired to. |
min | float | Optional | Sets a software limit on the minimum angle in degrees your servo can rotate to. Default = 0.0 Range = [ 0.0 , 180.0 ] |
max | float | Optional | Sets a software limit on the maximum angle in degrees your servo can rotate to. Default = 180.0 Range = [ 0.0 , 180.0 ] |
starting_position_degs | float | Optional | Starting position of the servo in degrees. Default = 0.0 Range = [ 0.0 , 180.0 ] |
hold_position | boolean | Optional | If 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_deg | int | Optional | The maximum angle that you know your servo can possibly rotate to, according to its hardware. Refer to your servo’s data sheet for clarification. Must be greater than or equal to the value you set for max .Default = 180 |
Tip
Refer to your servo’s data sheet for pulse-width modulation (PWM), rotation, and wiring specifications.
Test the servo
After you establish the connection to your servo motor, navigate to the Control tab and select the dropdown panel dedicated to the motor. Use the buttons to move the servo motor to the desired angle.

Have questions, or want to meet other people working on robots? Join our Community Discord.
If you notice any issues with the documentation, feel free to file an issue or edit this file.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!