Controlling multiple steppers - How Best?

I have a variety of Arduino computers and 4 L298N driver boards and 4 small four phase unipolar motor 24 V/75 ohms = 0.3 A.

I have scoured the forums and, although there is information for 1 or 2 steppers, I could find nothing on controlling 4 steppers.

If I simply copy and modify the 2 stepper sketch, I can't determine how to organize it so that all steppers can be operated at once, rather than first one, then the next, etc. Is there a shield or something that takes care of that or something I have not yet found.

Can someone give me some guidance in this matter?

John

This project controls three motors at the same time:- http://www.thebox.myzen.co.uk/Hardware/CNC_Conversion.html

It may depend on whether the motors need to maintain a strict relationship with each other. For example do you need to ensure motor A take 87 steps, B 63 steps, C 123 steps and D 17 steps all in exactly the same time.

I think I know how to do that with a stepper driver board that takes step and direction signals but the code may be a little more complicated with your L298 drivers.

...R

OldSalt1945: I have a variety of Arduino computers and 4 L298N driver boards and 4 small four phase unipolar motor 24 V/75 ohms = 0.3 A.

Those unipolar motors can be controlled with half an ULN2803... However you haven't said how many wires (6 or 8 I guess as you mention the H-bridge chip).

For driving several unipolars with ULN2803's you can connect 74HC595 shift registers to drive the inputs of the ULN2803's, giving 3 pins for as many motors as you want...

This is for experimentation to learn how to do a CNC machine. At a later date, I will go for NEMA 17 or 23 steppers. In the meanwhile, what I have is free. It won't do much of anything useful, but like I said free while I am learning.

The motors I have have 5 wires. I want to be able to operate all of the motors simultaneously so that I can cut diagonal lines along the x-axis and y-axis while varying the z-axis. I will use an Arduino Mega 2560, so I/O pins shouldn't be a problem. It has lots. I am lightly familiar with State Machine concepts. I have written several sketches and modified several example sketches. I am very good at "copy, paste, & modify", except when I am not. :P

I have been unsuccessful at finding a sketch that operates all axis simultaneous. Or, I am, but I don't recognize it. Most of what I've found are littered with "Delay" statements. I know that's not good in a State Machine environment.

John

even the stepper.h in the standard lib can do this, if you want to write yourself, you can put a byte to a port, so it will move up to 8 steppers in one command the drivers you have can be used just leave the 5th wire unconnected. .

shooter:
the drivers you have can be used just leave the 5th wire unconnected.

I thought the 5th (common) wire went to ground.

Photo attached.

John

I decided to do a little bit of learning earlier today and I spent some time reading the documentation for the accelStepper library. I came across this interesting statement

AccvelStepper does not guarantee any synchronisation between individual steppers.

here.

Getting two steppers to cause a tooltip to follow a diagonal path requires (say) one of them to do 89 steps in exactly the same time as the other does 53 steps. I believe (based on some simple testing a few months ago) that this can be achieved with a simple FOR loop that iterates 4717 times (89 * 53) and every 53rd iteration it steps one motor one step and every 89th iteration it steps the other one.

The total time for the 4717 iterations must take account of how fast the fastest motor is to move. In this case it may be OK to use delay() if the Arduino is doing nothing else. However if, perhaps, you want the Arduino to get more stuff from the PC (for the next move) while the stepping is going on delay() wouldn't be appropriate. A very short delay for the step pulse (a few microseconds, perhaps) wouldn't matter. I am writing this based on using Pololu A4988 stepper drivers. There may be other timing issues with the L298 boards as the Arduino has to do more of the work. But in the end it could do it, perhaps a little more slowly.

...R

OldSalt1945:
This is for experimentation to learn how to do a CNC machine. At a later date, I will go for NEMA 17 or 23 steppers. In the meanwhile, what I have is free. It won’t do much of anything useful, but like I said free while I am learning.

The motors I have have 5 wires.
I want to be able to operate all of the motors simultaneously so that I can cut diagonal lines along the x-axis and y-axis while varying the z-axis.
I will use an Arduino Mega 2560, so I/O pins shouldn’t be a problem. It has lots.
I am lightly familiar with State Machine concepts.
I have written several sketches and modified several example sketches. I am very good at “copy, paste, & modify”, except when I am not. :stuck_out_tongue:

I have been unsuccessful at finding a sketch that operates all axis simultaneous. Or, I am, but I don’t recognize it. Most of what I’ve found are littered with “Delay” statements. I know that’s not good in a State Machine environment.

John

5 wire means unipolar only really. Normally you’d use ULN2803 or similar to drive
widings to ground and have the common wire connected to the motor supply.

For multi-axis control there are projects like GRBL, although these usually only
support step+direction bipolar drivers.

If your motors are quite old they won’t have NdFeB magnets in them and probably
have quite modest torque specs, note.

MarkT: 5 wire means unipolar only really. Normally you'd use ULN2803 or similar to drive widings to ground and have the common wire connected to the motor supply.

For multi-axis control there are projects like GRBL, although these usually only support step+direction bipolar drivers.

