Configure a Single Encoder (Micro-RDK)

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.

{
  "name": "<your-encoder-name>",
  "model": "single",
  "type": "encoder",
  "namespace": "rdk",
  "attributes": {
    "pin": <int>,
    "dir_flip": <boolean>
  }
}
{
  "name": "<your-encoder-name>",
  "model": "single",
  "type": "encoder",
  "namespace": "rdk",
  "attributes": {
    "pin": 22,
    "dir_flip": false
  }
}

The following attributes are available for single encoders:

NameTypeRequired?Description
pinobjectRequiredGPIO number of the pin to which the encoder is wired.
dir_flipbooleanRequiredIf the encoder’s count should increment or decrement in its initial state before a SetPower() call is made to an encoded motor. true implies decrement.

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.

Encoder control panel.

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.