bipolar stepper motor control through stepstick a4988 with RAMPS/Arduino Mega

Looking to see if there is basic/general code out there for this, just trying to run 2 bipolar stepper motors

these are the basic parts (without the bipolar steppers): http://www.ebay.com/itm/Geeetech-RAMPS1-4-with-Arduino-compatibe-Mega2560-Pololu-DRV8825-stepper-driver-/281362811013?pt=LH_DefaultDomain_0&hash=item418287c885

Have you studied the stepper examples that come with the Arduino IDE.

This demo code should enable you to get things moving.

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// as posted on Arduino Forum at http://forum.arduino.cc/index.php?topic=208905.0

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 25; // milliseconds


void setup() 
{ 

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
  
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
 
  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  
  delay(3000);
  

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  
}

void loop() 
{ 

}

You must have a suitable power supply that can provide enough volts and amps. Up to the upper limit of the A4988 the higher the voltage the better. The Pololu website has good information about the A4988 drivers.

Your motors must not demand more current than the A4988 can provide.

The maximum current setting on each A4988 must be set correctly.

…R

So i have a 12 & 24 volt supply, the pump needs 24V, but ive ran them with 12 before and am going to use that first.

Also i am using a arduino mega and the ramps microcontroller according to this: http://reprap.org/wiki/RAMPS_1.4

im guessing that pin 9 = 55, 8 = 54 and ena = 38

i'm just not sure, i think with the code i have i am not drawing in the power from my external power supply

can you post your wiring diagram ?

12v power goes to the stepper driver. The driver has the correct setting for enable ? no other jumpers needed for end switches or other stops ?

a typical stepper motor will move if it is fed with power of about 2 volts. but, without much power. the higher voltages offer more power and more speed. if your machine does everything you ask at 12 volts, then great !

and lastly, there should be a reprap group ? if there is, then those guys who deal with this every day should be able to offer you exact solutions.

This code works (disregard the backslashes later in the program):

/*
stepper test sketch for pololu stepper driver board.
 
connect enable pin to arduino pin 38
connect step pin to arduino pin 54
connect direction pin to arduino pin 55
 
The sketch lights led13 and runs the stepper 400 steps in one direction
then it waits one second, then turns off the led13 and runs the stepper 400 steps in the other direction
It waits another second then repeats the 400 one way 400 the other way.
 */
 
int ledPin =  13;    // LED connected to digital pin 13
int enx = 38;
int stepx = 54;
int dirx = 55;
 
// The setup() method runs once, when the sketch starts
 
void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);    
  pinMode(enx, OUTPUT);    
  pinMode(stepx, OUTPUT);    
  pinMode(dirx, OUTPUT);  
  digitalWrite(enx, HIGH);
  digitalWrite(stepx, LOW);
  digitalWrite(dirx, LOW);
 
}
 
// the loop() method runs over and over again,
// as long as the Arduino has power
 
void loop()                    
{
  digitalWrite(enx, LOW);
  digitalWrite(dirx, HIGH);
  digitalWrite(ledPin, HIGH);   // set the LED on
for (int x = 0; x<000; x++){
  digitalWrite(stepx, HIGH);
  delay(1);
  digitalWrite(stepx, LOW);
//  delay(1);
}
 
  delay(0000);     // wait for a second
  //digitalWrite(ledPin, LOW);    // set the LED off
  //digitalWrite(dirx, LOW);
//for (int x = 0; x<400; x++){
  //digitalWrite(stepx, HIGH);
  //delay(1);
  //digitalWrite(stepx, LOW);
//  delay(1);
//}
  //digitalWrite(enx, HIGH);
  //delay(2000);                  // wait for a second
}

But now i want to change the speed (rps or rpm whatever), and im guessing it would be done via the int x = 0; x<400; x++ line??

Can you please edit that

// to use code tags?

Its all explained in the sticky thread(s).

/*
stepper test sketch for pololu stepper driver board.
 
connect enable pin to arduino pin 38
connect step pin to arduino pin 54
connect direction pin to arduino pin 55
 
The sketch lights led13 and runs the stepper 400 steps in one direction
then it waits one second, then turns off the led13 and runs the stepper 400 steps in the other direction
It waits another second then repeats the 400 one way 400 the other way.
 */
 
int ledPin =  13;    // LED connected to digital pin 13
int enx = 38;
int stepx = 54;
int dirx = 55;
 
// The setup() method runs once, when the sketch starts
 
void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);    
  pinMode(enx, OUTPUT);    
  pinMode(stepx, OUTPUT);    
  pinMode(dirx, OUTPUT);  
  digitalWrite(enx, HIGH);
  digitalWrite(stepx, LOW);
  digitalWrite(dirx, LOW);
 
}
 
// the loop() method runs over and over again,
// as long as the Arduino has power
 
void loop()                    
{
  digitalWrite(enx, LOW);
  digitalWrite(dirx, HIGH);
  digitalWrite(ledPin, HIGH);   // set the LED on
for (int x = 0; x<400; x++){                //i dont know how to use this line, if thats how i am suppose to vary the "speed"
  digitalWrite(stepx, HIGH);
  delay(1);
  digitalWrite(stepx, LOW);
delay(1);
}
 
  delay(0000);     // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  digitalWrite(dirx, LOW);
for (int x = 3; x<400; x++){
  digitalWrite(stepx, HIGH);
  delay(1);
  digitalWrite(stepx, LOW);
  delay(1);
}
  digitalWrite(enx, HIGH);
  delay(2000);                  // wait for a second
}

Your code is still not in code tags! Code tags make it much easier for us to read it.

