Questions on the stepper_oneRevolution example

Hello, I am learning how to use Arduino to control stepper motor. From the comment in the example, it states that the motor is attached to digital pins 8-11 of the Arduino. Then, it defined:

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

Does that mean in this example, no motor driver is involved? If I use a motor controller with Digital port 8 of UNO assigned to DIR+ and port 9 assigned to PUL+, what should I do to make this example works?

Please read and use How to get the best out of this forum - Using Arduino / IDE 1.x - Arduino Forum

Code, schematics, links please....

No, absolutely not.

1 Like

Here is the example code copied and pasted directly from Arduino IDE.

/*
 Stepper Motor Control - one revolution

 This program drives a unipolar or bipolar stepper motor.
 The motor is attached to digital pins 8 - 11 of the Arduino.

 The motor should revolve one revolution in one direction, then
 one revolution in the other direction.


 Created 11 Mar. 2007
 Modified 30 Nov. 2009
 by Tom Igoe

 */

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}


Thanks! Please post the schematics.

No, this is to drive the stepper via a double H-bridge. It can also be used to drive a unipolar stepper like the widely used 28BYJ-48 geared stepper. But in this case you must interchange the middle pins ( 8,10,9,11 )
But most modern steppers cannot be driven via a simple H-bridge.

Best would be to use another library ( like AccelStepper, MobaTools or others). These libraries also contain examples. The stepper.h isn't designed to operate step/dir drivers.

1 Like

Which motor? Post datasheet or part number.

Thank you. I found the documentation of AccelStepper difficult to read. Is there any good guides or tutorials? I could not find suitable ones.

Speaking of AccelStepper, what is the maximum acceptable value to put in setMaxSpeed and setAcceleration?

https://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html#abee8d466229b87accba33d6ec929c18f

Maybe the MobaTools Dokumentation is better :innocent: :wink: ( This pdf will also be installed in your library folder if you install MobaTools ).

On an UNO AccelStepper cannot create steps faster then 5000 steps/sec for one stepper ( if there is nothing else in the loop ).

1 Like

Thank you. I will read through the MobaTools manual. Basically I just want the Arduino to generate a constant linear speed until a button is pressed. Nothing fancy.

How about the latest UNO R4 Wifi and Giga R1 Wifi? What is the maximum steps/sec per stepper for these two Arduino?

I don't have any experience with the Giga, and I don't have experience with Accelstepper on R4. But it will be considerable faster than on UNO.
MobaTools can create up to 12000 steps/sec on a R4 (for up to 6 steppers). Because the steps are created by timer interrupts, this is independent from other tasks in loop() ( As long as interrupts are not disabled ).

1 Like

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