Go Down

Topic: Stepper Motors help needed (Read 891 times) previous topic - next topic

akatende

I have been designing a circuit to control multiple stepper motors and i succeeded in that,now my main objective is to be able to control them independently in a way that i am able to command the motors to go to any position randomly without having to wait for all that time of uploading the code to the arduino uno.I have been using this code,any suggestions are highly appreciated.
#include <AccelStepper.h>


AccelStepper bipolar_stepper_motor;
AccelStepper unipolar_stepper_motor(4,6,7,8,9);

void setup()

    bipolar_stepper_motor.setMaxSpeed(200.0);
    bipolar_stepper_motor.setAcceleration(100.0);
    bipolar_stepper_motor.moveTo(24);
   
    unipolar_stepper_motor.setMaxSpeed(300.0);
    unipolar_stepper_motor.setAcceleration(100.0);
    unipolar_stepper_motor.moveTo(1000000);
     
}

void loop()
{
   
    if (bipolar_stepper_motor.distanceToGo() == 0)
   bipolar_stepper_motor.moveTo(-bipolar_stepper_motor.currentPosition());
    bipolar_stepper_motor.run();
    unipolar_stepper_motor.run();
   
}

kf2qd


akatende

How can i control the positions,velocity and acceleration of five stepper   motors, apparently i was able to use the accelstepper library to control 2 bipolar stepper motors but i dint have control of the position.i really really need some help figuring it out..
fortunately or unfortunately the entire project deals with driving five stepper motors of the articulating so not being able to control position of any means a dead end

scottyjr

Do I understand correctly that you seek to control the motors by means of some influence outside the Arduino platform, such as a sensor, switch, pot, etc.? - Scotty

jwatte

There are at least three questions here:

1) How to hook up 5 stepper motors to 1 Arduino
2) How to use the Stepper motor library with 5 stepper motors
3) How to have the code "go to" a position and then stay there

To solve 1, you have to look at your stepper drivers, and see what connections they have. External controllers just need two inputs: direction and step. If those are the ones you're using, then you can use 10 digital pins, such as pins 2 .. 11, to drive 5 motors. If you use EasyDriver shields or similar, then you have more of a wiring problem.

To solve 2, you have to look at the API for the library and how it lets you configure which pins are used. It may support that use case, or it may not -- I haven't used it much myself, so I don't remember. An alternative, if you use two wires per stepper, is simply to set the outputs yourself, and generating the pulses yourself. It's not that hard.

To solve 3, you have to initialize a variable saying "motor is at position 0" on start-up. For each step it takes in the "forward" direction, add one to the variable. For each step it takes in the "backward" direction, subtract one. Then, to control the motor, send not a direction ("forward") but a target ("37"). Then, in the loop, if the motor value is less than the target, step forward once; if the motor value is greater than the target, step backward once; else hold. Because you run the loop many hundreds of times a second, the actual motor movement will be sufficiently smooth. I don't know whether the stepper library actually supports you telling it "only take one step," or whether you need to control the pulses yourself to do this -- check the documentation.

woody_unreal

Quote
I don't know whether the stepper library actually supports you telling it "only take one step,"

Code: [Select]
myStepper.step(stepsPerRevolution)
:)
and of course :)
Code: [Select]
myStepper.step(1);
  Serial.print("steps:" );
  Serial.println(stepCount);
  stepCount++;

akatende

Thanks,my question is more of like the third point,i still havent yet figured it out,so I am asking,sorry if this is a stupid question.


jwatte


Thanks,my question is more of like the third point,i still havent yet figured it out,so I am asking,sorry if this is a stupid question.


Have you tried this? If so, what part do you run into problems with?

Quote
- initialize a variable saying "motor is at position 0" on start-up.
- For each step it takes in the "forward" direction, add one to the variable.
- For each step it takes in the "backward" direction, subtract one.
- to control the motor, send not a direction ("forward") but a target ("37").
- in the loop, if the motor value is less than the target, step forward once; if the motor value is greater than the target, step backward once; else hold.


Go Up