Can anyone tell me why the first motor that I call with the "moveMotor" function is the only one that moves?
Why wouldnt this move both motors? In the below example... motor2 just moves... if i call the function in the reverse order motor1 just moves.... what am i missing? (see attachment)
#include <Stepper.h>
#define STEPS 100 //Number of steps per revolution
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4 and then the pins entered
// here in the sequence 1-3-2-4 for proper sequencing
Stepper motor1(STEPS, 8, 10, 9, 11);
Stepper motor2(STEPS, 6, 12, 7, 13);
void setup()
{
// set the speed of the motor
moto.setSpeed(300);
small_stepper2.setSpeed(300);
}
void moveMotor(Stepper mtr, int spd, int sps){
mtr.setSpeed(spd);
mtr.step(sps);
}
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
moveMotor(motor2, 200, 800);
delay(500);
moveMotor(motor1, 200, 800);
delay(500);
}
Try again with working code:
sketch_jul07b.ino: In function 'void setup()':
sketch_jul07b:24: error: 'moto' was not declared in this scope
sketch_jul07b:25: error: 'small_stepper2' was not declared in this scope
DUH! I was trying so many things that I dont think the undo went back that far; here is another go:
#include <Stepper.h>
#define STEPS 100 //Number of steps per revolution
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4 and then the pins entered
// here in the sequence 1-3-2-4 for proper sequencing
Stepper motor1(STEPS, 8, 10, 9, 11);
Stepper motor2(STEPS, 6, 12, 7, 13);
void setup()
{
// set the speed of the motor
motor1.setSpeed(300);
motor2.setSpeed(300);
}
void moveMotor(Stepper mtr, int spd, int sps){
mtr.setSpeed(spd);
mtr.step(sps);
}
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
moveMotor(motor2, 200, 800);
delay(500);
moveMotor(motor1, 200, 800);
delay(500);
}
How are you powering the stepper? How much current do they draw?
Add (to setup)
Serial.println("Start ");
delay(500);
this lets you check that the sketch is not bing reset.
Mark