Optical Shaft Encoders + Arduino Programming

I’m using this optical shaft encoder on a project https://www.vexrobotics.com/276-2156.html#jqql20i. I’m struggling to find out whether it’s an X1, X2, or X4 encoder. Here are the differences for reference: https://www.motioncontroltips.com/faq-what-do-x1-x2-and-x4-position-encoding-mean-for-incremental-encoders/. Vex RobotC seems to do that programming set up for you, however, I need to know in order to program the device using Arduino.

From that document those are just counting schemes using the exact same encoder, all of them would work with the Vex encoder. X4 would have the highest resolution and it’s what is normally used in my experience.

The Vex encoders really are standard quadrature encoders and any arduino encoder library should work.

5 Likes

Just note for anyone wondering,
A standard quadrature encoder has 4 states possible from its 2 digital outputs.

Low, high
Low, low
High, low
High, high

Those 4 states are a circle and loop back around. Go up the list and you count it as clockwise motion, go down the list and it’s counterclockwise motion. The x1 x2 and X4 schemes were just saying do you count every step along the list as 1 encoder tick(X4), count everytime you move twice in the same direction (X2) or only every time you loop the entire list (x1).

Higher resolution might be a bit noisier but usually still worth it.

6 Likes

I can confirm that these are quadrature encoders. I have used the shaft encoders successfully in past projects. My hint is if you using an 8-bit arduino(uno,mega,etc), you will need to use interrupt pins to get precise measurements. The standard pins WILL miss steps.

2 Likes