////////////////////////////////
//TWO WIRE STEP/DIR DRIVER BOARD CODE
int Motor1StepPin = 7;
int Motor1DirPin = 8;
//The number of steps required for your stepper to make one revolution. (Don't forget to take into
//account the settings on your driver board. i.e. Microstepping, half stepping etc.)
float steps = 4800;
//Set the travel speed for your stepper motors here. (In Rev/Min)
//Note: There is a limit to how fast or slow this code is able to spin the stepper motors.
//You can try experimenting with the "delayMicroseconds" code if you need different speeds.
int altSpeed=1;
////////////////////////////////
float Motor1Delay, doSteps;
void setup()
{
Serial.begin(9600);
////////////////////////////////
//TWO WIRE STEP/DIR DRIVER BOARD CODE
pinMode(Motor1StepPin, OUTPUT);
pinMode(Motor1DirPin, OUTPUT);
Motor1Delay = ( 1000000 * ( 60 / (steps * altSpeed) ) ) / 2;
////////////////////////////////
pinMode(6, OUTPUT);
// pinMode(7, OUTPUT);
// pinMode(13, OUTPUT);
}
void loop()
{
delay(1000);
digitalWrite(6, LOW);
delay(100);
moveToPosition(1, 0, -steps * 1);
moveToPosition(1, 0, steps * 1);
moveToPosition(1, -steps * 1, 0);
moveToPosition(1, steps * 1, 0);
digitalWrite(6, HIGH);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This code moves the stepper motors
void moveToPosition(int limitSearch, long altsteps, long azsteps){
// Serial.println("altsteps");
// Serial.println(altsteps);
// Serial.println("azsteps");
// Serial.println(azsteps);
////////////////////////////////
//TWO WIRE STEP/DIR DRIVER BOARD CODE
if (abs(altsteps)==altsteps){digitalWrite(Motor1DirPin, HIGH);}else{digitalWrite(Motor1DirPin, LOW);}
for (doSteps=1; doSteps <= abs(altsteps); doSteps++){
digitalWrite(Motor1StepPin, HIGH);
delayMicroseconds(int(Motor1Delay));
digitalWrite(Motor1StepPin, LOW);
delayMicroseconds(int(Motor1Delay));
}
}
Above is the only code I've been able to use with my driver/motor set up. The driver I have is set up in 2 pin (step/dir) mode.
I want to modify the above code to turn the motor around once every HOUR instead of once every minute like it is currently setup to do.
I have experimented with changing delayMicroseconds to Delay and adjusting the values to what I'd think wold be appropriate to turn the motor at 1 revolution per hour but all it does is make strange unpleasant noises.
How can I get my motor to turn one revolution in an hour?
duncan916:
How can I get my motor to turn one revolution in an hour?
There seems to be a lot of complexity in that code for something that ought to be very simple. Ultimately, all you need to do is set the direction pin to the right state and then toggle the step pin at the required frequency. If you want to take 4800 steps in an hour then you need to send a pulse to the step pin every 750ms which means toggling the state every 375ms. There are various ways to code that, but a fairly simple approach which also leaves your sketch free to control other things as well as the stepper motor would look like this:
duncan916:
How can I get my motor to turn one revolution in an hour?
There seems to be a lot of complexity in that code for something that ought to be very simple. Ultimately, all you need to do is set the direction pin to the right state and then toggle the step pin at the required frequency. If you want to take 4800 steps in an hour then you need to send a pulse to the step pin every 750ms which means toggling the state every 375ms. There are various ways to code that, but a fairly simple approach which also leaves your sketch free to control other things as well as the stepper motor would look like this:
void doStepping()
{
static const unsigned long HALF_STEP_INTERVAL = 375; // ms
static unsigned long lastStepTime = 0;
I should have mentioned I have the motor set up in 1/4 stepping mode, which is probably why it took 30 minutes to turn 90º. Unfortunately the only instructions that came with my driver board were how to set it up in 1/4 step mode.
Also, I'm getting an unpleasant speaking noise coming from my stepper between steps. http://youtu.be/EzqkM3plGu0
Hopefully you can hear it on that video.
There's a low purring sound then a high pitched squeak, each about a second long and it's not my gears it's coming from inside the motor. Happens between each step.
The motor also gets a lot hotter than usual. What do I have to change in my code to set things up correctly to control the motor in 1/4 stepping mode? Hopefully that will get rid of the squeaking and cool the motor down. If there's anything else that looks wrong in my code please let me know.
I suggest you look at the documentation for your stepper motor driver to find how to select the stepping mode. Also find out the voltage/current requirements of your motor and see whether it is designed to be powered continuously with the voltage you're using.
duncan916:
The motor also gets a lot hotter than usual. What do I have to change in my code to set things up correctly to control the motor in 1/4 stepping mode? Hopefully that will get rid of the squeaking and cool the motor down. If there's anything else that looks wrong in my code please let me know.
Sounds like your stepper driver is getting hot and shutting down, then restarting. This is consistent with the motor getting hot - it is drawing a lot of current. You either need to put some cooling on the driver, reduce the current limit or use a bigger driver.
The squeaking is probably normal for any microstepping driver, they use PWM to control the current. Often some of this ends up in an audible band. It may be possible to tune out the noise, depends on the stepper driver.