Look at the motor data sheet. It should list the coil current limit, Use the DIP switches to a smaller number so that the motor and driver will not run too hot.
Use the DIP switches to set in some microstepping, say 4. Microstepping will allow the motor to run smoother and mitigate resonance affects,
The code you have posted is the most rudimentary and simple code to to eaxch detail new from scratch.
Well for learning what happends inside a motor-stepper-library this is good.
If you are interested in making it work without knowing the details use a stepper-motor-library
I recommend using the MobaTools-Library for the following reasons:
The MobaTools-library creates the step-pulses in the "background" based on a timer-interrupt.
The motor-position in relation to a zero-point is always updated internally and you can use absolute positions or a number of steps for relative moving.
The library takes care which way round (clockwise or counter-clockwise) the motor has to turn to reach this position.
It includes acceleration and deceleration.
Once you have understood the "commands" writing code becomes much easier
You can intall the MobaTools from the library-manager of the Arduino-IDE
So the most rudimentary code for simply make the motor rotate with a certain rpm looks like this
/* ====== minimumStepper =======================================
* Bare minimum to get a stepper with step/dir driver turning
*/
#include <MobaTools.h>
// Stepper connections - Please adapt to your own needs.
const byte stepPin = 2;
const byte dirPin = 3;
const int stepsPerRev = 200; // Steps per revolution - may need to be adjusted
MoToStepper stepper1( stepsPerRev, STEPDIR ); // create a stepper instance
void setup() {
stepper1.attach( stepPin, dirPin );
stepper1.setSpeed( 300 ); // 30 rev/min (if stepsPerRev is set correctly)
stepper1.setRampLen( stepsPerRev / 2); // Ramp length is 1/2 revolution
stepper1.rotate(1); // start turning, 1=vorward, -1=backwards
}
void loop() {
}