- Code: Select all
#include <AFMotor.h>
AF_Stepper motor(48, 2);
int analogPin = 0; // potentiometer wiper (middle terminal)
//connected to analog pin 3
// outside leads to ground and +5V
int val = 0; // variable to store the value read
int prepos = 0;
int pos = 0;
void setup()
{
motor.setSpeed(100);
}
void loop() {
prepos = pos;
val = analogRead(analogPin); // read the input pin
pos = map (val, 0, 1023, 0, 96);
if (pos != prepos){
int diststep = pos - prepos;
if (diststep < 0) {
motor.step(-diststep, BACKWARD, INTERLEAVE);
}
if (diststep > 0) {
motor.step(diststep, FORWARD, INTERLEAVE);
}
}
}
it responds beautifully, but i saw that there was a twitch and a tremble when the stepper is holding position. when i put my finger on the spindle i also noticed that the whole motor is very very hot. the tech specs say that the coil temp is 115º - though being new to steppers i'm not sure if that's a maximum or if its a normal operating temperature. the temperature of the h-bridges on the shield is fine.
i'd like to add in a motor.release() for when the motor is not actually being moved - (it will be panning a suspended camera so releasing the coils won't be a problem). putting the release in the loop just causes unpredicatable behaviour, and outside the loop doesn't seem to do anything.
any tips for how to eliminate the trembles and run my motor a bit cooler?
thanks

