2_stepper_motors_with_2_drv8825

Hi ,
im very new at arduino word .i just join the forum.i am in dead end as i dont know cc++ and i was searching around to find a way to make my project work.Finaly i decided to ask all of you. :slight_smile:

I have 2 stepper motors nema 17 200steps, 2 drivers DRV8825 2 pushbuttons, 2 limit switches and a genuino uno. :confused:

i want to move the 2 steppers with the 2 drivers but i couldn't find something ready
i'm confused witch library to use ...

i hope someone has the patience and the willingness to help me!

i want to do two things:
1)when i push button1
i want to move stepper1 clockwise till it reach limitswitch1 and then go counterclockwise 1/4 rev.
and stay there. The same time stepper 2 clockwise till it reach limitswitch2 and stay there .
2)when i push button 2
i want to move stepper1 specific time,speed,dir,and also to make pauses between.
At the same time stepper2 do something equivalent

Here are the pins i use
stepper1(7, 8);
stepper2(9,10);

const int dirPin = 8;
const int stepPin = 7;
const int dirPin = 10;
const int stepPin = 9;
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int limswitch1 = 5;
const int limswitch2 = 6;

void setup() {
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
}

Thanks a lot for your time to read all this and i hope that you ll give me a solution!

I don't think the Stepper library is suitable for a DRV8825 which just requires step and direction signals. The AccelStepper library does work with them if you use the DRIVER option.

This Simple Stepper Code should get the motors going and does not need any library.

If you have more questions please post a link to the datasheet for your motors.

...R
Stepper Motor Basics

Thanks for your answer. i already use accelstepper liblary and the motors are moving.
i dont know how to do what i want because i dont know cc++.
the link you attached was helpfull enough but i still dont have it... :frowning:

I found somewhere this code and im using it .Is there any way to make a stop between movement
and to use the buttons?

#include <AccelStepper.h>

AccelStepper stepper1(1, 7, 8);
AccelStepper stepper2(1, 9, 10);

int pos1 = 25;
int pos2 = 25;

void setup()
{
stepper1.setMaxSpeed(1000);
stepper1.setAcceleration(600);
stepper2.setMaxSpeed(1000);
stepper2.setAcceleration(600);
}

void loop()
{
if (stepper1.distanceToGo() == 0)
{
pos1 = -pos1;
stepper1.moveTo(pos1);
}
if (stepper2.distanceToGo() == 0)
{
pos2 = -pos2;
stepper2.moveTo(pos2);
}
stepper1.run();
stepper2.run();
}

Sure, add in reading of buttons and make a decision based on them.

// before setup()
byte button2 = 2; // button on pin 2, wired to connect to GND when pressed
// in setup():
pinMode (button2, INPUT_PULLUP);
// in loop():
if (digitalRead(button2) == LOW){
// take some action
}

kostasgian:
i dont know how to do what i want because i dont know cc++.

The first thing is to write down your requirement in plain language (not code). Write each step of the logic on a separate line.

When you have that done it will be much easier to write code to implement the logic.

Have a look at Planning and Implementing a Program

...R

hi again.
finaly i use this code

#include <AccelStepper.h>

AccelStepper stepper1(1, 7, 8);
AccelStepper stepper2(1, 9, 10);

int pos1 = 27;
int pos2 = 27;

void setup()
{
stepper1.setMaxSpeed(300);
stepper1.setAcceleration(100);
stepper2.setMaxSpeed(300);
stepper2.setAcceleration(100);
}

void loop()
{
if (stepper1.distanceToGo() == 0)
{
pos1 = -pos1;
stepper1.moveTo(pos1);

}
if (stepper2.distanceToGo() == 0)
{
pos2 = -pos2;
stepper2.moveTo(-pos2);
delay(3000);

}
stepper1.run();
stepper2.run();
}

this turn motor1 left and motor 2 right and stay for 3seconds

is it possible someone to tell me how i can
turn motor1 left and motor2 right and stay for 3seconds
and then turn motor1 right and motor2 left and stay for 7seconds
Thanks

Certainly smileys have no part in it. Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Have a look at how timing is managed using millis() in the demo Several Things at a Time. In simple terms you need to record the time (the value of millis() ) when your motors complete the first move and then regularly check the latest value of millis() until 3 seconds (or whatever) have elapsed.

DO NOT use delay() because the stepper.run() function must be called as often as possible.

Also have a look at how to organize your code into functions in Planning and Implementing a Program. If you organize your code that way it will make it much easier to manage and to add features.

...R