Quadrature encoders are incremental encoders that you can use to measure the speed and direction of a rotating shaft. They convert the angular rotation of the shaft to digital pulses that tell you which direction the shaft moves. By measuring the time difference between the pulses, you can derive the speed. You can use quadrature encoders in bidirectional position sensing and length measuring applications. You can decode quadrature signals to use them as a sensory input to a system to determine the speed, acceleration, and position of the rotary devices. The three types of decoding — X1, X2, and X4 — provide 1, 2, or 4 pulses, respectively, at each rotational cycle. X4 decoding is only supported as it provides the highest accuracy and angular resolution.
Before you use quadrature encoder functions, create an Arduino object using
arduino. For more
information, see Connect to Arduino Hardware.
|Connection to quadrature encoder on Arduino or ESP32 hardware|
|Set count value to zero or user-specified value|
|Read current count value from encoder with X4 decoding|
|Read current rotational speed|
- Control Rotary Encoder Knob
This example shows how to use the MATLAB® Support Package for Arduino® Hardware to control a 12-step rotary encoder with a built-in push button.
- Steer Two-Wheel Robot
This example shows how to use the MATLAB® Support Package for Arduino® Hardware to steer a two-wheel Arduino-based robot with closed-loop control.