I am trying to set up a large stepper motor to use in my project. It's too large to run directly off of the pins of my Arduino, so I purchased this: http://www.omega.com/pptst/STR.html stepper motor driver, along with a power supply. It uses two digital inputs to determine the steps and direction to run the motor: Step+ and Dir+ (Step- and Dir-are connected to the Arduino's ground). Step+ inputs pulses from a source and translates them into step moves. I'm a little confused as to what Dir+ does, but I think it changes the motor direction whether the pin is HIGH or LOW.
My question is: will the stepper library directly work for this driver? If not, how do I send pulses to the driver?
Normally the motor is moved a single step when the driver receives a short pulse on the STEP pin (perhaps 100 microseconds) from the Arduino. The time between pulses will determine how many steps happen per second. Again, normally, the motor moves in one direction when DIR is high and in the other direction when it is low.
You may find the Pololu webpage for their A4988 stepper useful. (Google Pololu A4988) - from what you say the control of your driver is the same.
It's too large to run directly off of the pins of my Arduino - this is true of ALL stepper motors.
Robin2: It's too large to run directly off of the pins of my Arduino - this is true of ALL stepper motors.
What I meant by this, just to clarify, is that this isn't your average hobby stepper motor and can't be driven by a motor shield or equivalent. At 5.6 A/phase, this thing is a beast.
Those drivers are pretty nifty. I had no idea that they existed. However, the documentation for my driver is pretty light when it comes to communication. The attached page in my original post is about as good as it gets. The whole thing can be found on omega's product page if you're interested.
None of this really answers my question of how to code the pulses in the Arduino. Will the stepper library work, or do I need to hand code the output myself?
You said you have a suitable stepper driver board. That takes care of the 5.6A. From what you said earlier I said your driver board seems to be controlled exactly the same way as the Pololu A4988 board. I presume the stepper library works with the A4988 so it will probably work with your board. I believe the AccelStepper library is better, but I haven't used either as I have written my own code. Again I had assumed I had given enough guidance in my earlier post - create a short pulse (make an output pin high for, say 100 microseconds) and repeat as often as you need with a suitable time between pulses to get the speed you want. Set the DIR pin high or low to control direction.
I only made the comment about ALL steppers so you would know that what you are doing is perfectly normal.
Thanks for the support. I guess I'm just making this harder than it seems to be. I've never controlled anything like this before so I'm more than a little timid to get going. I think I've got the code figured out now, but just to double check I've pasted it below:
You could add a third parameter to pass the desired delay to the function.
However ... while your code should work well ...
The way you have written it means that the Arduino will be completely tied up while it is making the 1000 steps (or whatever). For example it won't be able to read a switch which might be telling it to stop.
If you look at the "blink without delay" sketch you will see a mechanism for keeping time without using the delay() function and you may need to replace the second delay with that concept. The very short delay for the pulse could probably be left as it is. The documentation for your stepper driver might tell you the minimum acceptable pulse length and I would keep it as short as possible.
The best way to deal with the second delay (i.e. using delayMicroseconds() or the "blink without delay" concept) will depend on the exact stuff you want to do with your sketch.
Before trying out more complex coding I suggest you use the simple code you already have to learn about controlling the motor at different speeds - the interface between theory and reality
As far as my project needs are, the Arduino only needs to do one task at a time. Step motor x steps, then do next task. The delayMicroseconds() function should be fine for this, in my opinion. The stop button can be programmed as an interrupt to stop the action at any time.
Now that I think about it, I'm going to need a variable to keep track of the position of the stepper (easy enough). If I understand delayMicroseconds() correctly, it will work inside an interrupt routine so I might be able to return the stepper to its original position when the stop button is pressed. This could be an important safety feature so please let me know if I'm wrong here.
I've thought about adding the third parameter and came up with a simple formula to convert rpm to the needed delay, but I'm not sure I need to add it in the code yet.
The only info the documentation has on pulse length is when they describe the digital input to be "very fast"
Edit: Upon re-reading, the docs say that the driver can handle 150kHz (or 2 MHz if I move an internal jumper). That means I can potentially set the pulse speed to 7 microseconds for 150kHz! Will I have noise problems with pulses that short?
Your description of using a stop button is too vague to form a basis for comments - especially if personal safety is involved. You should write out a risk analysis.
I'm not sure about delayMicroseconds() and interrupts. In any case keep the interrupt code very very short - perhaps it would just set a flag variable that is read by your the stepper() function before each step.
It may be a good idea to have a limit switch to detect the end of movement and form a basis for zeroing the step counter.
As far as the noise is concerned why not "suck it and see"?
The stop switch is kind of hard to explain. In my mind, I know it will work. I just ran a quick test, and delayMicroseconds() does work within the interrupt. I'm probably giving the interrupt more than its fair share of the burden, but from what I've seen, that hasn't been an issue.
Thanks for all of your help. I think I have enough information to get rolling on this stepper motor business. If I run into anymore hiccups, I'll be sure to drop by!