Skip to main content
2 of 7
deleted 448 characters in body
Luigi
  • 181
  • 7

Accelstepper: missing syncro in simple test program

I have the following test code, which I'm running on an Arduino Yùn. Only PulCyan and DirCyan are connected to Arduino, all the remaining pins are not connected (except ground).

If I run this program I'd expect to have a 500ms stop when the position of the only motor connected (stepperCyan) reaches 0.

However I see that while running, after few minutes I start to see 2 stops and if I let the program run the stops are more and more distant one to the other.

How is this possible? I'm quite confused.

#include <AccelStepper.h>
 
// Define a stepper and the pins it will use
//Stepper motors

int pulYellow = 30;     //N/A on Yùn
int dirYellow = 31;     //N/A on Yùn
//int enaYellow = 32;   //N/A on Yùn
int pulMagenta = 33;    //N/A on Yùn
int dirMagenta = 34;    //N/A on Yùn
//int enaMagenta = 35;  //N/A on Yùn
int pulCyan = 4;   //36 MEGA
int dirCyan = 8;   //37 MEGA
//int enaCyan = 38;   //N/A on Yùn
AccelStepper stepperMagenta(AccelStepper::DRIVER, pulMagenta, dirMagenta);
AccelStepper stepperYellow(AccelStepper::DRIVER, pulYellow, dirYellow);
AccelStepper stepperCyan(AccelStepper::DRIVER, pulCyan, dirCyan);
void setup()
{  
  // Change these to suit your stepper if you want
  stepperMagenta.setPinsInverted(true, true, true);
  stepperYellow.setPinsInverted(false, false, false);
  stepperCyan.setPinsInverted(true, true, true);
  stepperMagenta.setMinPulseWidth(20);
  stepperYellow.setMinPulseWidth(20);
  stepperCyan.setMinPulseWidth(20);
  stepperMagenta.setMaxSpeed(400);
  stepperMagenta.setAcceleration(200);
  stepperMagenta.moveTo(200);
  stepperYellow.setMaxSpeed(400);
  stepperYellow.setAcceleration(200);
  stepperYellow.moveTo(200);
  stepperCyan.setMaxSpeed(400);
  stepperCyan.setAcceleration(200);
  stepperCyan.moveTo(200);
}
 
void loop()
{
    // If at the end of travel go to the other end
    if (stepperMagenta.distanceToGo() == 0)
      stepperMagenta.moveTo(-stepperMagenta.currentPosition());
    if (stepperYellow.distanceToGo() == 0)
      stepperYellow.moveTo(-stepperYellow.currentPosition());
    if (stepperCyan.distanceToGo() == 0)
      stepperCyan.moveTo(-stepperCyan.currentPosition());
    if (stepperMagenta.currentPosition() == 0) 
    delay(500); // Delay for 500 milliseconds if the position is 0;
    if (stepperYellow.currentPosition() == 0) 
    delay(500); // Delay for 500 milliseconds if the position is 0;
    if (stepperCyan.currentPosition() == 0) 
    delay(500); // Delay for 500 milliseconds if the position is 0;
      
    stepperMagenta.run();
    stepperYellow.run();
    stepperCyan.run();    
}
Luigi
  • 181
  • 7