Run 2 stepper motors

What torque do you need?

I don’t really know it’s to operate a sliding rail weighing about a kilo.
Cheers
David

Use a scale to show force on the weight in motion. Then have the motor pull on the same scale. The motor should pull that much weight in the same direction, without significantly slowing. Do not let the motor stall.

If the motor needs a little assistance, consider using a gearbox (requires faster motor speed) or block-and-tackle pulley system.

Ok thanks for your help with this.
Cheers
David

It is not done with just choosing a nema 23 motor.
You can have a nema17 with a lot of torque if the motor-length is big enough.

You can have a nema 23 with relative small torque if the motor-length is short.
And even with the same size the torque can vary a lot

best regards Stefan

cheers i will look at that

hi i have altered the code with changing the const unsigned int microstepMultiplier = 1; to (const unsigned int microstepMultiplier = 5;) after making a gearbox to increase torque. this moves the stepper the distance i need but i have messed about to see if i can get the ystepper to half rotation by changing (yStepper.moveTo(STEPS_REVOLUTION / 2):wink: but it turns half and goes back to different positions like it either does not remember where it started from or mot moving the correct steps, any idea what could be the cause of this and how to fix?.
cheers
David

Post the code and I will have a look.

1 Like

Code-Sections have a limited height. That's their most important functionality

  1. limited height
  2. copy code by a single mouse-click in the upright corner of the code-section

I second that. Always post your actual code version as a code-section.

hi thank you, this is the code not sure if i post it here or where as new to this and got a telling off the for putting in the wrong place hopefully this is ok.
// stepper sequence by groundFungus aka c.goulding

#include <MobaTools.h>

const byte xStepPin = 2;
const byte xDirPin = 5;
const byte yStepPin = 3;
const byte yDirPin = 6;

const unsigned int motorStepsPerRev = 200;
const unsigned int microstepMultiplier = 5; //= number of rotations
const int STEPS_REVOLUTION = motorStepsPerRev * microstepMultiplier;

MoToStepper xStepper( STEPS_REVOLUTION, STEPDIR );
MoToStepper yStepper( STEPS_REVOLUTION, STEPDIR );

byte steps = 0; // step in sequence

void setup()
{
Serial.begin(115200);
Serial.println("stepper sequence");

xStepper.attach( xStepPin, xDirPin );
xStepper.setSpeedSteps(5000); // = 1000 steps/sec (steps /10)
xStepper.setRampLen(10);
xStepper.setZero();

yStepper.attach( yStepPin, yDirPin );
yStepper.setSpeedSteps(3000); // = 1000 steps/sec (steps /10)
yStepper.setRampLen(10);
yStepper.setZero();

delay(4000);
}

void loop()
{
if (steps == 0)
{
xStepper.move(STEPS_REVOLUTION); // roatate 1 rev
steps = 1;
}

if (steps == 1)
{
if (xStepper.distanceToGo() == 0)
{
Serial.println("step 1 complete");
steps = 2;
}
}

if (steps == 2)
{
yStepper.moveTo(STEPS_REVOLUTION / 10); // devides rotation for cutter
steps = 3;
}

if (steps == 3)
{
if (yStepper.distanceToGo() == 0)
{
Serial.println("step 2 complete");
steps = 4;
}
}

if (steps == 4)
{
yStepper.moveTo(0);
steps = 5;
}
if (steps == 5)
{
if (yStepper.distanceToGo() == 0)
{
Serial.println("step 4 complete");
steps = 0;
}
}

}

please RE-edit your posting to present your code as a code-section

click on the pencil-icon below your posting and then re-edit your posting following this short tutorial

best regards Stefan

Hi I would also like to know how many cycles stepper has done, would it be possible to add a sketch to this using a HD44780 1602 16x2 LCD Display Module to display the cycles it has done for the period it’s was on and reset when it’s been switched off?.
Cheers
David

Hi thank you. Where do I find the code section I have looked but can’t see anywhere that says code section. Sorry I am very new to this so have difficulty finding my way around at the moment.
Cheers
David

click on the link
Make experienced users help: two ways to quickly post code as a code-section
and read the steps how to do it

// stepper sequence by groundFungus aka c.goulding

#include <MobaTools.h>

const byte xStepPin = 2;
const byte xDirPin = 5;
const byte yStepPin = 3;
const byte yDirPin = 6;


const unsigned int motorStepsPerRev = 200;
const unsigned int microstepMultiplier = 5; //= number of rotations
const int STEPS_REVOLUTION = motorStepsPerRev * microstepMultiplier;

MoToStepper xStepper( STEPS_REVOLUTION, STEPDIR );
MoToStepper yStepper( STEPS_REVOLUTION, STEPDIR );

byte steps = 0; // step in sequence

void setup()
{
   Serial.begin(115200);
   Serial.println("stepper sequence");

   xStepper.attach( xStepPin, xDirPin );
   xStepper.setSpeedSteps(5000); // = 1000 steps/sec (steps /10)
   xStepper.setRampLen(10);
   xStepper.setZero();

   yStepper.attach( yStepPin, yDirPin );
   yStepper.setSpeedSteps(3000); // = 1000 steps/sec (steps /10)
   yStepper.setRampLen(10);
   yStepper.setZero();

   delay(4000);
}

void loop()
{
   if (steps == 0)
   {
      xStepper.move(STEPS_REVOLUTION); // roatate 1 rev
      steps = 1;
   }

   if (steps == 1)
   {
      if (xStepper.distanceToGo() == 0)
      {
         Serial.println("step 1 complete");
         steps = 2;
      }
   }

   if (steps == 2)
   {
      yStepper.moveTo(STEPS_REVOLUTION / 10); // devides rotation for cutter
      steps = 3;
   }

   if (steps == 3)
   {
      if (yStepper.distanceToGo() == 0)
      {
         Serial.println("step 2 complete");
         steps = 4;
      }
   }

   if (steps == 4)
   {
      yStepper.moveTo(0);
      steps = 5;
   }
   if (steps == 5)
   {
      if (yStepper.distanceToGo() == 0)
      {
         Serial.println("step 4 complete");
         steps = 0;
      }
   }

}

hi i think i did it dont know if this is correct but followed instructions, can you let me know if i have.
cheers
david

Yes very good.
Now your code is easy to read and easy to analyse.
You have used if-conditions to make the code drive the stepper-motors in a certain sequence.

Your method works.
Executing certain steps in a well defined order can be done more efficient with the switch-case-break;-statement.
The break; is really important !

The break; is that part that makes the code-execution mutually exclusive.
Using the switch-case-break-statement minimizes the number of if-conditions and can be easily maintained and expanded.

Please write down a normal worded description of what you want the two stepper-motors to do.

best regards Stefan

I will leave you in the hands of @StefanL38 since my if, else if, else code is so inefficient. It was meant to be easy to follow. But they, obviously, are much more knowledgeable.

Hi easy sounds good to me as i am a beginner at using arduino soe easier the better for me

Hi Stefan, thank you for your reply and help, i am very new to this so forgive me but i dont understand what you are telling me to do, i dont have a clue where or how to use switch-break-statement, what is it that i change all the if's to break; is that what you mean?. and where do i write down what i want the stepper motor to do, inbetween the brackets for example if (yStepper.distanceToGo() == 0) do i change that to, break; (yStepper.distanceToGo() == 0)
cheers
David

Your style of asking questions is very good.
You are asking with making assumptions asking if they are correct.
These assumptions give helpful information on how to explain it.

Well if you don't want to wait for an answer in the forum you can google yourself

use the keywords Arduino C++
and
additionally the words of interest
which in this case is
switch case break

Arduino C++ switch case break
https://www.google.com/search?as_q=Arduino+C%2B%2B+switch+case+break
The minimum that you will find is the arduino-reference.

Though the reference is not the best explaining because the explanations are short.
Sometimes too short to be understandable.

Anyway take a look into it

Here is a tutorial about it. You can give it a try.
If you find it hard to understand you should start with simpler things.

If you find this hard to understand you should start with simpler things
Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

Of course you can ask any questions you like. Including very very elementary questions.
So my suggestion is that you work through this tutorial and ask questions as soon as you do not understand a detail.

best regards Stefan