Re: Multiple stepper motors

Hi all,

I’m working on a similar project where I want to input an array into serial that references [which motor, how far to turn]. I have a code that is similar to above, but am running into some issues with the arrays. Can anyone give some guidance?

#include <Stepper.h>

const int stepsPerRevolution = 512; 
int motorcommand[2];
int motornumber=0;
int motorturns=0;
Stepper motor1(stepsPerRevolution, 12,11,10,9);            
Stepper motor2(stepsPerRevolution, 8,7,6,5);            

void setup() {
 motor1.setSpeed(25);
 motor2.setSpeed(25);
 Serial.begin(9600);
}

void loop() {

 if (Serial.available())
 {
   motorcommand[2] = Serial.read();
   motornumber = motorcommand[1];
   motorturns = motorcommand[2];
   Serial.print("Turn motor ");
   Serial.println(motornumber, DEC);
   Serial.print("Turn amount ");
   Serial.println(motorturns, DEC);
   if (motorcommand[1]==1)
   {
   motor1.step(motorturns);
   }
   if (motorcommand[1]==2)
   {
   motor1.step(motorturns);
   }
 }
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Hi all,

I’m working on a similar project where I want to input a serial array of [which motor to turn, # of steps], but running into some issues with the arrays. Anyone have a suggestion on how to make this work?

Thanks for the help

#include <Stepper.h>

const int stepsPerRevolution = 512; 
int motorcommand[2];
int motornumber=0;
int motorturns=0;
Stepper motor1(stepsPerRevolution, 12,11,10,9);            
Stepper motor2(stepsPerRevolution, 8,7,6,5);            

void setup() {
  motor1.setSpeed(25);
  motor2.setSpeed(25);
  Serial.begin(9600);
}

void loop() {

  if (Serial.available())
  {
    motorcommand[2] = Serial.read();
    motornumber = motorcommand[1];
    motorturns = motorcommand[2];
    Serial.print("Turn motor ");
    Serial.println(motornumber, DEC);
    Serial.print("Turn amount ");
    Serial.println(motorturns, DEC);
    if (motorcommand[1]==1)
    {
    motor1.step(motorturns);
    }
    if (motorcommand[1]==2)
    {
    motor1.step(motorturns);
    }
  }
}

It's theoretically possible to control a stepper with a single pin (because a pin has four possible states), but you'd need a fair bit of circuitry hanging off it.

Please do not cross-post. Please do no hijack. Threads split and merged.

Hi all,

I am looking into a project where I’ll be controlling 5 NEMA 42 steppers (8A, 4V) all operating at different times. Does anyone have some guidance on how to set this up in the most efficient way?

Thanks!

That's a big stepper motor.
You might need something very big and ugly like this : High-Torque Stepper Motor, Stepper Motor, Driver, Stepper Motor kit, DC Servo Motor, DC Servo Motor kit, Stepper Motor Power Supply, CNC Router, Spindle, and other Components.

Controlling 5 stepper motors depends on the driver. Some drivers are intelligent, others need a step and direction signal.
The AccelStepper supports mulitple stepper motors.
http://www.airspayce.com/mikem/arduino/AccelStepper/

You need to tell us what you want the motors to do - in particular, do you want them to move in a co-ordinated way as required by a CNC machine or 3D printer?

Also, where will the information come from that describes what moves the motors have to make?

It would also be very useful to tell us what is your experience so we don't waste time with the basics if you don't need them.

That said, you may get useful info from stepper motor basics. It was not written with large stepper motors in mind, but the general principles are the same for all stepper drivers that use step and direction signals.

I have written code to drive 3 steppers on my small lathe. Extending the general approach to 5 should not be difficult.

...R

@jgatvl, stop cross-posting.

Apologies, I am new to the forum and thought that hardware specific questions should be separated.

Was more looking at what kind of power supply and drivers would be needed to control a motor this big.

Regarding the software piece, another device will be outputting an array which will dictate which motor will turn, and how far. These are small movements and only one motor will turn at a time.

The other device will take up 6 pins and each of the 5 motors should take up four each. I'm assuming I need to move to a MEGA? Then each motor will require it's own stepper, or can I just use one since only one motor will move at any given time?

Thanks again for everyone's help!

jgatvl:
...thought that hardware specific questions should be separated.

Reasonable choice.

Was more looking at what kind of power supply and drivers would be needed to control a motor this big.

When you do actually ask a question about powering the motors this is a good place...
Motors, Mechanics, and Power

[quote author=Coding Badly date=1427137774 link=msg=2153844]Reasonable choice.

When you do actually ask a question about powering the motors this is a good place...
Motors, Mechanics, and Power[/quote]
Personally, I find it easier if there is just a single Thread for a single project, even if it spreads between programming and hardware. When there is a single Thread all of the relevant data is in one place.

It can be very difficult to draw a hardware/software line between the cause of problems and the solutions until the problem is solved.

Apart from that there is a "natural" tendency for Threads to wander and when there are two Threads the wandering will result in overlap regardless of the original best intentions of the OP.

...R

Thanks for everyone's input-- will stick by this suggestions from now on.

I've figured out how to pull in an array from serial now and have it set up to choose a motor, then turn it.

Regarding the hardware piece (once I scale up to the NEMA 42) what do you think would be the best way to control 5+ motors? The other device I'll be using to feed inputs will take up 6 pins and each of the 5 motors will take up four each. I'm assuming I need to move to a MEGA? Will each motor will require it's own driver, or can I set it up with some switchrs and a single driver since only one motor will move at any given time?

Thanks for the help!

Why would the motors need 4 pins each? The usual is 2 for step and direction.

Assuming you are using a specialized stepper motor driver the control does not vary just because the driver is more powerful.

...R

PaulMurrayCbr:
It's theoretically possible to control a stepper with a single pin (because a pin has four possible states), but you'd need a fair bit of circuitry hanging off it.

Care to elaborate on that?

crOsh, that is output HIGH, output LOW, input floating, input with internal pullup.
I think PaulMurryCbr was only talking about that 4 pins for a stepper is not a fact, that in theory a single pin is possible.

Perhaps my brain works a lillte like PaulMurryCbr's brain, because there are possibilities. Suppose a voltage regulator has a feedback. Then the Arduino can be used to inject current in the feedback with exteranl resistor. The four different pin states would result into four different voltages :slight_smile:

Peter_n:
crOsh, that is output HIGH, output LOW, input floating, input with internal pullup.

I’m not sure that those 4 states can be sensed by an external device ?

…R