#include "Stepper.h"
// change the steps variable to the number of steps on your motor
int step= 25600;
// create and attaches a stepper motor
// with 100 steps to pins 0, 1, 2 and 3
Stepper stepper(step, 8, 9, 10, 11);
void setup()
{
// set the speed of the motor to 20 rpms
stepper.setSpeed(1600);
}
void loop()
{
stepper.step(5120);
delay(6000);
}
with Ardino Uno + 8 lead stepper motor (Unipolar connection)+ attached stepper drive
all connection as the code said but when i run the motor the motor just rotate 1/4 Revolution i noted that the max accepted microstepping setup was 6400 steps and when i tried to run the code with 6400*4 to give me one revolution
why 1/4 Revolution???
and what is the best configuration and set up for .and really i need 1/128 micro step to get more accurate.
The standard Stepper library is not suitable for a stepper driver that takes step and direction signals. Try using the AccelStepper library - it is much more comprehensive.
Or just write your own code without using a library.
Thank you so much and i didn't have any background to write a code from the beginning so i just need to learn from already written code and try to modify to learn and know every about the code and real motion effect
i will check your links and try but i just ask about why this code give only 1/4 Revolution ?
is there any special wiring for such as this stepper drivers or what ?
SignTop:
is there any special wiring for such as this stepper drivers or what ?
Of course there is special wiring for a stepper driver. How could there not be? I don't think there is a single electrical item on the planet which does not require special wiring.
If you want help you need to post links to the datasheet for the driver and for your stepper motor.
SignTop:
And may you help me for the correct library have to use
Robin2:
The standard Stepper library is not suitable for a stepper driver that takes step and direction signals. Try using the AccelStepper library - it is much more comprehensive.
Or just write your own code without using a library.
That motor seems to have 8 wires and the stepper driver only has 4 connections. While I am not certain if the two are compatible I suggest that you connect the centre wires of the pairs of coils on each side - Red and Yellow for one side and Black and Orange for the other side. However if the wires colours for your motor are not exactly like the datasheet do not connect anything until we have figured out exactly what connects to what.
Then you will have 4 motor wires to connect to the driver's A+ and A- for one coil and B+ and B- for the other one.
Then connect Pul+, Dir+ and ENA+ to the Arduino 5v pin and the corresponding - pins to the relevant Arduino I/0 pins. I'm not sure if it is actually necessary to connect the ENA- to anything. You need to read the datasheet carefully.
It should then be possible to test the motor with my simple program.
Dir+ , PUL+ to Arduino V5
Dir - to Digital 9 (CW)
PUL- to Digital 8 (CLK)
Then setup the drive for the desired microstepping 128 (25600 steps)
and use the AccelStepper library using the following code:
#include <AccelStepper.h>
// Define a stepper motor 1 for arduino
// direction Digital 9 (CW), pulses Digital 8 (CLK)
AccelStepper stepper(1, 8, 9);
void setup()
{
// Change these to suit your stepper if you want
stepper.setMaxSpeed(3000);
stepper.setAcceleration(3000);
stepper.moveTo(25600);
}
void loop()
{
stepper.run();
}
the result the motor rotate (CW) one revolution very smooth and accurately and matched the micro stepping set up -stepper.moveTo(25600 steps-.but how i can reversed the rotation since the code when i tried the remaining part of the original Loop in the code
if (stepper.distanceToGo() == 0){
stepper.moveTo( -stepper.currentPosition() );
}
the motor make two revolution to go to start point ,
#include <AccelStepper.h>
// Define a stepper motor 1 for arduino
// direction Digital 9 (CW), pulses Digital 8 (CLK)
AccelStepper stepper(1, 8, 9);
char motorPos = 'S'; // S for start F or finish
void setup()
{
// Change these to suit your stepper if you want
stepper.setMaxSpeed(3000);
stepper.setAcceleration(3000);
}
void loop()
{
if (stepper.distanceToGo() == 0) {
if (motorPos == 'S') {
stepper.moveTo(25600);
motorPos = 'F';
}
else {
stepper.moveTo(0);
motorPos = 'S';
}
delay(2000); // pause between movements
}
stepper.run();
}
Waw you are the king of codes
Thank you very much the code work very very very very very good
Thank you Robin2
and if you please any extended explanation with more details to understand the logic for the code and make some changes if i need or recommend good refrance for that if you please
i tried the code with different micro stepping setup it also working very good very accurately
but may i know the best speed set up and how i can avoid the over heating for the motor