As you say the code works, can we assume you have no further questions?

...R

http://forum.arduino.cc/index.php?topic=148850.0

go about 1/3 of the way down, shortly after the google logo. read about code tags.

then go back to your first thread and add the code tags. repeast for your other posted code.

your code and your posts are running together so we are not sure if you are asking a question or noting your code.

if I am reading your post, you are asking about altering the speed. is this to be a one time change ? or do you want to use a pot to change it or software ?

Still very much a noob at this, but im getting there from the help of this forum mainly! haha

/*
stepper test sketch for pololu stepper driver board.

connect enable pin to arduino pin 38
connect step pin to arduino pin 54
connect direction pin to arduino pin 55

The sketch lights led13 and runs the stepper 400 steps in one direction
then it waits one second, then turns off the led13 and runs the stepper 400 steps in the other direction
It waits another second then repeats the 400 one way 400 the other way.
*/

int ledPin = 13; // LED connected to digital pin 13
int enx = 38;
int stepx = 54;
int dirx = 55;
int Z =1;
int eny = 56;
int stepy = 60;
int diry = 61;
int A = 1;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(enx, OUTPUT);
pinMode(stepx, OUTPUT);
pinMode(dirx, OUTPUT);
pinMode(eny, OUTPUT);
pinMode(stepy, OUTPUT);
pinMode(diry, OUTPUT);
digitalWrite(enx, HIGH);
digitalWrite(stepx, LOW);
digitalWrite(dirx, LOW);
digitalWrite(eny, HIGH);
digitalWrite(stepy, LOW);
digitalWrite(diry, LOW);

}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(enx, LOW);
digitalWrite(eny, LOW);
digitalWrite(dirx, HIGH);
digitalWrite(diry, HIGH);
digitalWrite(ledPin, HIGH); // set the LED on
for (int x = 0; x<100; x++){ //not sure how this line is effecting the entire system, x< any# does not change how long the motors step for me
digitalWrite(stepx, HIGH);
delay(1); //using this and the below delay to control speed, but only a few different combinations between 0-3 run smoothly so i could use help here
digitalWrite(stepx, LOW);
delay(0);
} //no matter what both motors are running in sync, not what i want
for (int b = 0; b<100; b++){
digitalWrite(stepy, HIGH);
delay(1);
digitalWrite(stepy, LOW);
delay(0);
}
}

Why not save yourself a ton of grief, and use the AccelStepper library?

And why not make life easier for us to help you by putting your code inside code tags so it looks like this. The instructions ar in the How to use this forum thread at the top of the section.

Also, why are you starting a separate thread when there is a lot of useful information in your previous Thread. Please ask the Moderator to merge them.

...R

It looks like davidabs persistently will not post his code correctly despite being told several times in several threads. This means on of two things:- 1) He is arrogant and will not comply in which case he does not deserve a reply. 2) He can not understand the instructions about how to post the code and so he will not understand any reply given.

If i new how to make life easier, i would lol trust me haha

/*
stepper test sketch for pololu stepper driver board.
 
connect enable pin to arduino pin 38
connect step pin to arduino pin 54
connect direction pin to arduino pin 55
 
The sketch lights led13 and runs the stepper 400 steps in one direction
then it waits one second, then turns off the led13 and runs the stepper 400 steps in the other direction
It waits another second then repeats the 400 one way 400 the other way.
 */
 
int ledPin =  13;    // LED connected to digital pin 13
int enx = 38;
int stepx = 54;
int dirx = 55;
int Z =1;
int eny = 56;
int stepy = 60;
int diry = 61;
int A = 1;
 
// The setup() method runs once, when the sketch starts
 
void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);    
  pinMode(enx, OUTPUT);    
  pinMode(stepx, OUTPUT);    
  pinMode(dirx, OUTPUT);  
  pinMode(eny, OUTPUT);    
  pinMode(stepy, OUTPUT);    
  pinMode(diry, OUTPUT);
  digitalWrite(enx, HIGH);
  digitalWrite(stepx, LOW);
  digitalWrite(dirx, LOW);
  digitalWrite(eny, HIGH);
  digitalWrite(stepy, LOW);
  digitalWrite(diry, LOW);
 
}
 
// the loop() method runs over and over again,
// as long as the Arduino has power
 
void loop()                    
{
  digitalWrite(enx, LOW);
  digitalWrite(eny, LOW);
  digitalWrite(dirx, HIGH);
  digitalWrite(diry, HIGH);
  digitalWrite(ledPin, HIGH);   // set the LED on
for (int x = 0; x<100; x++){                //not sure how this line is effecting the entire system, x< any# does not change how long the motors step for me
  digitalWrite(stepx, HIGH);
  delay(1);                                           //using this and the below delay to control speed, but only a few different combinations between 0-3 run smoothly so i could use help here
  digitalWrite(stepx, LOW);
  delay(0);
}             //no matter what both motors are running in sync, not what i want
 for (int b = 0; b<100; b++){
  digitalWrite(stepy, HIGH);
  delay(1);
  digitalWrite(stepy, LOW);
  delay(0);
}
}

Thank you for your suggestions though,

I tried learning a little bit about the accelstepper yesterday but got side tracked with other work, i was told by someone i cannot use the stepper library because of my controller setup, does the same apply to the accelstepper?

Sorry gentlemen, didnt understand exactly what you guys meant about the code tags

, does the same apply to the accelstepper

No.

However for full control you need to use the blink without delay technique for two LEDs running at different speeds. This is known as a state machine, see this:- http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

Threads merged.