First post here, I have some stepper motors with controllers that I would like to use the difficulty I have is the controllers are based on STK672-540 controllers which basically take a clock signal and a direction signal which doesnt seem to be compatible with the stepper library? Anyone have any easy(ish) ways round this without having to write a whole new library?
you don't need the stepper lib. for this driver. The driver does all the step sequencing for you. You just need to pulse the cloc pin to make the motor step in the direction set by the direction pin.
Yeah your right - couldnt see the wood for the trees...
/*
* Stepper driver routine
*/
int clockPin = 5; // Clock
int dirPin = 6; // Step Direction
int ledPin = 13;
void setup() // run once, when the sketch starts
{
pinMode(clockPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(dirPin, HIGH);
}
void loop() // run over and over again
{
digitalWrite(clockPin, HIGH); // sets the LED on
digitalWrite(ledPin, HIGH);
delayMicroseconds(500); // waits for a second
digitalWrite(clockPin, LOW); // sets the LED off
digitalWrite(ledPin, LOW);
delayMicroseconds(500); // waits for a second
}
Here is some slightly more elegant code if anyone is interested - accelerates the motor to the required speed to prevent stalling - any builds/comments happily recieved
/*
* Stepper driver routine
*/
int clockPin = 5; // Clock
int dirPin = 6; // Step Direction
int startfreq = 1000;
int topfreq = 125;
int test = 0;
void setup() // run once, when the sketch starts
{
pinMode(clockPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(dirPin, HIGH); // set direction
}
void loop() // run over and over again
{
if (test == 0){
for (int i = startfreq; i > topfreq; i--){// accelerate motor from stationary to required speed
digitalWrite(clockPin, HIGH); // need to do this to prevent stalling at higher speeds
delayMicroseconds(i);
digitalWrite(clockPin, LOW);
delayMicroseconds(i);
}
test = 1;
} else {
digitalWrite(clockPin, HIGH);// run motor at required speed after acceleration
delayMicroseconds(topfreq);
digitalWrite(clockPin, LOW);
delayMicroseconds(topfreq);
}
}
I have the STK672-110, SEVERAL of them actually. Looking at your picture Georgew77, It looks like you have a simple circuit devised. Any way you could share it? Im a newbie and still trying to learn, but I think I have been way over-complicating things.