Hi everyone. I am having an issue driving a stepper motor and I was looking for some help.
The motor I am using is here
This is the driver that I am using
I am trying to move the motor at various speeds with an analog signal, and I am using the AccelStepper library AccelStepper: AccelStepper library for Arduino . This is because in the future I want to use two motors at once. I can drive the motor quick with step speeds over a couple hundred steps per second. But when I slow down the motor just stalls and makes more of a clicking sound. Right now I do not have micro stepping engaged, so each signal of the drive should be a step to the motor.
Here is my code. This is make a custom syringe pump.
#include <AccelStepper.h>
AccelStepper stepper(1, 3, 2); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
int microStepResolution = 1;
int numStepsPerMl = 1500 * microStepResolution; //8 revolutions for 1 ml in 10 ml syringe. 200 steps per rev
float flowRate = 8; // ml/min Don't go over 40 ml/min. We want
int stepSpeed = flowRate * (numStepsPerMl / 60);
const int trialPin = 12;
const int driverSleep = 11;
int stepPosition = 0;
int trialState = 0;
int analogInPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int outputValue = 0;
void setup() {
// put your setup code here, to run once:
stepper.setMaxSpeed(800);
stepper.setSpeed(stepSpeed);
pinMode(trialPin, INPUT);
pinMode(driverSleep, OUTPUT);
pinMode(13, OUTPUT);
stepper.setCurrentPosition(0);
}
void loop() {
// put your main code here, to run repeatedly:
trialState = digitalRead(trialPin);
stepPosition = stepper.currentPosition();
if (trialState == HIGH) {
digitalWrite(13, HIGH);
digitalWrite(driverSleep, HIGH);
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 2 * stepSpeed);
stepper.setSpeed(outputValue);
stepper.runSpeed();
}
else if (trialState == LOW && stepPosition != 0)
{
digitalWrite(13, LOW);
digitalWrite(driverSleep, HIGH);
stepper.moveTo(0);
stepper.setSpeed(800);
stepper.runSpeedToPosition();
}
else
{
digitalWrite(driverSleep, LOW);
}
}
Thank you tremendously for any help. I can't quite tell if this is an issue with the Accelstepper library, my coding, the driver, or the motor.
FB