Have a look here:
A simple code to control a stepper. This little piece of code is quite old, change it according to your needs.