Not with the Accelstepper Library (#include <AccelStepper.h>)(see below)
This is a program I use with my RAMPS A4988
//This is an example of how you would control 1 stepper
#include <AccelStepper.h>
byte ledPin = 13;
int motorSpeed = 9680; //maximum steps per second (about 3rps / at 16 microsteps)
int motorAccel = 80000; //steps/second/second to accelerate
int mposition=32000;
int motorDirPin = 7; //digital pin 7
int motorStepPin = 8; //digital pin 8
//set up the accelStepper intance
//the "1" tells it we are using a driver
AccelStepper stepper(1, motorStepPin, motorDirPin);
void setup()
{
stepper.setMaxSpeed(motorSpeed);
stepper.setSpeed(motorSpeed);
stepper.setAcceleration(motorAccel);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
stepper.moveTo(mposition); //move 32000 steps (should be 10 rev)
}
void loop()
{
//if stepper is at desired location
if (stepper.distanceToGo() == 0)
{
//go the other way the same amount of steps
//so if current position is 400 steps out, go position -400
stepper.moveTo(-stepper.currentPosition());
for (int i=0;i<4;i++)
{
digitalWrite(ledPin, !digitalRead(ledPin));
delay(150);
}
}
//these must be called as often as possible to ensure smooth operation
//any delay will cause jerky motion
stepper.run();
}
If you DIDN’T have a dedicated stepper driver like you do, you WOULD need to use digitalWrites, like the example below for the L293 H-BRIDGE. (you do not need this code because you HAVE a stepper driver. This is just shown as an example to show you why using stepper driver iinstead of an H-BRIDGE makes programming easier;
/* Stepper Copal
* -------------
*
* Program to drive a stepper motor coming from a 5'25 disk drive
* according to the documentation I found, this stepper: "[...] motor
* made by Copal Electronics, with 1.8 degrees per step and 96 ohms
* per winding, with center taps brought out to separate leads [...]"
* [http://www.cs.uiowa.edu/~jones/step/example.html]
*
* It is a bipolar stepper motor with 5 wires:
*
* - red: power connector, I have it at 5V and works fine
* - orange and black: coil 1
* - brown and yellow: coil 2
*
* (cleft) 2005 DojoDave for K3
* http://www.0j0.org | http://arduino.berlios.de
*
* @author: David Cuartielles
* @date: 20 Oct. 2005
*/
int ENA=9; //Connect on Arduino, Pin 9
int ENB=10; //Connect on Arduino, Pin 10
int motorPin1 = 2;
int motorPin2 = 3;
int motorPin3 = 5;
int motorPin4 = 6;
int delayTime = 100;
void setup()
{
pinMode(ENA,OUTPUT);
pinMode(ENB,OUTPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
digitalWrite(ENA,HIGH);// Activer moteur A
digitalWrite(ENB,HIGH);// Activer moteur B
}
void loop() {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(delayTime);
}