I currently have a stepper motor wired through an Easydriver v4.2 controller board to my arduino Duelmilanove.
I have managed to get the motor wired correctly, and successfully working with the Arduino.
Although, unfortunately due to my limited coding ability I am struggling to get my head around how to get the motor to do exactly what I am after;
I require the motor to move 400 microsteps (1/4 of a rotation) over one minute (so rather slowly). Pause, and then reverse back to the original position.
The code I am using was found on lusarobotics, and has been edited by me, though at the moment, My motor is twiching quickly forwards, and then reverse.
If I change the "400" in my loop for "800" it behaves in a completely different manner, going
forward, backward, forward, forward, forward, foraward, forward, forward, backward, forward, backward, foward, backward, forward, backward, forward, forward, forward, forward, forward, backward, backward, backward, forward, forward, forward, forward, forward, backward,forward etc...
which seems borderline random to me... (all these steps are of the same distance.
The code Im using looks like:
int dirPin = 2;
int stepperPin = 3;
void setup() {
pinMode(dirPin, OUTPUT);
pinMode(stepperPin, OUTPUT);
}
void step(boolean dir,int steps){
digitalWrite(dirPin,dir);
delay(100);
for(int i=0;i<steps;i++){
digitalWrite(stepperPin, HIGH);
delayMicroseconds(100);
digitalWrite(stepperPin, LOW);
delayMicroseconds(100);
}
}
void loop(){
step(true,800); // this is the first line I am editing
delay(1000);
step(false,800); //this is the second line I am editing
delay(1000);
}
Any pointers would be greatly appreciated, and I understand that there are probably glaringly obvious reasons for this, but I am not a great coder