Pages: [1]   Go Down
Author Topic: Ardiuno UNO, a4983 driver and stepper motor  (Read 534 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
maybe you can help me
i am using this code:

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:
http://www.sparkfun.com/datasheets/Robotics/SM-42BYG011-25.pdf

what is wrong why cant i get a bigger movment?

itamar


* 4.JPG (635.09 KB, 1632x1224 - viewed 7 times.)
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1204
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1204
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Code:
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.
Logged

Pages: [1]   Go Up
Jump to: