Hi everyone ,
I am using 2 a4988 and 2 stepper motors.I want 2 stepper motors to run continuously in the for loop. I write the for loop as repeat 10 times but the loop works only once .
Where am I making a mistake?
What should I do for this?
#include <AccelStepper.h>
#include <MultiStepper.h>
// Define the stepper motor and the pins that is connected to
//stepper 1 flasteri ilerleten motor
//stepper 2 kesici motor
AccelStepper stepper1(1, 3, 2); // (Typeof driver: with 2 pins, STEP, DIR)
AccelStepper stepper2(1, 9, 10);
void setup() {
stepper1.setMaxSpeed(1000); // Set maximum speed value for the stepper
stepper1.setAcceleration(1500); // Set acceleration value for the stepper
stepper1.setCurrentPosition(0); // Set the current position to 0 steps
stepper1.setSpeed(200);
stepper2.setMaxSpeed(1000);
stepper2.setAcceleration(1500);
stepper2.setCurrentPosition(0);
stepper2.setSpeed(200);
}
void loop() {
for (int i = 0; i <= 10; i++) {
stepper1.runToPosition(); // Moves the motor to target position w/ acceleration/ deceleration and it blocks until is in position
stepper1.moveTo(5000); // Set desired move: 200 steps (full çözünürlükte 200 adım bir tur dönmesi anlamına geliyor. (biz 0,5 çapta 1 turu 3,14 cm diyelim) )
delay(1000);
stepper2.runToPosition();
stepper2.moveTo(500);
stepper2.moveTo(-500);
delay(1000);
}
for (int i = 0; i <= 10; i++) {
stepper1.runToPosition(); // Moves the motor to target position w/ acceleration/ deceleration and it blocks until is in position
stepper1.moveTo(5000); // Set desired move: 200 steps (full çözünürlükte 200 adım bir tur dönmesi anlamına geliyor. (biz 0,5 çapta 1 turu 3,14 cm diyelim) )
delay(1000);
stepper2.runToPosition();
stepper2.moveTo(500);
stepper2.moveTo(-500);
delay(1000);
}
This doesn't really make sense. runToPosition and moveTo should be the other way round. First tell the motor where to go, and then start the movement. Be aware, the runToPosition is a blocking move. It moves the stepper to the position last set by moveTo. But once this position is reached, further calls to runToPosition will not do anything, if you don't change the target position. In your loop, the target position is always the same in every loop cycle. So nothing happens anymore once this position is reached.
stepper2.moveTo(500);
stepper2.moveTo(-500);
The first moveTo is completely useless, becase you immediately change the target to a new positon without moving to the first.
What do you really want to do? Your sketch will never run both steppers continuously at the same time.
I want to make a paper cutting machine . Paper size 10 cm x10 meters. The first stepmotor should extend the paper by 6 cm and then wait (in the meantime, the second stepmotor should operate the paper cutter mechanism).
The comments below the video indicate flaws in the design (wrong motors and drivers) and code (does not write to motors in the video)... and the display is not coded in the sketch, but is a binary file needing to be uploaded to a Nexion.
You should step back from the code and write a functional description in normal words.
what do you want to the paper-cut machine to do ?
Of course cutting paper.
But what shall happen in detail?
rotating the stepper-motor that unrolls the paper from the roll.
unwinding 10 m of paper continiously?
or
unwinding in mutliple steps with stopping the unwinding inbetween ?
How many steps does the stepper-motor rotate into one direction before the cutter is activated?
How many steps must the stepper-motor rotate that push/pulls the cutter-knife?