Pages: [1]   Go Down
Author Topic: Arduino for A4988 Pololu Stepper Motor Driver code!  (Read 11926 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I really need help. I'm trying to learn how to control a 200 step, 1.8 degree stepper motor with an A4988 Stepper Motor driver and arduino. I'm having trouble finding example codes that work at all, or when they do work and something happens, I have no idea if the motor is spinning the way it is supposed to. All of this is making the learning process very difficult.

If anyone has sample code I would really appreciate it! The more the better so I can learn to have full control on the motor and get it to do what I want for many projects I have planned. If you know of any helpful links, I would also be very grateful for those!

I don't know if it is relavent, or if it changes the code, but I am connecting everything through a RAMPS 1.4 motor control board: http://reprap.org/wiki/RAMPS_1.4

Again, I will be grateful for anything that will help me learn and understand how to code the stepper motor!

Thanks in advance.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31567
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There are only two lines to control. One controls the direction and the other the step. So put the direction high and pulse the other one like the LED blink example. Then repeat putting the direction low.
That is all there is to it.
Logged

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

Do you know how to control the motor by number of steps? all of the stepper libraries don't seem to work properly, or are not written for drivers. The rotation of the motor sputters at lower speeds also, do you know any fix for this?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31567
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't need a libary to control the motor just give it the number of pulses to move required angle. Most motors are 200 steps per revolution.
The delay between the pulses gives you the speed.
If the motor sputters you are doing it too fast, that is the delay is not long enough.
Logged

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

There is a tutorial with code and circuits for driving stepper motors by direction, speed, and angle over at lucidtronix. http://www.lucidtronix.com/tutorials/24
Logged

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

I know this is an old post, but I came here looking for an answer and left without one.
So I decided to come back and post.

Code:

//simple A4988 connection
//jumper reset and sleep together
//connect  VDD to Arduino 3.3v or 5v
//connect  GND to Arduino GND (GND near VDD)
//connect  1A and 1B to stepper coil 1
//connect 2A and 2B to stepper coil 2
//connect VMOT to power source (9v battery + term)
//connect GRD to power source (9v battery - term)


int stp = 13;  //connect pin 13 to step
int dir = 12;  // connect pin 12 to dir
int a = 0;     //  gen counter

void setup()
{               
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);       
}


void loop()
{
  if (a <  200)  //sweep 200 step in dir 1
   {
    a++;
    digitalWrite(stp, HIGH);   
    delay(10);               
    digitalWrite(stp, LOW); 
    delay(10);             
   }
  else
   {
    digitalWrite(dir, HIGH);
    a++;
    digitalWrite(stp, HIGH); 
    delay(10);               
    digitalWrite(stp, LOW); 
    delay(10);
   
    if (a>400)    //sweep 200 in dir 2
     {
      a = 0;
      digitalWrite(dir, LOW);
     }
    }
}


* a4988 diagram.png (74.25 KB, 600x363 - viewed 1701 times.)
Logged

Pages: [1]   Go Up
Jump to: