Hi,
I'm working on a camera mount that tracks the stars so that I can take long exposures. I am using a NEMA17 stepper motor driven by an Arduino Nano and an A4988 driver. I'm using the driver in quarter step mode and it is driven by a 12v adapter capable of delivering 2 amps. The nominal current for the motor is 1.2 amps.
I've gotten the motor to work fairly quickly without any problems. But I have noticed that when I stop the motor movement either by breaking the loop or resetting the board, the current measured trough one of the four wires stays locked at values that differ after each rotation. This is accompanied by a whining noise that is different after every time I stop the rotation.
I've experimented with current limits in full step mode between 0.4 and 0.8 amps but the problem persists.
Some forum posts state that this driver "holds" the motor at a certain position when stationary. Could this be the cause of the noise/current?
My code:
//Set drive gear number of teeth
const int driveTeeth = 38;
//Set intermediate gear number of teeth
const int intermediateTeeth = 18;
//Set motor gear number of teeth
const int motorTeeth = 17;
//Set stepper motor steps per revolution
const int motorStepsrev = 200;
//Required drive gear speed (RPM, default 1)
////----Change this value during calibration---------------------------------------////
////----Calculate using formula: Radius (in inches) = RPM / ((2Π/ 1436) * TPI)----////
float driveSpeed = 1;
//Calculation of required intermediate gear speed [RPM]
float intermediateSpeed = (38 / 18) * 1;
//Calculation of required motor gear speed [RPM]
float motorSpeedRPM = (intermediateTeeth / motorTeeth) * intermediateSpeed;
float motorSpeedStepsSec = 7.45098039;
//Required motSpeed in milliseconds/step
float motSpeed = ((1/motorSpeedStepsSec)/4)*1000;
int currentPos = 0;
//stepper motor outputs
#define dirPin 3
#define stepPin 2
#define motorInterfaceType 1
// button inputs
#define buttonRun 11
#define buttonReturn 5
// create debounce objects
Bounce runIn = Bounce(); //Run tracker toggle
Bounce returnIn= Bounce(); //Return to start toggle
void setup() {
//Set pinModes
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
//Attach input pins/buttons to internal pullup and set debounce time
runIn.attach(buttonRun, INPUT_PULLUP);
runIn.interval(100);
returnIn.attach(buttonReturn, INPUT_PULLUP);
returnIn.interval(100);
//Print results from speed calculations in serial
Serial.begin(9600);
Serial.println("Calculated intermediate speed [RPM] at:");
Serial.println(intermediateSpeed);
Serial.println("Calculated motor speed [RPM] at:");
Serial.println(motorSpeedRPM);
Serial.println("Calculated motor speed [Steps/s] at:");
Serial.println(motorSpeedStepsSec);
Serial.println("Calculated motor milliseconds/s");
Serial.println(motSpeed, 7);
digitalWrite(stepPin, LOW);
digitalWrite(dirPin, LOW);
}
void loop() {
//Update button debounce status
runIn.update();
returnIn.update();
if(runIn.fell()){
currentPos = 0;
Serial.println("RUN PRESSED"); //Used for debugging
while(currentPos < 3200)
{
currentPos = currentPos + 1;
Serial.println(currentPos);
// advance motor one step at calculated steptime
digitalWrite(stepPin, HIGH);
delay(motSpeed);
digitalWrite(stepPin, LOW);
delay(motSpeed);
}
}
}