Hi
maybe you can help me
i am using this code:
// Stepper
#include <Stepper.h>
// steps value is 360 / degree angle of motor
#define STEPS 200
// create a object on pins 6 and 7
Stepper stepper(STEPS, 6,7);
void setup()
{
}
void loop()
{
///// Turn the stepper 200 steps with a 1 sec delay between steps at 60rpm
/// then reverse the direction and do 50 steps at 20rpm with a 1sec delay between steps
stepper.setSpeed(20);
stepper.step(200);
//delay(1000);
//stepper.setSpeed(20);
//stepper.step(-50);
//delay(1000);
}
and the only movment i am getting is like a of millimeter (left & right)
i am using 12V battery and this motor:
what is wrong why cant i get a bigger movment?
itamar
The stepper library does not know that you have an a4983. It is toggling the pins alternatly, thinking there is a motor. As one of the pins is the "dir" pin on the chip, your motor just jiggles to and fro.
Control your pins directly. Leave the pin going to the "dir" high and then alternate the the "step" pin up and down with a delay.
(I'm sure someone has made a library, but it is just a 3 line program to control the motor through the A4983.)
Hey Msquare, Thanks for the quick reply!
Sorry for the questions, I'm a total newb at this and trying to get a project off the ground…I can't seem to find a library to define the A4983 and am failing miserably when trying to build it, can you point me in the right direction? How do I go about controlling my pins directly and speccing the delay? Again, sorry for the bother and really appreciate your help!
Looking at the photo you might have the motor wires in the wrong order. I am using the same stepper and driver and the order that works for me is blue-yellow-green-red. Make sure the power is off before changing the motor wiring.
Swapping the 4-wire is a good try, assuming the chip is controlled correctly. It is enough to just swap any (adjacent) pair of motor wires.
Code suggestion (your actual pinnumbers and values may vary)
const int Mdir=6 ;
const int Mstep=7 ;
:
pinMode(Mdir,OUTPUT) ;
pinMode(Mstep,OUTPUT) ;
:
digitalWrite(Mdir,HIGH) ; // LOW to go the other way
for (int j=0; j<200; j++) {
digitalWrite(Mstep,HIGH) ;
delayMicroseconds(12) ; // Step occurs on rising edge
digitalWrite(MStep,LOW);
delay(3) ; // more delay-> slower rotation speed.
}
Lastly, if you use delay() you are blocking, that is, the Arduino wont be able to do other things, like watching if a button is pushed, whilst turning the motor. That is also how the stepper-library works. If that is good enough, fine. Otherwise you have to start reading about "avoid using delay". Here and here and lots more from other contributors.