If your motors are quite old they won't have NdFeB magnets in them and probably have quite modest torque specs, note.

Modest, hell, they are positively anemic. 7 in/oz 24v. Better than nothing, but not by a helluva lot.

I have some ULN2003 driver boards coming over on a slow boat from China. Don't know how they compare to ULN2803.

Right now I'm just playing around. When I get serious, I'll get some serious steppers.

John

If you just want some working software, get and read GRBL.

If you want to learn how to make your steppers draw clean lines through space, the best way is to learn about Bresenham's Algorithm and work from there. It's a neat way of drawing a straight line when you have discrete output steps, eg pixels or CNC steps. Think of your line as a 3D function of a parameter, t. Compute the t-values where any of x, y or z changes, and do your changes at those times. Precompute the bit patterns in advance for each step event and send them with a single port write so that you don't get jitter.

For best performance with lines of arbitrary slope, you will want to run a very high-frequency timer and send step events at carefully scheduled times in order to maintain velocity as close to constant as possible. Have a look into the 16-bit timer and how you can use the output-compare functionality to toggle a pin with the timer hardware at a carefully scheduled time.

OldSalt1945: Modest, hell, they'er positively anemic. 7 in/oz 24v. Better than nothing, but not by a helluva lot.

in/oz is a new one on me, most people get it wrong as oz/in or ft/lb or N/m

Torque is force x distance. SI units are more convenient for calculations since the only arbitrary constant you need to remember is 2 x pi.

Arguably torque is better described as energy / angle (ie joules/radian) since this encapsulates the idea of rotation. Anywya your motor is 50mN-m, which is quite small, but perfectly plausible for a motor with ferrite magnets.

Some old stepper motors cannot be disassembled without destroying their performance because the permanent magnet material used doesn't have enough remanence to survive opening the magnetic circuit! NdFeB magnets and SmCo magnets have very high remanence-coercivity products and basically cannot be demagnetised in normal use without cooking them.

polyglot: the best way is to learn about Bresenham's Algorithm and work from there. It's a neat way of drawing a straight line when you have discrete output steps, eg pixels or CNC steps.

Just out of curiosity on my part, is it different from the mechanism I suggested in Reply #7?

...R

MarkT: On such things as in/oz vs. oz/in, my memory sometimes trips me up. On the other hand, doesn’t it strike you as odd that the convention is ft-lbs and oz-in? Torque should be represented with a dash, not a slash. A slash suggests “per”, but it ain’t ounces per inch, or inches per ounce, for that matter. My bad.

I never considered taking the motors apart. Don’t have any desire to disassemble my watch, either. (I did that once when I was 10 or 11. The watch kept stopping. I thought it had dirt in it and was determined to clean it out. It didn’t work out as well as I thought it might).

polyglot:

If you just want some working software, get and read GRBL

Does GRBL take care of all the calculations needed to draw straight lines?

John

Robin2: Just out of curiosity on my part, is it different from the mechanism I suggested in Reply #7? ...R

plotLine(x0,y0, x1,y1)
  dx=x1-x0
  dy=y1-y0

  D = 2*dy - dx
  plot(x0,y0)
  y=y0

  for x from x0+1 to x1
    if D > 0
      y = y+1
      plot(x,y)
      D = D + (2*dy-2*dx)
    else
      plot(x,y)
      D = D + (2*dy)

Thanks John, but I'm afraid I don't see the connection?

Where does that function come in?

...R

Robin2:

polyglot: the best way is to learn about Bresenham's Algorithm and work from there. It's a neat way of drawing a straight line when you have discrete output steps, eg pixels or CNC steps.

Just out of curiosity on my part, is it different from the mechanism I suggested in Reply #7?

...R

If you're willing to have a loop that is as long as the lowest common multiple of the line dx and dy values, it's functionally the same. But consider the case where you want to draw a line that is of interesting (ratio of two relatively prime numbers) and length 100,000: the loop length in your algorithm will be 10 billion and the tool will move extremely slowly.

Bresenham explicitly tracks the remainder in a variable instead of iterating the remainder so it is far more efficient in the general case. Classic Bresenham (for graphics) tracks the slope of your line in X/Y; for CNC you run 3 (or more) parallel Bresenham instances that track the slope of X/t, Y/t, Z/t.

GRBL takes G-code, ie instructions like "move to X,Y,Z at speed S", plus curves and all that good stuff. So yes, drawing lines is about the simplest thing it does. It will even handle acceleration & deceleration in a line!

Thanks @polyglot - interesting food for thought. That's exactly the sort of pointer I was looking for.

I suspect the Bresenham calculations would need to take place on the Arduino. I had/have hopes that all the hard calculations can be done on the PC - which is easier to program than an Arduino.

...R

Yes, you must do Bresenham (or variation thereon) on the Arduino because it needs to happen for every step. It's a simple algorithm; the hard part is not the calculations but all the jumping through hoops to schedule the timing events accurately and reliably using interrupts. That hard part is unavoidable.

The attraction of just using a long FOR loop is the avoidance of interrupts since the Arduino needs to do nothing else. I will study Bresenham tomorrow.

…R