/*NOTES:
Items named "VCC" and GND are the external power suitable for the stepper requirements, + connected to VMOT
The A4988 driver "VCC" pin is connected to the arduino/attiny 5v
*/
#include <AccelStepper.h>
const byte motStep = 11;
const byte motDir = 12;
int mm = 0;
float mmSteps = 200; // Arbitrary number of steps per mm of axis travel - Change to suit
AccelStepper stepper(AccelStepper::DRIVER, motStep, motDir);
void setup() {
pinMode(motStep, OUTPUT);
pinMode(motDir, OUTPUT);
stepper.setMaxSpeed(400.0);
stepper.setAcceleration(200.0);
}
// Single function to move the motor x number of mm (steps per mm * mm requested)
void motMove(int mm) {
if(stepper.distanceToGo() == 0){
delay(50); // Short delay between moves
stepper.moveTo(mm * mmSteps);
}
stepper.run();
}
void loop() {
motMove(2); // Go to 2mm (based on steps/mm defined above)
motMove(0); // Go to 0mm
}
tiny:12
tiny:11
tiny:10
tiny:9
tiny:8
tiny:7
tiny:6
tiny:5
tiny:4
tiny:3
tiny:2
tiny:GND.2
tiny:RESET.2
tiny:0
tiny:1
tiny:13
tiny:3.3V
tiny:AREF
tiny:A0
tiny:A1
tiny:A2
tiny:A3
tiny:A4
tiny:A5
tiny:A6
tiny:A7
tiny:5V
tiny:RESET
tiny:GND.1
tiny:VIN
tiny:12.2
tiny:5V.2
tiny:13.2
tiny:11.2
tiny:RESET.3
tiny:GND.3
drv1:ENABLE
drv1:MS1
drv1:MS2
drv1:MS3
drv1:RESET
drv1:SLEEP
drv1:STEP
drv1:DIR
drv1:GND.1
drv1:VDD
drv1:1B
drv1:1A
drv1:2A
drv1:2B
drv1:GND.2
drv1:VMOT
stepper1:A-
stepper1:A+
stepper1:B+
stepper1:B-
vcc1:VCC
gnd1:GND