Configure a single encoder

A single encoder sends a signal from the rotating encoder over a single wire to one pin on the board. Software calculates the relative position that the motor has rotated.

Configuring a single encoder requires configuring one pin (i) on the board to which the encoder is wired. The direction of spin is dictated by the motor that has this encoder’s name in its encoder attribute field.

On the COMPONENTS subtab, navigate to the Create Component menu. Enter a name for your encoder, select the type encoder, and select the single model.

Creation of a single encoder in the Viam app config builder.

Fill in the attributes for your encoder:

Configuration of a single encoder in the Viam app config builder.
{
    "name": "<encoder_name>",
    "type": "encoder",
    "model" : "single",
    "attributes": {
      "board": "<board_name>",
      "pins": {
        "i": <string>
      }
    }
}

The following attributes are available for single encoders:

NameInclusionDescription
boardRequiredThe name of the board to which the encoder is wired.
pinsRequiredA struct holding the name of the pin wired to the encoder:
  • i: Pin number of the pin to which the encoder is wired. Use pin number, not GPIO number.

Viam also supports a model of encoder called "incremental" which uses two pins.