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:
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?
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);
}
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.
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 ).