Welcome! Log In Create A New Profile

Advanced

RAMPS1.4 and using AccelStepper or Stepper arduino library

Posted by murf83 
RAMPS1.4 and using AccelStepper or Stepper arduino library
November 14, 2012 12:20PM
Hi,

I'm using the reprap infrastructure for other purposes so I want to explore using the Stepper and AccelStepper libraries available to Arduino to control my stepper motors.

I am confused about which pins do I input as the 4 pins needed in these libraries, seeing as the RAMPS1.4 wiki defines 5 pins, and which order do I place them?

I currently have it set up like this:

#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38
#define X_MIN_PIN 3
#define X_MAX_PIN 2

#include

AccelStepper stepper(AccelStepper::FULL4WIRE, X_STEP_PIN, X_DIR_PIN, X_ENABLE_PIN, X_MIN_PIN);

This setup does work for basic setSpeed codes but does not seem to work properly for any other examples posted on the Arduino websites, so I think its the pin order/assignment I used.

Please let me know if you can clarify this for me.
Re: RAMPS1.4 and using AccelStepper or Stepper arduino library
November 14, 2012 03:43PM
From a brief examination of the library you need to use:

AccelStepper stepper(AccelStepper:grinning smileyRIVER, X_STEP_PIN, X_DIR_PIN);

Notes:
- FULL4WIRE tries to drive a motor DIRECTLY from the Arduino, so you may have fried a stepper driver (not hugely likely, but you never know).
- The library ONLY knows about step and direction pins, and nothing else. You will need to handle the other parts yourself in code.
- You will manually need to set the X_ENABLE_PIN to the correct state to get the motors to move.
- X_MIN_PIN and X_MAX_PIN are the end-stops, so you will need to check them for collisions to detect if you're at the end of your axis, and act appropriately.

Hope this helps.
Re: RAMPS1.4 and using AccelStepper or Stepper arduino library
November 14, 2012 03:59PM
i am starting to dig into these, the below code is what is being used to test all parts of a ramp 1.4 setup. it is slightly diff from a std code being circulated around the web, jus to suit my own testing.

iirc max/min pins are physical limit switch logics

operationally, i think it is possible to use "enable" pins like a emergency stop switch. dir n step are pretty str8 forward, direction of stepper rotation ... n steps :p



#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38
#define X_MIN_PIN 3
#define X_MAX_PIN 2

#define Y_STEP_PIN 60
#define Y_DIR_PIN 61
#define Y_ENABLE_PIN 56
#define Y_MIN_PIN 14
#define Y_MAX_PIN 15

#define Z_STEP_PIN 46
#define Z_DIR_PIN 48
#define Z_ENABLE_PIN 62
#define Z_MIN_PIN 18
#define Z_MAX_PIN 19

#define E_STEP_PIN 26
#define E_DIR_PIN 28
#define E_ENABLE_PIN 24

#define Q_STEP_PIN 36
#define Q_DIR_PIN 34
#define Q_ENABLE_PIN 30

#define SDPOWER -1
#define SDSS 53
#define LED_PIN 13

#define FAN_PIN 9

#define PS_ON_PIN 12
#define KILL_PIN -1

#define HEATER_0_PIN 10
#define HEATER_1_PIN 8
#define TEMP_0_PIN 13 // ANALOG NUMBERING
#define TEMP_1_PIN 14 // ANALOG NUMBERING

void setup() {
pinMode(FAN_PIN , OUTPUT);
pinMode(HEATER_0_PIN , OUTPUT);
pinMode(HEATER_1_PIN , OUTPUT);
pinMode(LED_PIN , OUTPUT);

pinMode(X_STEP_PIN , OUTPUT);
pinMode(X_DIR_PIN , OUTPUT);
pinMode(X_ENABLE_PIN , OUTPUT);

pinMode(Y_STEP_PIN , OUTPUT);
pinMode(Y_DIR_PIN , OUTPUT);
pinMode(Y_ENABLE_PIN , OUTPUT);

pinMode(Z_STEP_PIN , OUTPUT);
pinMode(Z_DIR_PIN , OUTPUT);
pinMode(Z_ENABLE_PIN , OUTPUT);

pinMode(E_STEP_PIN , OUTPUT);
pinMode(E_DIR_PIN , OUTPUT);
pinMode(E_ENABLE_PIN , OUTPUT);

pinMode(Q_STEP_PIN , OUTPUT);
pinMode(Q_DIR_PIN , OUTPUT);
pinMode(Q_ENABLE_PIN , OUTPUT);

digitalWrite(X_ENABLE_PIN , LOW);
digitalWrite(Y_ENABLE_PIN , LOW);
digitalWrite(Z_ENABLE_PIN , LOW);
digitalWrite(E_ENABLE_PIN , LOW);
digitalWrite(Q_ENABLE_PIN , LOW);
}


