How to use nema 17 stepper motor as a optical encoder?

hello sir/madam can i use my nema 17 stepper motor as a rotary encoder(just like optical encoder do)??? if it is possible how can i make that?

the things i already have
2 a4988 stepper motor driver
1 arduino uno
1 cnc v3 shield
4 nema 17 stepper motor