Stepper Motor Setup Trouble Shooting CNC Shield V3.0 - AccelStepper.h

ups ! my fault. setMinPulseWidth is a - you could call it a "member"-function of accelstepper.
So the correct syntax is:

stepper_y.setMinPulseWidth(200);

For convenience the complete code

#include <AccelStepper.h>

#define step_x 2
#define step_y 3
#define step_z 4

#define dir_x 5
#define dir_y 6
#define dir_z 7

int led = 13;

// AccelStepper stepper_x(1, step_x, dir_x);
AccelStepper stepper_y(1, step_y, dir_y);
// AccelStepper stepper_z(1, step_z, dir_z);


void setup()
{
  pinMode(led, OUTPUT);

  for (int n = 0; n < 5; n++)
  {
    digitalWrite(led, HIGH);
    delay(500);
    digitalWrite(led, LOW);
    delay(500);
  }
  stepper_y.setMinPulseWidth(200);

  stepper_y.setMaxSpeed(1000);
  stepper_y.setSpeed(100);
}

void loop()
{
  stepper_y.runSpeed();
  delayMicroseconds(800);
  // delay(1);  // alternativey use a 1 millisecond delay
}

If you like to do more investigations on the accelStepper-problem
You could change the compile-log to maximum detail-output
like described in this tutorial.

Activating maximum details does help even in case that the code compiles

The thing I am most interested in is what version of the AccelStepper-library do you use?

best regards Stefan

1 Like

Version 1.64

I finally took a Arduino-clone board and uploaded this code

#include <AccelStepper.h>

#define step_x 2
#define step_y 3
#define step_z 4

#define dir_x 5
#define dir_y 6
#define dir_z 7

int led = 13;

// AccelStepper stepper_x(1, step_x, dir_x);
AccelStepper stepper_y(1, step_y, dir_y);
// AccelStepper stepper_z(1, step_z, dir_z);


void setup() {
  pinMode(led, OUTPUT);

  for (int n = 0; n < 5; n++)
  {
    digitalWrite(led, HIGH);
    delay(500);
    digitalWrite(led, LOW);
    delay(500);
  }
  //stepper_y.setMinPulseWidth(200);

  stepper_y.setMaxSpeed(1000);
  stepper_y.setSpeed(100);
}

void loop() {
  stepper_y.runSpeed();
  //delayMicroseconds(800);
  // delay(1);  // alternativey use a 1 millisecond delay
}

which is essentially your initial code except for added LED blinking in setup
and some comments but the same active code

On my Arduino-Clone board that has a QFP-package-chip instead of a DIL-housing

On this board your code runs and runs
Maybe there is a problem through code-optimisation
The compiler can be adjusted to different levels of code-optimisations that might cause this problem if your loop has just this single function-call
stepper_y.runSpeed();

Your Arduino uno seems to be a QFP-chip clone too.

1 Like

I looked up my storage and found an Arduino Uno-board with blue color that looks very similar to yours.

Having the same color does NOT mean it is the same manufacturer.
I tested the code from post # 23 too.
And this code runs well.

Another idea - but this is just a wild guessing - which could mean nothing
is to use a different IO-pin than IO-pin 3 for the step-pulses

So what results do you get if you run this code-version that uses IO-pin 4

Switch off all power-supplies !
Then disconnect the stepper-motor-driver from the Arduino

What happens if you run the code on the Arduino-Uno with everything disconnected
and just measure the frequency on IO-pin 4

#include <AccelStepper.h>

#define step_y 4

#define dir_y 6

int led = 13;

AccelStepper stepper_y(1, step_y, dir_y);


void setup() {
  pinMode(led, OUTPUT);

  for (int n = 0; n < 5; n++) {
    digitalWrite(led, HIGH);
    delay(500);
    digitalWrite(led, LOW);
    delay(500);
  }
  //stepper_y.setMinPulseWidth(200);

  stepper_y.setMaxSpeed(1000);
  stepper_y.setSpeed(100);
}

void loop() {
  stepper_y.runSpeed();
  //delayMicroseconds(800);
  // delay(1);  // alternativey use a 1 millisecond delay
}

best regards Stefan

What happens if you use this code.

Step-pin is pin 4
and this code has an additional heartbeat-blinker that makes the onboard LED blink at 2 Hz.

Does the LED continue to blink even if you do not measure the 100 Hz step-pulse-frequency with your digital multimeter?

On my Arduino Uno the code runs and step-pulses are continually created

#include <AccelStepper.h>

#define step_y 4

#define dir_y 6

int led = 13;

AccelStepper stepper_y(1, step_y, dir_y);


void setup() {
  pinMode(led, OUTPUT);

  for (int n = 0; n < 5; n++) {
    digitalWrite(led, HIGH);
    delay(500);
    digitalWrite(led, LOW);
    delay(500);
  }
  //stepper_y.setMinPulseWidth(200);

  stepper_y.setMaxSpeed(1000);
  stepper_y.setSpeed(100);
}

void loop() {
  stepper_y.runSpeed();
  BlinkHeartBeatLED(led,250);
  //delayMicroseconds(800);
  // delay(1);  // alternativey use a 1 millisecond delay
}


// easy to use helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();
  if ( currentMillis - startOfPeriod >= TimePeriod ) {
    // more time than TimePeriod has elapsed since last time if-condition was true
    startOfPeriod = currentMillis; // a new period starts right here so set new starttime
    return true;
  }
  else return false;            // actual TimePeriod is NOT yet over
}

unsigned long MyTestTimer = 0;                   // Timer-variables MUST be of type unsigned long
const byte    OnBoard_LED = 2;


void BlinkHeartBeatLED(int IO_Pin, int BlinkPeriod) {
  static unsigned long MyBlinkTimer;
  pinMode(IO_Pin, OUTPUT);
  
  if ( TimePeriodIsOver(MyBlinkTimer,BlinkPeriod) ) {
    digitalWrite(IO_Pin,!digitalRead(IO_Pin) ); 
  }
}

best regards Stefan

Disconnected everything leaving the bare Uno board. Tested it using both IO 3 & 4 (one at a time) as the step output.

They created the 100Hz signal for no more than 10 seconds then dropped to 0Hz.

Interesting! I ran the heartbeat-blinker variant for half an hour and it didn't fall over. Produced the 100Hz signal the entire time. I set up a tripod to watch it :wink:

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