Stepper Motors with Activity Board and H-Bridge
plau45
Posts: 109
Hello, I'm not sure where this discussion should go so I defaulted to the general chat. Anyway. I am trying to drive a stepper motor via an Activity Board and a H-Bridge using C as my language for programming. My question is where to find any libraries to actually simplify running this stepper or just simply how to do it. I'm using a Bipolar Stepper and have no experience working with steppers. Any help is appreciated thanks. P.S. I'm not entirely sure on how the communication even works between the board and the stepper in terms of signals and what not. I'm very new to steppers as a whole and can't really find much major help on the software side of it. Any resources on steppers as a whole would help too.
Comments
I would say that is an under statement
plau45
Since this is your first experience with steppers, please take Hal's advice, and purchase a premade driver from Pololu, because it will greatly simplify a variety of issues.
Most bipolar stepper drivers have three main input pins, which are: Step, Direction, and Enable. However, most bipolar stepper drivers can have the Enable input bypassed, to help reduce IO requirements.
The Direction pin can also be bypassed, if you only need your stepper motor to rotate in one particular direction.
The main input pin for a stepper driver is the Step input pin. This Step pin requires a high signal for the stepper motor to make a step and this high signal will have a specified duration, being dependent upon the IC chip being used by the driver.
Simplified pseudo code for 10 steps
LOOP 10
WAIT
LOW
WAIT
I agree - it doesn't get much easier than the Pololu drivers - https://www.pololu.com/category/156/a4988-stepper-motor-driver-carriers
Stepper Motor:
http://www.omc-stepperonline.com/3d-printer-nema-17-stepper-motor-2a-45ncm64ozin-17hs162004s-p-16.html
H-Bridge:
https://www.amazon.com/gp/product/B00CAG6GX2/ref=oh_aui_search_detailpage?ie=UTF8&psc=1
And then an olderish Activity Board from parallax. I would absolutely love to be able to use the hardware I have right now simply because time is a factor in figuring this out.
I do actually need the stepper motors to rotate in 2 directions, +x and -x. I am going to use the same technique for the other two axis. This is not for any CNC or Printer of any sort so it is going to be controlled manually via directional buttons or pots.
Those steppers actually require a bit of current for a NEMA 17, although you do not have to provide it with the full 2A per phase.
What h-bridge do you intend to use?
If you are bound and determined to use h-bridges, than I would also suggest using a step translator in combination with the h-bridge.
However, once again, I strongly urge you to reconsider a premade drive. I learned that lesson the hard way, because I was stubborn and trying to conserve money.
Choice 1 = headache
Choice 2 = plug and play
Take a look at these high current drivers: https://pololu.com/category/154/drv8825-stepper-motor-driver-carriers-high-current
These drivers will allow you 1.5A per phase, without a heat sink or forced air flow, however they are rated for 2.2A with additional cooling. These drivers are about the best bang for your buck, to get the most out of your 2.0A per phase steppers. With additional cooling, you can run your steppers at full current, otherwise you will have to adjust the pot.
That h-bridge (L298) is quite capable of driving a stepper motor, although that board most likely will not do it, but to make life easier, the L298 should be paired with a L297 step translator (st.com/en/motor-drivers/l297.html).
I have a couple of the same driver that I recommended, so if you get these drivers, I can help you with the code to make your steppers sing.
You need to be aware of the drive waveform and the output patterns you need to form each step of the waveform with your H-bridge controller. I generally load the waveform steps into an array, and to step the motor I either increment or decrement the pointer and output the new pattern to the output port. You don't have to be too concerned with the pointer's actual value as long as you wrap it around forward and backward, which is really easy if you're using a four or eight step waveform because you can just bitwise AND the pointer with the appropriate mask after inc/dec.
I am simply wanting to run the stepper like a motor in a linear actuator and control it via a variable pot so I can control the position manually. It's not meant to automated so I don't know if I really need to keep track of the steps it takes if I'm just wanting it to rotate until I tell it not to. I don't know if this makes any sense but hopefully it does. I will possibly upload a picture of what I'm wanting to do if I get the thing built before I figure out the programming but it is just a 3 axis mount for a laser vibrometer that would be moved using these steppers. I don't need to worry about the vibration of the motors because it will be stationary with the motors only holding the vibrometer in place when I'm taking measurements.
Is the idea for your design set in stone?
Controlling the position of linear actuator with a pot, sounds a little complicated. It's more like shooting from the hip, so to speak. If you are not attempting any kind of automation, then may I suggest the use of pushbuttons, instead of a pot. With pushbuttons, you could have two pushbuttons for each stepper, with one button rotating the motor clockwise and the other, rotating it counter-clockwise. Going back to pseudo code, it would look something like this:
Additionally, if you have access to keep it tied to a computer, you could issue positions serially. X100 Y200 Z300
I think it is best to handle all of this in baby steps, otherwise you may become overwhelmed with information.
Stepper motors rotate in degrees, and the number of degrees per step, is referred to as the step angle. The stepper motor that you linked to above, has a step angle of 1.8 degrees. That means, with the stepper driver set to "full step mode", the motor will rotate 1.8 degrees, with every high pulse that it receives. The direction of motor rotation, of this 1.8 degree angle movement, will be determined by whether the direction pin is held high or low. With a 1.8 degree step angle, you must send 200 high pulses to the stepper driver, to get one full rotation of the motor in "full step mode".
If you are using screw driven linear actuators, as compared to belt driven actuators, the math is actually quite simple. Let's use 1/4-20 thread as an example. 1/4-20 thread has 20 threads per inch, so one full rotation of the thread will move you 1/20th of an inch and with 20 rotations, you will have moved a complete inch. Now to equate this to high pulses sent to the stepper driver, in "full step mode", you would simply send 200 pulses to move 1/20th of an inch or 20 * 200 pulses to move a complete inch.
There are a several ways to wire it up, but start with simple. Pololu provides 2 wiring diagrams for this driver:
Minimal Wiring: https://a.pololu-files.com/picture/0J4232.1200.png?f2f6269e0a80c41f0a5147915106aa55
Alternative Minimal Wiring: https://a.pololu-files.com/picture/0J4233.1200.png?665d623ba84232de64511d8aa6644836
loop (however many times I want)
high(pin number)
end loop
Or would I need a combination of pins being set to high or low like the pseudo code you originally gave me further up in the comments? I'm just wondering if this would be the correct idea or if I'm way off.
Your math is way off.
200 pulses = 1/20th of an inch (1 complete rotation of motor shaft)
4000 pulses = 1 inch (20 complete rotations of motor shaft)
40000 pulses = 10 inches (200 complete rotations of motor shaft)
Yes, they need to go high and low for movement.
Are you building first or playing with motors first?
Wow, I feel stupid now haha. And I am currently building and playing with motors. I know the design I want and have been prototyping with ways to build it for a few weeks now and I also know where I want the motors to be placed and what kind of placement I would like for the interface and what not but I am not putting them in place until I get the motor situation figured out thus not to create anymore confusion. So as a short answer I'm doing both separately.
Frank,
That sounds like a good idea and all but I figured I could use a method including two micro switches that are activated when the apparatus being moved hits one of the upper or lower limits of the bed kind of how some 3D-Printers work with their limits for the movement of the nozzle and heated bed or however they may be set up. I figure either way works and they are pretty similar so I don't think either way will be an issue.
I am currently working on C code for synchronizing four axes of motion, utilizing stepper motors, so I cannot set aside too much time for specialized code pertaining to your project, but I am still willing to help.
At this time, let's concentrate on getting one motor to run.
First thing I need to know is the required high pulse width.
Secondly, I need the IO pin number that you will be using for direction rotation.
Thirdly, I need the IO pin number that you will be using for providing the step pulses.
Honestly your helping a bunch just by correcting my mistakes and showing me the ropes so to speak. And what do you mean by the required high pulse width? And also I only need help with one motor. The rest will come naturally after I know how to use one. The pin for the step is 15 and the pin for the direction is 14. You honestly just need to show me the code for the steps and directions. I can do the buttons and interface and the other logistics involved. A simple example really is all I think I would need to get my stepper going on this hardware. Either way thank you guys SO MUCH for taking time out of your own projects and helping me out on this one! I really do appreciate it!
Okay, I have slapped together some code for you, but it is untested, however I think it should work with some possible minor modifications. You will most definitely have to adjust the overcome_inertia variable, and the high_pulse_width variable may need adjustment, depending upon the DRV8825 specifications. The high_pulse_width variable cannot be adjusted lower, but only higher.
Additionally, this driver was written for a single speed operation. Once the moment of inertia has been overcome, speed can be increased. This increase in speed is called ramping, and it is achieved by altering the overcome_inertia variable during the looping process, until the maximum or desired speed is obtained.
As mentioned, it is untested, but if it doesn't work, it is very close to what you need. You can also use the Propeller counters to drive stepper motors, which will result in a much higher running speed, because they don't require 381 cycles for the waitcnt to register. I learned that today by the way
"The timing requirements for minimum pulse durations on the STEP pin are different for the two drivers. With the DRV8825, the high and low STEP pulses must each be at least 1.9 us; they can be as short as 1 us when using the A4988."
Is this what you meant by High Pulse Width? I'm still a bit hazy on what you mean by that. I looked through the specs for it and couldn't really find anything similar except for this unless I just missed it.
Here is a link to the specs of the board: https://www.pololu.com/product/2133