Test Stepper Motor [Beginner]

Hello !

I launched into the programming for a week for a project in connection with my studies. However my beginner's level returns complicated things.
I have to realize a program to test two engines step by step(Which moves a rail in translation), here is my specifications :

" Realize the program which will later allow to verify the smooth running of the engines of axes X and Y.
1st Program:

  • a procedure of grip of origin (By means of the sensors of the end of running)
  • a sequence of movement such as described below:
    Travel of 100mm according to X.
    Travel of 50mm according to Y.
    Travel of - 50mm according to X.
    Travel of 70mm according to Y.
    Return in the point of origin. "

Here is the material which I have at my disposal:
-L298N Hour-bridge.
-2 moters step by step

  • a card Arduino
  • 4 Sensors of the end of running

I used the function steppers to realize a program but I meet many problems at the level of the programming :

#include <Stepper.h>
const int stepsPerRevolution = 200;
// initialize the stepper library on pins 2-5 n 8-11
Stepper myStepper1(step_360,2,3,4,5);
Stepper myStepper2(step_360,8,9,10,11);
void setup()
{
// set the speed at 60 rpm:
myStepper1.setSpeed(60);//left
myStepper2.setSpeed(60);//right
// initialize the serial port:
Serial.begin(9600);
} myStepper.setSpeed(60);

void loop() {
stepper1.move(200);
stepper2.move(200);
do {
stepper1.run(); // Update du moteur 1
stepper2.run(); //Update du moteur2
capteur = digitalRead(8);
capteur = digitalRead(10);
} while (capteur == LOW);
stepper.stop();
stepper.move(-500);
do {
stepper1.run(); // Update du moteur 1
stepper2.run(); // Update du moteur 2
} while ( stepper1.distanceToGo() != 0 ) || ( stepper2.distanceToGo() != 0);
delay(50);
}
{
Moteur1.step(?); //I have to calculate the report between the steps of the engine and the distance traveled by the wagon.//
delay(50);
Moteur2.step( ?);
delay(50);
Moteur1.step( ?) ;
delay(50);
Moteur2.step( ?) ;
delay(50);
}
{
stepper1.move(200);
stepper2.move(200);
do {
stepper1.run();
stepper2.run();
capteur = digitalRead(8);
capteur = digitalRead(10);
} while (capteur == LOW);
stepper.stop();
stepper.move(-500);
do {
stepper1.run(); // Update du moteur 1
stepper2.run(); // Update du moteur 2
} while ( stepper1.distanceToGo() != 0 ) && ( stepper2.distanceToGo() != 0);
delay(50);
}

Thanks ! :wink:

You need to post your code between code tags, not quote tags. Code tags can be generated using the </> button in the "Post" or "Reply" window.

There are so many problems that it's hard to know where to start.
In this section:-

void setup()
{
    // set the speed at 60 rpm:
    myStepper1.setSpeed(60);//left
    myStepper2.setSpeed(60);//right
    // initialize the serial port:
    Serial.begin(9600);
}  myStepper.setSpeed(60);

you need to delete this:-

myStepper.setSpeed(60);

because
a. You can't have that statement outside the function
b. You don't have a stepper called "myStepper"

Next, you have these lines at the beginning of 'loop()':-

  stepper1.move(200);
    stepper2.move(200);

but you don't have steppers called "stepper1" and "stepper2".

Then, in your 'do..while' loop, you have:-

capteur = digitalRead(8);
capteur = digitalRead(10);

You can't use the same variable to do both digital reads. The second overwrites the first, so you're only effectively reading pin 10.
And you never declare a variable called "capteur" anyway.

Next, you do this:-

  stepper.stop();
    stepper.move(-500);
    do
    {
        stepper1.run();                         // Update du moteur 1
        stepper2.run();                         // Update du moteur 2

when you've never declared steppers named "stepper", "stepper1" or "stepper2".

Then you do:-

  Moteur1.step( ? ); //I have to calculate the report between the steps of the engine and the distance traveled by the wagon.//
    delay(50);
    Moteur2.step( ? );
    delay(50);
    Moteur1.step( ? ) ;
    delay(50);
    Moteur2.step( ? ) ;

but again, you've never declared a stepper called "Moteur1" or "Moteur2". And these will do nothing : ? . (Real values might be a good idea.

Heaps more of the same types of errors all through, and a few others.

You need to stop, go and learn a bit about programming, study the "Stepper" library commands, then start again from the beginning. To be frank, it hurts just looking at this code.

You may find something useful in Stepper Motor Basics, in this Simple Stepper Code and in Planning and Implementing a Program

...R