Configure an Incremental Encoder
Use the incremental
encoder model to configure a quadrature encoder.
Configuring an incremental
encoder requires specifying the pin numbers of the two pins on the board to which the encoder is wired.
These two pins provide the phase outputs used to measure the speed and direction of rotation in relation to a given reference point.
Navigate to the Config tab of your machine’s page in the Viam app.
Click on the Components subtab and click Create component.
Select the encoder
type, then select the incremental
model.
Enter a name for your encoder and click Create.
Fill in and edit the attributes as applicable.
{
"name": "<your-encoder-name>",
"model": "incremental",
"type": "encoder",
"namespace": "rdk",
"attributes": {
"board": "<your-board-name>",
"pins": {
"a": "<your-first-pin-number>",
"b": "<your-second-pin-number>"
}
}
}
{
"components": [
{
"name": "local",
"model": "pi",
"type": "board",
"namespace": "rdk",
"attributes": {}
},
{
"name": "myEncoder",
"model": "incremental",
"type": "encoder",
"namespace": "rdk",
"attributes": {
"board": "local",
"pins": {
"a": "13",
"b": "11"
}
}
}
]
}
The following attributes are available for incremental
encoders:
Name | Type | Inclusion | Description |
---|---|---|---|
board | string | Required | The name of the board to which the encoder is wired. |
pins | object | Required | A struct holding the names of the pins wired to the encoder:
If the encoded motor does not operate as expected, the encoder pins might be configured in reverse, switch the |
Viam also supports a model of encoder called "single"
which requires only one pin (i
).
Test the encoder
Once your encoder is configured and connected, go to the Control tab and click on the encoder’s dropdown panel. The ticks count is displayed. Try moving the encoder (for example, by turning a motor it is attached to) and check whether the count increases as expected.
If the encoder does not appear on the Control tab, or if you notice unexpected behavior, check your machine’s Logs tab for errors, and review the configuration.
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!