sorry, I wasn’t very clear about that. by increasing the rate I mean increase the delay, or
as you have suggested, I did try to have a delay of once second which didn’t work at all (stalling
or moving back and forth). but: I managed to make it work now, it seems this problem is more
software related. If I only execute the following code the stepper works:
int stepPin = 2;
int dirPin = 3;
void setup(){
Serial.begin(9600);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(dirPin, LOW); // Set the direction.
digitalWrite(stepPin, LOW); // Set the direction.
}
void loop()
{
digitalWrite(stepPin, LOW);
delay(200);
digitalWrite(stepPin, HIGH);
delay(200);
}
the problem is I have some switches that I’d like to use… as soon as the code gets a bit more complex,
the stepper doesn’t work anymore, and I have not been able to understand why… maybe you can find
an error within the code…
int stepPin = 2;
int dirPin = 3;
int turnSwitch = 4;
int dirSwitch = 5;
int laserSwitch = 6;
int ledPin = 7;
boolean isTurning = false;
boolean clockWise = false;
boolean LaserOn = false;
void setup()
{
Serial.begin(9600);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(turnSwitch, INPUT);
pinMode(dirSwitch, INPUT);
pinMode(laserSwitch, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(dirPin, LOW); // Set the direction.
digitalWrite(stepPin, LOW); // Set the direction.
}
void loop()
{
//////////////////////////////////////////// STEPPER ON/OFF
if(digitalRead(turnSwitch) == HIGH){
if(isTurning == false){
isTurning = true;
digitalWrite(ledPin, HIGH);
delay(500);
}
else{
isTurning = false;
digitalWrite(ledPin, LOW);
delay(500);
}
}
//////////////////////////////////////////// STEPPER ON/OFF
//////////////////////////////////////////// DIRECTION CHANGE
if(digitalRead(dirSwitch) == HIGH){
if(clockWise == false){
clockWise = true;
delay(500);
}
else{
clockWise = false;
delay(500);
}
dirChange();
}
//////////////////////////////////////////// DIRECTION CHANGE
stepper();
}
//////////////////////////////////////////// STEPPER METHOD
void stepper(){
if(isTurning == true){
digitalWrite(stepPin, LOW);
delay(500);
digitalWrite(stepPin, HIGH);
delay(500);
}
}
//////////////////////////////////////////// STEPPER METHOD
//////////////////////////////////////////// DIRECTION METHOD
void dirChange(){
if(clockWise == false){
digitalWrite(dirPin, LOW); // Set the direction.
delay(100);
}
else{
digitalWrite(dirPin, HIGH);
delay(100);
}
}
//////////////////////////////////////////// DIRECTION METHOD
I haven’t had so much time to spend on arduino, so maybe I’m doing something
wrong terribly here… I’m glad for any help!
On a side note, while executing the first code example… it works, but
3 steps of 4 the motor vibrates quite a bit and the laser line is thus
quite blurry. is that because of the mircostepping?