// NO library
int stepPin[] = {11, 9, 7, 5, 3}; // motor step pins
int dirPin[] = {10, 8, 6, 4, 2}; // motor direction pins
#define stepsPerRevolution 200
#define steps 200
byte counter;
void setup() {
Serial.begin(115200);
randomSeed(analogRead(A0)); // for random pick of motor and direction
for (int i = 0; i < 5; i++) {
pinMode(stepPin[i], OUTPUT);
pinMode(dirPin[i], OUTPUT);
}
}
void loop() {
int dir = random (2); // 0 = CW, 1 = CCW
int mot = random (5); // motor
Serial.print("(M"); Serial.print(mot); // motor
Serial.print(" D"); Serial.print(dir); // direction
Serial.print(") ");
if (counter++ == 7) { // output formatting
counter = 0;
Serial.println();
}
runMotor(mot, dir); // make 'mot' motor run in 'dir' direction
delay(250); // pause between moving motors
}
void runMotor(int motor, bool direction)
{
digitalWrite(dirPin[motor], direction);
// this condition is processor-blocking and will not allow multiple events to occur in parallel
for (int i = 0; i < steps; i++) { // steps per revolutino, typically 200
digitalWrite(stepPin[motor], HIGH); // start of start pulse
delayMicroseconds(2000);
digitalWrite(stepPin[motor], LOW); // end of start pulse
delayMicroseconds(2000);
}
}
/*
+-------------------------+
LOW=DSBL | ENABLE A4988 VMOT | 8-35vdc ---+ 100uf electro cap
| MS1 GND | gnd -------+ pwr spike protect
| MS2 2B | stepper 2B
| MS3 2A | stepper 2A
SLP | RESET 1A | stepper 1A
RST | SLEEP 1B | stepper 1B
stepPin | STEP VDD | 5vdc
stepPin | DIR GND | gnd
+-------------------------+
MS1 MS2 MS3 Step resolution
Low Low Low Full step
High Low Low 1/2 step
Low High Low 1/4 step
High High Low 1/8 step
High High High 1/16 step
SET DRIVER CURRENT LIMIT
1. Power A4988 driver (Vdd, GND)
2. Connect RST to SLP
3. Disconnect motor
4. Apply USB power
5. Calculate current limit: Current Limit = Vref ÷ (8 × Rcs)
6. A current limit of 1A (standard) needs Vref of 540mV
7. Adjust POT while measuring Vref at GND to POT (metal screw)
8. If the motor is making a lot of noise, lower the current limit
*/