Step PIN Number for FastAccelStepper on Arduino Mega 2560

Hello,

I am using Arduino Mega 2560 for running Stepper Motors at high speeds using FastAccelStepper library. Everything is working perfectly fine when I use Pin 6 for Steps. But if I use pins 7 or 8, there is no movement on the motor. I am currently running only one motor but need to expand to 2 hence I need one more pin for Step signal.

As per the AVRStepperPins.h file included with the library pins 6,7 and 8 are capable for steps signal.

Can anyone please help suggest what could be the issue and how to use pins 7 and 8 for Steps.

I have attached my working code.

Just to make it clear, the commands will come from VB.net using Serial communication.

Looking forward to your help.

#include <FastAccelStepper.h>

#define PPRX 800
#define STEP_X 6 //6 OK, 
#define DIR_X 22
#define EN_X 23
const char markerGetData = 'G', markerStartMotion = 'M';
const char markerChangePara = 'P', endMarker = '>';

long xCoord, yCoord, stepsX, stepsY;
unsigned long startTime, endTime, duration;

// FastAccelStepperEngine engine;
// FastAccelStepper *stepperX;
FastAccelStepperEngine engine = FastAccelStepperEngine();
FastAccelStepper *stepperX = NULL;


void setup() {
  engine.init();
  stepperX = engine.stepperConnectToPin(STEP_X);
  stepperX->setSpeedInHz(20000); // 20000 the parameter is hz
  stepperX->setAcceleration(20000); // 20000 steps/s^2
  stepperX->setDirectionPin(DIR_X);
  stepperX->setEnablePin(EN_X);
  stepperX->enableOutputs();
  // stepperX->setAutoEnable(true); // Enables only when running
  
  Serial.begin(115200);
}

void loop() {
if (Serial.available() > 0) {
  String input = Serial.readStringUntil('>');

  //To move axes if command received with <M
    if (input.charAt(1) == 'M') {
      moveAxes(input);
    }

    //To Enable/Disable Servo <SE/<SD
    if (input.charAt(1) == 'S') {
      if (input.charAt(2) == 'E') {
        enableAxis();
      } else {
        if (input.charAt(2) == 'D') {
          disableAxis();
        }
      }
    }
  }
}

void moveAxes(String input) { //Should be like <M,10,1,2,3,4,5,E>
  int idx[7];
  int lastidx = -1;
  for (int i = 0; i <7; i++) {
    idx[i] = input.indexOf(',', lastidx + 1);
    lastidx = idx[i];
  }

  xCoord = input.substring(idx[0] + 1, idx[1]).toInt();
  yCoord = input.substring(idx[1] + 1, idx[2]).toInt();
  stepsX = xCoord * PPRX;
  
  startTime = micros(); // Start Time
  // stepperX->moveTo(stepsX); //Absolute
  stepperX->move(stepsX); //Relative
      while (stepperX->isRunning()) { // Wait until movement is complete
  }

  endTime = micros(); // End Time
  duration = endTime - startTime;
  float actualSpeed = abs((float)xCoord / ((float)duration / 1000000.0)*60);
  Serial.println("RPM(" + String(xCoord) + ") : " + String(actualSpeed));
}

void disableAxis(){
  stepperX->disableOutputs();
}
void enableAxis(){
  stepperX->enableOutputs();
}

Im just examining using this library for a project.
I am only using a single axis in a atmega328 but will need pin 9.
Github says 8, or 9 are good.

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