Best Library for 10+ Stepper Motor Control

Hello,

I have a script that controls 5 stepper motors simultaneously. Its a fairly simple script using the MoToStepper library from MobaTools.

Link: GitHub - MicroBahner/MobaTools: Arduino library for model railroaders

My intent is to increase the number of stepper being controlled to 10. The issue is, this library only allows the control of 6 steppers at one time. I am not doing any think fancy, just pre-set clockwise and counterclockwise turns the may-or-may not occur at the same time as the other steppers.

My question is: Has anyone else used this library and found a way around this limit? The total control limit for servos with the library is 16. If not is there a more suitable library that I can use to control 10+ stepper with overlapping movements? (As I said, I don't need the bells and whistles, just simple setting of speeds and directions.)

Thanks in advance for the help!

Opposed to the 16 Servo limit - which is really a hard limit because of the software structure - the 6 stepper limit isn't that hard. This limit is dependent on various facts - especially max speed of the steppers, use of SoftLeds ( which are processd in the same ISR ) and processor speed.
The actual limit is set by a define in MobaTools.h:
#define MAX_STEPPER 6
Please show your sketch for a first estimate if it may be possible to set this higher.
Which Arduino are you using?

MicroBahner,

Thanks for the reply! I am using a mega 2560. Below is the script for 10 steppers. Just as a note, I am using the mega with a RasPi. Most of the logic is controlled at the RasPi, and it just sends a command to the mega, via serial, to turn the motors (i.e. the "arrival" variable is just a value sent from the RPI to initiate a turn sequence.) Currently, I am running the motors at 2,500 (steps/10 seconds, I believe), but I have run them at 6,000 (i.e. 60,000 steps/second) previously, so hoping I have some room to increase the # of steppers, due to the slower speed?

With regard to the limit set in MobaTools.h, that was my initial hunch. So hopefully I will be eligible to redefine that variable.

Let me know your thoughts!

#include <MobaTools.h>

const int STEPS_REVOLUTION = 200; //Not micro-stepping, step angle 1.8deg/step or 200 steps/rev

//---Stepper 1---
const byte _1_s_pul = 61;
const byte _1_s_dir = 60;
MoToStepper stepper_1( STEPS_REVOLUTION, STEPDIR );

//---Stepper 2---
const byte _2_s_pul = 55;
const byte _2_s_dir = 54;
MoToStepper stepper_2( STEPS_REVOLUTION, STEPDIR );

//---Stepper 3---
const byte _3_s_pul = 44;
const byte _3_s_dir = 42;
MoToStepper stepper_3( STEPS_REVOLUTION, STEPDIR );

//---Stepper 4---
const byte _4_s_pul = 32;
const byte _4_s_dir = 30;
MoToStepper stepper_4( STEPS_REVOLUTION, STEPDIR );

//---Stepper 5---
const byte _5_s_pul = 10;
const byte _5_s_dir = 11;
MoToStepper stepper_5( STEPS_REVOLUTION, STEPDIR );

//---Stepper 6---
const byte _6_s_pul = 68;
const byte _6_s_dir = 69;
MoToStepper stepper_6( STEPS_REVOLUTION, STEPDIR );

//---Stepper 7---
const byte _7_s_pul = 5;
const byte _7_s_dir = 4;
MoToStepper stepper_7( STEPS_REVOLUTION, STEPDIR );

//---Stepper 8---
const byte _8_s_pul = 27;
const byte _8_s_dir = 29;
MoToStepper stepper_8( STEPS_REVOLUTION, STEPDIR );

//---Stepper 9---
const byte _9_s_pul = 39;
const byte _9_s_dir = 41;
MoToStepper stepper_9( STEPS_REVOLUTION, STEPDIR );

//---Stepper 10---
const byte _10_s_pul = 51;
const byte _10_s_dir = 53;
MoToStepper stepper_10( STEPS_REVOLUTION, STEPDIR );

int arrival = 0;

void setup() {

  //Serial setup
  Serial.begin(115200);
  Serial.setTimeout(4); //was 0.4

  //---Stepper 1---
  stepper_1.attach(_1_s_pul, _1_s_dir);
  stepper_1.setSpeedSteps(2500); 

  //---Stepper 2---
  stepper_2.attach(_2_s_pul, _2_s_dir);
  stepper_2.setSpeedSteps(2500);

  //---Stepper 3---
  stepper_3.attach(_3_s_pul, _3_s_dir);
  stepper_3.setSpeedSteps(2500);

  //---Stepper 4---
  stepper_4.attach(_4_s_pul, _4_s_dir);
  stepper_4.setSpeedSteps(2500);

  //---Stepper 5---
  stepper_5.attach(_5_s_pul, _5_s_dir);
  stepper_5.setSpeedSteps(2500);

  //---Stepper 6---
  stepper_6.attach(_6_s_pul, _6_s_dir);
  stepper_6.setSpeedSteps(2500);

  //---Stepper 7---
  stepper_7.attach(_7_s_pul, _7_s_dir);
  stepper_7.setSpeedSteps(2500);

  //---Stepper 8---
  stepper_8.attach(_8_s_pul, _8_s_dir);
  stepper_8.setSpeedSteps(2500);

  //---Stepper 9---
  stepper_9.attach(_9_s_pul, _9_s_dir);
  stepper_9.setSpeedSteps(2500);

  //---Stepper 10---
  stepper_10.attach(_10_s_pul, _10_s_dir);
  stepper_10.setSpeedSteps(2500);
}

void loop() {
  
  if (Serial.available() > 0) {
    arrival = Serial.parseInt();

    //---Stepper 1------------------------------------------
    if(arrival == 1)
      stepper_1.doSteps(11560);
      
    if(arrival == 2)
      stepper_1.doSteps(-11560);

     //---Stepper 2------------------------------------------
    if(arrival == 11)
      stepper_2.doSteps(11560);
      
    if(arrival == 12)
      stepper_2.doSteps(-11560);
      
     //---Stepper 3------------------------------------------
    if(arrival == 21)
      stepper_3.doSteps(11560);
      
    if(arrival == 22)
      stepper_3.doSteps(-11560);
      
     //---Stepper 4------------------------------------------
    if(arrival == 31)
      stepper_4.doSteps(11560);
      
    if(arrival == 32)
      stepper_4.doSteps(-11560);
      
     //---Stepper 5------------------------------------------
    if(arrival == 41)
      stepper_5.doSteps(11560);
      
    if(arrival == 42)
      stepper_5.doSteps(-11560);
      
    //---Stepper 6------------------------------------------
    if(arrival == 51)
      stepper_6.doSteps(11560);
      
    if(arrival == 52)
      stepper_6.doSteps(-11560);
      
     //---Stepper 7------------------------------------------
    if(arrival == 61)
      stepper_7.doSteps(11560);
      
    if(arrival == 62)
      stepper_7.doSteps(-11560);
      
    //---Stepper 8------------------------------------------
    if(arrival == 71)
      stepper_8.doSteps(11560);
      
    if(arrival == 72)
      stepper_8.doSteps(-11560);
      
     //---Stepper 9------------------------------------------
    if(arrival == 81)
      stepper_9.doSteps(11560);
      
    if(arrival == 82)
      stepper_9.doSteps(-11560);
      
    //---Stepper 10------------------------------------------
    if(arrival == 91)
      stepper_10.doSteps(11560);
      
    if(arrival == 92)
      stepper_10.doSteps(-11560);
  }
}

With this speed it should be possible to control 10 steppers. Even 6000steps/10sec seems to be possible because you don't use Softleds.

I would recommend to learn aboout arrays. Your sketch will be much shorter and more easy to maintain.

MicroBahner,

(Just seeing now that the 60,000 steps/second is obviously not correctly calculated haha. Division is hard some times for me apparently...)

But anyways, yes that was my hunch as well! Appreciate the help! Definitely feel more confident with a second opinion.

Out of curiosity before this form is closed. Under the conditions described above, what do you think is the max about of steppers I can control? I had some future plans to try and expand to 20, but not sure if I'm pushing my luck.

Hi all. Seems that you guys have alot of experience with MobaTools. I'm running a single Nema23+TB6600 set and it's kinda difficult to make it run without occasional missed steps and erratic behaviour. I've tried with different currents, different microsteps as well, but I actually need it to be on the 1 step configuration, otherwise the speed isn't enough for my purposes. When zero is set and make it run on loops back and forward the zero position is drifted slowly. Also if you make it run a certain number of turns sometimes it's not completing the round accurately, though by very little. What are your advices for running this system reliably? Thanks in advance.

Problem is most likely the TB6600.

1 Like

@mogo4414: Sorry for the very late reply - unfortunately I completely overlooked your post.
20 steppers is definitely a lot - I never tried that much steppers by far. It's a question of the time the ISR needs to complete. That may be too long with that number of steppers.

@fbolzoni: You should not hijack other threads. Ask a moderator to move your post to a new topic. And your question has nothing to do with using a large number of steppers.
There may be different reasons for your problem. Please post your sketch that shows the problem and a schematic with all wiring and links to the used components - especially the stepper and the PSU.

Got it MicroBahner. Thanks for your help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.