I am building a programmable stepper motor. It contains arduino mega 2560, lcd keypad shield, nema 14 stepper motor, a opto interrupter sensor and a stepper motor driver (polulu DRV8825). I am stuck at one point. I want to update the lcd screen everytime the motor takes 1 step. The number of steps, speed of motor and direction will be user input. Also, I want to set the speed of the stepper motor according to the input entered using the keypad shield. But I don't know how to make this thing work. Any idea what should be the logic? Please help me out with this issue I am having.
The two motors are completely different.
Your stepping motor can be advanced one step at a time. Lots are 1.8 degrees per step.
There are a lot of Arduino/stepping motor hits on the Internet.
Maybe look at YouTube for some stepping motor offerings.
The simple answer to the question in your title is to command the motor to move one step at a time and increment a variable once for every step. Then the code for your LCD can read the value in that variable and display it on the screen.
Writing to an LCD is time consuming so you probably won't want to update the display for every step unless the motor is moving very slowly. It may be sufficient to update the display once or twice per second.
Do not use the delay() function anywhere in your program.
Thank you for helping me out. Well its a project I am doing for my final semester. My professor asked me to display it on the lcd for every step the motor takes. I have no choice, but to do it. What if I display the revolution instead of displaying steps? Will it help solving the problem I am having?
This is the logic I have written for using the lcd keypad shield. I was trying to put the steps2 value in a new variable and then increment it but its simply showing me the value on the lcd. Its not updating. I am not having much idea about arduino commands. Is there a way I can use a counter or limit condition to count the steps?
Its working properly. But the only thing I am having trouble with, is to update the lcd screen everytime the motor takes the steps entered by the user. And secondly I want to run the motor according to the speed entered by the user. Not to run it at a constant speed.
With the code for the different activities in different functions it will be much easier to manage and to change one part without screwing up another.
If you want a responsive program you MUST get rid of all the delay()s and use millis() to manage timing without blocking. That is illustrated in the above link and in the demo Several Things at a Time