Configure a pi Servo
Note
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 navigate to the Create component menu.
Enter a name for your servo, select the type servo
, and select the pi
model.
Click Create component:
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"
}
}
]
}
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 | The minimum angle in degrees that the servo can reach. Default = 0.0 Range = [ 0.0 , 180.0 ] |
max | float | Optional | The maximum angle in degrees that the servo can reach. 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 the servo can rotate. Must be in between min and max .Default = 180 |
Tip
Refer to your servo’s data sheet for pulse-width modulation (PWM), rotation, and wiring specifications.
Have questions, or want to meet other people working on robots? Join our Community Discord.
Was this page helpful?
Glad to hear it! If there is anything we could be doing better, please create an issue.
We're sorry about that. If you'd like to talk to us for help, please join the Community Discord. To ensure we know what's wrong with this page, you can also open an issue.