Using Step/Dir method to drive a stepper motor

Hi, I am new of the Arduino programming, I had purchased a stepper motor which integrated with the controller. I had writing some code and try to driving the motor rotate faster. But I can not realize my purpose, It cost 15 seconds to run a cycle. It has slightly change when I reduce the delay but the difference in 1-2 seconds different.

The code as following shown.

// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 200;


void setup()
{
	// Declare pins as Outputs
	pinMode(stepPin, OUTPUT);
	pinMode(dirPin, OUTPUT);
  Serial.begin(9600);
}
void loop()
{
  int x = 0;
	// Set motor direction clockwise
	digitalWrite(dirPin, HIGH);

	// Spin motor slowly
	for(int x = 0; x < 50 * stepsPerRevolution; x++)
	{
    Serial.println(x);
		digitalWrite(stepPin, HIGH);
		delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(500);
  }
}

Hope anyone who had played with Step/Dir control can give me some suggestion to increase the rotational speed.

Try to remove Serial.print() line too - it take more time for printing than delays itself.

You may have a default microstepping ratio set.

Thank you problem solved

Please mark the thread as "solved"

What did you do to fix the problem?

Tom.... :smiley: :+1: :coffee: :australia:

Hi, Tom. I just delay the Serial.(9600). Do not understand the theory but the code working.

Hi,
Did you try a higher baud rate, 115200?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi, Tom.

I did not try high rate because the datasheet of motor show 9600.

Thank you

Okay, fair enough.

Tom... :smiley: :+1: :coffee: :australia:

What kind of motor are you using that has a baud rate specification?

It's name is PD60-4-1076

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.