Hi Everyone, I have made my own code for driving a Stepper Motor with the ‘2H Stepper Driver’.
If you would like to try it out for yourself just copy & paste my code into the Arduino IDE.
//really basic code for the ‘MakeBlock 2H Microstep Driver’
//step controller
int dirPin = 2;
int pulPin = 3;
int enblPin = 4;
void setup(){
pinMode(dirPin, OUTPUT);
pinMode(pulPin, OUTPUT);
pinMode(enblPin, OUTPUT);
digitalWrite(enblPin, HIGH);
}
void loop(){
slide(‘L’, 500, 500); //go Left for 500 steps at speed 500, (the lower the number is the faster the motor will go)
delay(2000);
slide(‘R’, 500, 500); //go Right for 500 steps at speed 500
delay(2000);
}
void slide(int dir, int steps, int sspeed){
if (sspeed < 50) sspeed = 10; //keeps the speed above 10
if (dir == ‘L’) digitalWrite(dirPin, HIGH);
else if (dir == ‘R’) digitalWrite(dirPin, LOW);
while (steps > 0){
digitalWrite(pulPin, HIGH);
delayMicroseconds(10);
digitalWrite(pulPin, LOW);
delayMicroseconds(10);
delayMicroseconds(sspeed);
steps–;
}
}