Quantcast
Channel: Reprap Forum - RAMPS Electronics
Viewing all articles
Browse latest Browse all 1807

Ramps 1.6 and AccelStepper Library (1 reply)

$
0
0
Dear RepRap forum members,

I would like to run my Nema 17 motors connected to Arduino Mega 2560+Ramps 1.6+Drv8825 with the AccelStepper library.
I have the mechanical connections set properly as I can run my motors by using Marlin.

I want to move the motors without using Marlin, I want to do this directly from AccelStepper.
To this end I have checked the file Marlin\src\pins\ramps\pins_RAMPS.h and got
// Steppers
//
#define X_STEP_PIN                            54
#define X_DIR_PIN                             55
#define X_ENABLE_PIN                          38
#ifndef X_CS_PIN
  #define X_CS_PIN                            53
#endif
Then, I tried to use this and run my x-motor with the following code.
// Include the AccelStepper Library
//#include (AccelStepper.h) //Correct Parenthesis

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

// Define motor interface type
#define MotorInterfaceType 1

// Creates an instance
AccelStepper myStepper(MotorInterfaceType,X_STEP_PIN,X_DIR_PIN);

void setup() {
  // set the maximum speed, acceleration factor,
  // initial speed and the target position
  pinMode(X_ENABLE_PIN,OUTPUT);
  digitalWrite(X_ENABLE_PIN,LOW);

 // myStepper.setCurrent(0);
  
 // myStepper.setMaxSpeed(1000);
  myStepper.setAcceleration(2000);
  myStepper.setSpeed(1000);
  myStepper.moveTo(1600);
  
}

void loop() {
  // Change direction once the motor reaches target position
  if (myStepper.distanceToGo() == 0) 
    myStepper.moveTo(-myStepper.currentPosition());

  // Move the motor one step
  myStepper.run();
}
But, I dont see any movement. What do you think can be the problem?

Thank you.
bkarpuz

Viewing all articles
Browse latest Browse all 1807

Trending Articles