Configure a single encoder
A single
encoder sends a signal from the rotating encoder over a single wire to one pin on the board.
The direction of spin is dictated by the motor that has this encoder’s name in its encoder
attribute field.
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 encoder
type, then select the single
model.
Enter a name for your encoder and click Create.
Fill in and edit the attributes as applicable.
{
"name": "<your-encoder-name>",
"type": "encoder",
"model": "single",
"attributes": {
"board": "<your-board-name>",
"pins": {
"i": "<your-pin-number-on-board>"
}
}
}
The following attributes are available for single
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 name of the pin wired to the encoder:
|
Viam also supports a model of encoder called "incremental"
which uses two pins.
Test the encoder
Once your encoder is configured and connected, go to the Control tab and click on the encoder’s drop-down 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 robot’s Logs tab for errors, and review the configuration.
Have questions, or want to meet other people working on robots? Join our Community Discord.
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!