Configure an incremental encoder
Use the incremental
encoder model to configure a quadrature encoder.
Configuring an incremental
encoder requires configuring 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.
On the COMPONENTS subtab, navigate to the Create Component menu.
Enter a name for your encoder, select the type encoder
, and select the incremental
model.

Fill in the attributes for your encoder:

{
"name": "<encoder_name>",
"type": "encoder",
"model" : "incremental",
"attributes": {
"board": "<board_name>",
"pins": {
"a": <string>,
"b": <string>
}
}
}
The following attributes are available for incremental
encoders:
Name | Inclusion | Description |
---|---|---|
board | Required | The name of the board to which the encoder is wired. |
pins | Required | A struct holding the names of the pins wired to the encoder:
|
Viam also supports a model of encoder called "single"
which requires only one pin (i
).
Example Config
The following example shows the configuration of a board and an encoder:
{
"components": [
{
"name": "local",
"type": "board",
"model": "pi",
"attributes": {}
},
{
"name": "myEncoder",
"type": "encoder",
"model": "incremental",
"attributes": {
"board": "local",
"pins": {
"a": "13",
"b": "11"
}
}
}
]
}