Stepper motor help needed

Hi all, basically I am a mechanical engineer and I can build anything mechanical and most arduino stuff but when I get some project in my head that goes past my knowledge Arduino base I am stumped

I have a CNC 3 axis I built that works great and makes lovely things, but I have a project I want to build with 5 stepper motors, this is for a moving archery targets I so want to get right

I have a few normal V3 stepper boards several Uno and Mega boards and several drivers from DRV8825 and TB6600 drivers and loads of kit including power supplies

but I can't find any way of controlling 5 stepper motors from 1 computer with a pre programmed schedule of motor movements

Maybe if I explain what I am attempting to do, imagine 5 items that I want to reveal and hide in turn, so that these can happen exactly the same every time, and when a set of movements have happened, the same range of movements and timing will be exactly the same every time it is run, hence my wish to use stepper motors for accuracy and speed control

Anyone help me ? I don't mind buying some new kit or shields if needed

Thanks everyone, stay safe & healthy

If you like the convenience of the CNC V3 board but need more than 3 (or 4) motors maybe consider a Ramps board (shield) and a Mega to run it. The Ramps shield holds drivers for 5 motors along with 2 MOSFETs to control loads and connections for limit switches, etc.

A class of the AccelStepper library called MultiStepper makes it easier to have several steppers with coordinated motions. The maximum speed of motions is limited with Multistepper because it does not use acceleration. That max speed is determined by the stepper, the driver and the voltage of the stepper power supply.

1 Like

You could also use my MobaTools lib. It can control up to 6 steppers simultaneously.
If you start them always with the same speed, acceleration and timing, the movements will be exactly the same.

A little more information about the timing of the movement and the required step rates/speeds would be helpful.

1 Like

Here is a one stepper example using AccelStepper library and arrays of positions and speeds for a sequence that may be helpful.

#include <AccelStepper.h>

const unsigned int NUM_STEPS = 6;

unsigned int xArray[NUM_STEPS] = {0, 900, 650, 400, 650, 100};
unsigned int xSpeeds[NUM_STEPS] = {200, 2000, 200, 100, 400, 50};

const byte enablePin = 8;

AccelStepper x_stepper(AccelStepper::DRIVER, 2, 5);

void setup()
{
   Serial.begin(115200);
   pinMode(enablePin, OUTPUT);
   digitalWrite(enablePin, LOW);
   x_stepper.setAcceleration(2000);
   x_stepper.setMaxSpeed(200);
   x_stepper.setSpeed(200);
   x_stepper.setCurrentPosition(0);
}

void loop()
{
   static unsigned int index = 0;
   if (x_stepper.run() == 0)
   {
      Serial.println(index);
      x_stepper.moveTo(xArray[index]);
      x_stepper.setMaxSpeed(xSpeeds[index]);
      index++;
      if (index >= NUM_STEPS)
      {
         index = 0;
      }
   }
}
1 Like

but I can't find any way of controlling 5 stepper motors from 1 computer with a pre programmed schedule of motor movements

And here is an example using arrays of positions and speeds with the MultiStepper library and 2 steppers. This could be expanded to 5 steppers.

#include <AccelStepper.h>
#include <MultiStepper.h>

int xPositions[] = { -100, 2000, -5000, 0, 5000, 0};
int yPositions[] = { -500, 3000, -10000, 0, 1000, 0};
int speeds[] = {100, 2000, 1000, 200, 500, 1000};

// EG X-Y position bed driven by 2 steppers
// Alas its not possible to build an array of these with different pins for each :-(
AccelStepper stepper1(AccelStepper::DRIVER, 2, 5);
AccelStepper stepper2(AccelStepper::DRIVER, 3, 6);

const byte enablePin = 8;  // necessary for my CNC shield V3.
long positions[2]; // Array of desired stepper positions
int numSteps = 0;

// Up to 10 steppers can be handled as a group by MultiStepper
MultiStepper steppers;

void setup()
{
   Serial.begin(9600);
   pinMode(enablePin, OUTPUT);
   digitalWrite(enablePin, LOW);

   // Configure each stepper
   stepper1.setMaxSpeed(1000);
   stepper2.setMaxSpeed(1000);

   // Then give them to MultiStepper to manage
   steppers.addStepper(stepper1);
   steppers.addStepper(stepper2);
   numSteps = sizeof(xPositions) / sizeof(xPositions[0]);
}

void loop()
{
   static int index = 0;
   if (steppers.run() == 0)
   {
      //Serial.print("run  ");
      //Serial.println(index);
      positions[0] = xPositions[index];
      positions[1] = xPositions[index];
      stepper1.setMaxSpeed(speeds[index]);
      stepper2.setMaxSpeed(speeds[index]);
      steppers.moveTo(positions);
      index++;
      if (index > numSteps)
      {
         index = 0;
      }
   }
}
1 Like

It sounds plausible enough. Get a suitable driver for each stepper from Pololu, a homing microswitch apiece and a power supply or supplies to drive the motors.

Each motor needs step, direction and homing detection. Fifteen pins, probably another one for a button to start things off, so even an Uno could do it.

1 Like

