help encoder


Help, pzhl))
What I have:
2 axes, each on such a set.

  1. Slotted disc (25 pcs per revolution, diameter 25 mm)
  2. Dual optical encoder. (i.e. 2 pins enter Arduin)
  3. Stepper motor (driver L298N, but I plan to change to DRV8825)
  4. Physical limiter of the angle of rotation in the video of a metal stopper, which does not allow to turn further.

When turned on, it is necessary that the device turns each axis until it stops counterclockwise.
In programming it is not strong, but I intuitively understand how it may look.

For example,
The engine is spinning.
If the delay between ticks (transitions from 0 to 1 or from 1 to 0) is more than a few milliseconds, then he considers this a zero point and sends 20 steps in the opposite direction.

Or so.
If the rotation speed of the encoder is 0, then assume that the axis meets the stop and this is the starting point, and then add 20 steps to the opposite direction.

I do not see a question here. If you want code written for you, go to "Gigs and Collaborations" and bring your wallet. One of the great things about an Arduino is that you get to do things for yourself.