Serial.print question

Hello everyone ^^

We have an unknown stepper motor, and I’m trying to figure out the length of the pulse so we can know the speed (Step/sec)

So we generated this code:


int dirpin = 2;
int steppin = 3;
//________________________________________

void setup()
{

Serial.begin (9600);
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);

}
//________________________________________

void loop()
{

digitalWrite(dirpin,LOW);

int i;

for (i = 0; i<8000; i++) // 8000 microsteps
{
digitalWrite(steppin, LOW);
digitalWrite(steppin, HIGH);

delayMicroseconds(100);

}

Serial.println ("******Finish *******") ; // we print finish so we know that the program finished from the for loop

delay(5000); // Stop the stepper motor for 5 sec .


The result is :

1
2
.
.
.
7999
******Finish *******


So the question is what is the time between 1 → 2 ??
Or is there some other solution to calculate that? :slight_smile:

Thank you soo much
greetings

The result is :

1
2

How?

Please use code tags when posting code.

So the question is what is the time between 1 -> 2 ??

Two weeks minimum, unless you observed something else.

Or is there some other solution to calculate that?

The micros() function might bear looking into.

On the other hand, it takes next to no time to diddle with a pin. All of your time is in the delayMicroseconds() method, so it doesn't take a degree in rocket surgery to figure out how long a loop iteration takes.

I think this is the answer

delayMicroseconds(100);

as @PaulS has mentioned.

...R
Stepper Motor Basics
Simple Stepper code