void loop () {

// if (millis() %1000 <500)
// digitalWrite(LED_PIN, HIGH);
// else
// digitalWrite(LED_PIN, LOW);

// if (millis() %1000 <300) {
// digitalWrite(HEATER_0_PIN, HIGH);
// digitalWrite(HEATER_1_PIN, LOW);
// digitalWrite(FAN_PIN, LOW);
// } else if (millis() %1000 <600) {
// digitalWrite(HEATER_0_PIN, LOW);
// digitalWrite(HEATER_1_PIN, HIGH);
// digitalWrite(FAN_PIN, LOW);
// } else {
// digitalWrite(HEATER_0_PIN, LOW);
// digitalWrite(HEATER_1_PIN, LOW);
// digitalWrite(FAN_PIN, HIGH);
// }



if ( millis() %60000 < 30000) {
digitalWrite(X_DIR_PIN , HIGH);
digitalWrite(Y_DIR_PIN , HIGH);
digitalWrite(Z_DIR_PIN , HIGH);
digitalWrite(E_DIR_PIN , HIGH);
digitalWrite(Q_DIR_PIN , HIGH);
digitalWrite(HEATER_0_PIN, LOW); digitalWrite(FAN_PIN, HIGH); digitalWrite(HEATER_1_PIN, LOW); digitalWrite(LED_PIN, HIGH);

}
else {
digitalWrite(X_DIR_PIN , LOW);
digitalWrite(Y_DIR_PIN , LOW);
digitalWrite(Z_DIR_PIN , LOW);
digitalWrite(E_DIR_PIN , LOW);
digitalWrite(Q_DIR_PIN , LOW);
digitalWrite(HEATER_0_PIN, HIGH); digitalWrite(FAN_PIN, LOW); digitalWrite(HEATER_1_PIN, HIGH); digitalWrite(LED_PIN, LOW);

}

digitalWrite(X_STEP_PIN , LOW);
digitalWrite(Y_STEP_PIN , LOW);
digitalWrite(Z_STEP_PIN , LOW);
digitalWrite(E_STEP_PIN , LOW);
digitalWrite(Q_STEP_PIN , LOW);

delay (150);

digitalWrite(X_STEP_PIN , HIGH);
digitalWrite(Y_STEP_PIN , HIGH);
digitalWrite(Z_STEP_PIN , HIGH);
digitalWrite(E_STEP_PIN , HIGH);
digitalWrite(Q_STEP_PIN , HIGH);

delay (150);

}
Re: RAMPS1.4 and using AccelStepper or Stepper arduino library
November 14, 2012 04:15PM
How would you suggest to manually set the X_ENABLE_PIN to the correct state to get the motors to move?
This is what I have so far. I'm trying to get this example
[www.open.com.au]

to look like:

[www.youtube.com]


#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38
#define X_MIN_PIN 3
#define X_MAX_PIN 2

#include


AccelStepper stepper(AccelStepper:grinning smileyRIVER, X_STEP_PIN, X_DIR_PIN);

void setup()
{
// My way of enabling the enable pin... probably very wrong

pinMode(X_ENABLE_PIN , OUTPUT);
digitalWrite(X_ENABLE_PIN , LOW);
}

void loop()
{

stepper.setMaxSpeed(200);
stepper.setAcceleration(50);
stepper.runToNewPosition(0);

stepper.moveTo(500);
while (stepper.currentPosition() != 300)
stepper.run();
// cause an overshoot as we whiz past 300
stepper.setCurrentPosition(600);
}


Thanks for your help Cefiar!!! Please let me know!
Re: RAMPS1.4 and using AccelStepper or Stepper arduino library
November 14, 2012 04:36PM
anyway i have no idea wads accelstepper ... its a another type of "soft" drive for steppers? i read its steps per second ... i dun quite understand how it is diff from the above way of drive ...
Re: RAMPS1.4 and using AccelStepper or Stepper arduino library
May 19, 2014 04:56PM
Hey there,
I also had a project in the past, where I used the same setup like you.
The solution is pretty simple and I think I know what troubles you.
The Enable pin of the pololus are LOW-active, which means you have to invert the logic of that pin (there exists a function "setPinsInverted" for this purpose).

Below you can find a example, that work perfectly for me.

#include "AccelStepper.h"

#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38

AccelStepper stepper(1, X_STEP_PIN, X_DIR_PIN); // 1 = Driver

void setup() {
stepper.setMaxSpeed(200);
stepper.setAcceleration(50);

stepper.setEnablePin(X_ENABLE_PIN);
stepper.setPinsInverted(false, false, true); //invert logic of enable pin
stepper.enableOutputs();
}

void loop() {
stepper.runToNewPosition(0);

stepper.moveTo(500);
while (stepper.currentPosition() != 300)
stepper.run();

// cause an overshoot as we whiz past 300
stepper.setCurrentPosition(600);
}

I hope you get your steppers to work properly
Re: RAMPS1.4 and using AccelStepper or Stepper arduino library
October 05, 2016 06:07AM
Hi all,

the code from the previous Post is working well.
Can someone tell me why this is not working??

#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38

#include "AccelStepper.h"

AccelStepper stepper(1, X_ENABLE_PIN, X_STEP_PIN, X_DIR_PIN); 

void setup()
{
  pinMode(X_ENABLE_PIN , OUTPUT);
  digitalWrite(X_ENABLE_PIN , LOW);
  stepper.setSpeed(400);
}

void loop()
{  
   stepper.runSpeed();
}

Edited 1 time(s). Last edit at 10/05/2016 06:07AM by shIxx.
Sorry, only registered users may post in this forum.

Click here to login