Once you move to lots of axes for CNC you might want to consider a faster microcontroller than an Uno or Mega - specifically one with hardware floating point (Teensy 4.x springs to mind) - that way the overhead of calculating step times for lots of motors simultaneously isn't going to throttle performance.

And the other approach is to step up to a system like LinuxCNC on a RPi or similar, which handles 9 axes out of the box - but of course needs to be driven with GCODE being a full CNC controller.

Good advice. In this case though, I don't think it matters because I get the impression that the targets move one at a time. Maybe initial homing is an exception, but even then I doubt speed and stepper interaction needs much CPU power.

On a UNO/Mega, the MobaTools lib can control up to 6 steppers at up to 2500 steps/sec each simultaneously. I suppose this should be sufficient here.
But as long as @ArcherToad doesn't post the requirements, it's all speculation.

Sounds like a plan, I don't need the accuracy of my CNC router, milling machine but do need to be sure that each time the system runs it will be exactly the same timing for each time I run it, I have actually bought a ramps kit and will play with that over the weekend thanks for the help

1 Like

Here is the (partial) Ramps board to the Mega pin mapping for your information.

And a schematic showing the pin to pin mapping.

Hi there, thanks for the advice and help, here is what I want to achieve, I have built the mechanical side of the archery pop up targets, so maybe I should explain, I have 5 see saw all nicely balanced and it is built with a load of bearings and they really are smooth, so nicely balanced that they can be moved with very little effort, so imagine 5 see saws each end has a target, so 10 targets in total, at the start no targets are showing, what I want to achieve is that the stepper motors work i sequence raising or lowering each target after it has been stationary for a few seconds, then disappears, so my archers have to react quite quickly or miss, when all the sequence has ended and the next archer comes to try for a score they get the same chances, I could be wrong but I just feel that using 5 stepper motors which I already have they are strong enough to move the target and have a very good hold with the torque so the target won't creep and appear locked for the few seconds needed, I thank yo all for your help it has been extremely usefull but please keep the suggestions coming

hi, yes correct the way the targets operate doesn't require much power at all, just want a nice speed of target without being super fast and a fast disappear, most of the time the steppers will not move more than 1 or 2 turns each time they are needed,

Best that I can say is to have a go at the code and if you have trouble post the code with a description of what it actually does and how that differs from what you want.

Also post a schematic.

I have a Ramps 1.4 board and Mega and steppers so can duplicate your project to some extent so that makes it easier to help. Write the code step by step. Stop and test often. Save often.

That looks amazing, if it can work that much that really does open my imagination, I have several projects on the go for the archery club and 1 of which is a sort of practical archery range with sensors that make targets rise and fall as the archer walks through, that really does look the business for me on that project as well as this one, Thanks much appreciated

I can see this ending up as being a lot of fun developing this and then modifying and tinkering with the codes will make this amazing

The speed depends a lot on power supply voltage. Use the highest voltage that your drivers will tolerate. For high speed, acceleration is necessary so the MultiStepper will be out. Experimentation can tell what you will need to get the speed that you want. You may need some microstepping to avoid resonance but, again, experimentation can tell you how much if any.

Hi Fungus, I am self taught about steppers and arduino from YouTube University, and I have never found out what is the optimum voltage or amps power supply for my stepper motors, the spec sheet on the motors says something like 1.4 volts which I know isn't relevant to real life and I run them from a 24 Volt supply which the motors etc seem to be quite happy with, can you educate me and tell me more about CNC stepper voltages

OK, here is my understanding. The voltage stated on the stepper motor data sheet is largely irrelevant. The Important spec is the coil current. For best speed, the motor supply should be as high as the stepper drivers can tolerate (45V for the DRV8825, 42V for TB6600). If you get good speed with 24V that is fine. I run my mini engraving machine and my 2D plotter at 12V.

The stepper driver must be set to limit the current (no matter the voltage) to the stepper coils to the maximum coil current specified in the data sheet or less. The procedure for setting the coil current for the DRV8825 drivers can be seen on the Pololu DRV8825 page. The coil current limit on the TB6600 is set by the DIP switches. The coil current must be set before the motors are used.

There may be information of interest in Robin2's stepper basics tutorial.

Yes that's basically it. Stepper windings are inductive, and this dominates performance. If you assume DC conditions then only the resistance of the winding comes into play, but that is not how steppers are used (constantly stationary!).

For inductance the higher the voltage the more rapidly the current can change, and for a standard 200-step-per-rev motor at 1000rpm the current in each winding has to reverse about 1600 times per second (current reverses every 2 steps) -(*)

Consider a typical NEMA17 sized stepper with about 2 ohms and 5 millihenry winding impedance:

resistance: 2 ohms
inductive reactance at 1600Hz: 50 ohms

Thus the winding resistance is completely irrelevant. If you want to get 1A in a winding you need at least 50V supply voltage.

This is why the key specs of a stepper are usually rated current and inductance (but inductance and resistance are strongly related in practice, low resistance implies low inductance).

(*) by contrast a typical DC motor at 4000rpm only reverse at a rate of 130Hz - inductance usually isn't very important for DC motors (and thus their torque doesn't drop much with speed).