Steppermotor with RAMPSV1.4

Hello,

Some students of mine would like to controle steppers with a RAMPS V1.4 that we had in our classroom. I placed a picture below.

But I have some questions about this:

  1. Is is possible to use the RAMPS V1.4 in combination with pushbuttons? If so, how?
  2. I found this code below on this forum, but I can't seem to get it running. Does anyone know what I'm doing wrong?
    (I change pins 8 and 9 to 54 and 55, because A0 = 54 and A1 = 55 on a MEGA)

Note: I used another code from this forum and then the stepper do work, so they are not broken.

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

byte directionPin = 54;
byte stepPin = 55;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps


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); // this line is probably unnecessary
    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); // probably not needed
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
}

void loop() { 
}

With regards,
Hans Vertongen
IMG_5779

Based on your other code that worked, I think you have enable and step switched over.

Edit: actually Direction and step.

What do you mean ?

I think that the step pin is 54.

Here is the Ramps to Mega pin mapping and analog pin to Arduino pin numbers.

#define PIN_A0   (54)
#define PIN_A1   (55)
#define PIN_A2   (56)
#define PIN_A3   (57)
#define PIN_A4   (58)
#define PIN_A5   (59)
#define PIN_A6   (60)
#define PIN_A7   (61)
#define PIN_A8   (62)
#define PIN_A9   (63)
#define PIN_A10  (64)
#define PIN_A11  (65)
#define PIN_A12  (66)
#define PIN_A13  (67)
#define PIN_A14  (68)
#define PIN_A15  (69)

Maybe this will help.

So I changed the code to the one below. But the motor stil doesn't run.

Anyone got other suggestions?

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

byte directionPin = 55;
byte stepPin = 54;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps


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); // this line is probably unnecessary
    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); // probably not needed
    digitalWrite(stepPin, LOW);

    delay(millisbetweenSteps);

    digitalWrite(ledPin, !digitalRead(ledPin));
  }
}

void loop() {
}

It may be that you need to set the x enable pin high too.

Can you verify that the RAMPS code that you were using that worked earlier still does?

@wildbill got it right except the enable on those driver is active LOW.

Add this to your global variables:
const byte xEnable = 38;

Add this to setup():

  pinMode(xEnable, OUTPUT);
  digitalWrite(xEnable, LOW);

Code now works on my Mega/Ramps 1.4 board.

y enable = A2 (56)
z enable = A8 (62)
E0 enable = 24
E1 enable = 30

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

const byte directionPin = 55;
const byte stepPin = 54;
const byte xEnable = 38;
const byte ledPin = 13;

int numberOfSteps = 100;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps

void setup()
{
   Serial.begin(9600);
   Serial.println("Starting StepperTest");
   digitalWrite(ledPin, LOW);

   delay(2000);

   pinMode(directionPin, OUTPUT);
   pinMode(stepPin, OUTPUT);
   pinMode(xEnable, OUTPUT);
   digitalWrite(xEnable, LOW);
   pinMode(ledPin, OUTPUT);

   digitalWrite(directionPin, HIGH);
   for (int n = 0; n < numberOfSteps; n++)
   {
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
      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); // probably not needed
      digitalWrite(stepPin, LOW);

      delay(millisbetweenSteps);

      digitalWrite(ledPin, !digitalRead(ledPin));
   }
}

void loop()
{
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.