Step motor direction does not change

Hi. i have a problem that step motor direction does not change.

  • Windows 11

  • Arduino IDE 2.3.2

  • Accelstepper library 1.64

  • LSM-NK174218-1605 step motor

  • SBD-10 motor driver

  • Arduino due

operating mechanism :

void Left_To_Grasping_Position();
x axis : 20mm downward
z axis : 20mm leftward

void Left_Pickup();
x axis : leftward
z axis : upward

void Left_Turn();
x axis : rightward
z axis : downward

void Left_Escape();
x axis : 20mm rightward
z axis : 10mm downward

** problem:
motor direction does not change.

  • in pickup stage, z axis motor continuously move downward.
  • in turn stage, x axis motor continuously move leftward.

what i've tried :

  1. change hardware components( Arduino, Arduino I/O pin position, bread board, connecting cable, motor driver, motor....etc)
  2. adjust value types( ex. int -> long)
  3. adjust DC power supply 10~24V
  4. use pinMode-digitalWrite algorithm( dir . low <-> high)
    instead of using accelstepper library

my code :

#include <AccelStepper.h>
#include <MultiStepper.h>

#define LX_ENA 2  // 3200 10mm
#define LX_PUL 4
#define LX_DIR 3

#define LZ_ENA 5  //
#define LZ_PUL 7
#define LZ_DIR 6

#define INI_XPOSITION -20  //PickUp coord
#define INI_ZPOSITION -20
#define INI_GPOSITION 800  

#define N 40
#define N2 14  //(L_Follow-1)/Weaving_x
#define N3 14  //(R-Follow-1)/Weaving_x
#define PR 40
#define PR2 26
#define L_LSR 39
#define R_LSR 38
#define L_LEAN 6.7
#define R_LEAN 5.5

long lxpPositions[N+1]; //PickUp arrays
long lzpPositions[N+1];
long lgpPositions[N+1];

long lxtPositions[N+1]; //PickUp Turn arrays
long lztPositions[N+1];
long lgtPositions[N+1];

long positions[2];

long Last_lxPosition = 0;
long Last_lzPosition = 0;
long Last_lgPosition = 0;

AccelStepper stepper1(AccelStepper::DRIVER, LX_PUL, LX_DIR); 
AccelStepper stepper2(AccelStepper::DRIVER, LZ_PUL, LZ_DIR); 

MultiStepper steppers;

void Left_To_Grasping_Position();
void Left_Pickup();
void Left_Turn();
void Left_Escape();

void setup() {

  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
//////////////////////////////////////////////
  stepper1.setMaxSpeed(3200);
  stepper2.setMaxSpeed(3200);

///////////////////////////////////////////////
  steppers.addStepper(stepper1);
  steppers.addStepper(stepper2);

///////////////////////////////////////////////
  for (int i=0;i<N+1;i++)   //Generate Left PickUp Path
  {
    lxpPositions[i] = INI_XPOSITION*1600/5 -1*round(1600/5*(PR-PR*cos(2*PI/360*15/N*i)));
    lzpPositions[i] = INI_ZPOSITION*1600/5 +1*round(1600/5*PR*sin(2*PI/360*15/N*i)); 
    lgpPositions[i] = INI_GPOSITION - 1*round(3200/360*15/N*i);
  }  

  for (int i=0;i<N+1;i++)   //Generate Left PickUp Turn Path
  {
    lxtPositions[i] = lxpPositions[N]+1*round(1600/5*(PR2-PR2*cos(2*PI/360*30/N*i)));
    lztPositions[i] = lzpPositions[N]-1*round(1600/5*(PR2)*sin(2*PI/360*30/N*i)); 
    lgtPositions[i] = lgpPositions[N] + 1*round(3200/360*32/N*i);
  }

//////////////////////////////////////////////////
  char s = 'n';

  while(1)
    {
      s=Serial.read();
      if(s=='q')
      {
        break;
      }
    }

  Left_To_Grasping_Position();
  Serial.println("Left_To_Grasping_Position() complete");

  while(1)
    {
      s=Serial.read();
      if(s=='w')
      {
        break;
      }
    }
  delay(500);//
  Left_PickUp();
  Serial.println("Left_PickUp() complete");

  while(1)
  {
    s=Serial.read();
    if(s=='e')
    {
      break;
    }
  }
 delay(500);
  Left_Turn();
  Serial.println("Left_Turn() complete"); 
  while(1)
  {
    s=Serial.read();
    if(s=='r')
    {
      break;
    }
  }
 delay(500);
 Left_Escape();
  Serial.println("Left_Escape() complete");

}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);

}

void Left_To_Grasping_Position(){
  
  positions[0] = 0;
  positions[1] = 0;

  steppers.moveTo(positions);
  steppers.runSpeedToPosition();  

  positions[0] = 0;
  positions[1] = INI_ZPOSITION*1600/5; // -20*1600/5 = -6400, z axis 20mm downward

  steppers.moveTo(positions);
  steppers.runSpeedToPosition();  

  positions[0] = INI_XPOSITION*1600/5; // -6400 ,   x axis 20mm leftward
  positions[1] = INI_ZPOSITION*1600/5; // -6400 

  steppers.moveTo(positions);
  steppers.runSpeedToPosition();  
}

void Left_PickUp(){
  for(int Flag = 0;Flag<N+1;Flag++)
  {
    positions[0] = (lxpPositions[Flag]);
    positions[1] = (lzpPositions[Flag]);

    steppers.moveTo(positions);
    steppers.runSpeedToPosition();
  }
}

void Left_Turn(){
  for(int Flag = 0;Flag<N+1;Flag++)
  {
    positions[0] = (lxtPositions[Flag]);
    positions[1] = (lztPositions[Flag]);

    steppers.moveTo(positions);
    steppers.runSpeedToPosition();
  }
}

void Left_Escape(){
  positions[0] = (lxtPositions[N]+20*1600/5);
  positions[1] = (lztPositions[N]-10*1600/5);

  steppers.moveTo(positions);
  steppers.runSpeedToPosition();

}

operating picture:

after operating, serial output is good.

thank you very much for you guys' support!!

Check the wiring of your steppers coils vs the coil connections on your drivers--if the coils are crossed, the steppers move in one direction:

(Wokwi updated to add switches, wire colors, defaults, and to slow things down)

thank for your reply.

step motor has 4 wire cables :
red (A+), green(A-), yellow(B+), blue(B-)

I checked wiring - bring into contact red and green

  • motor rotate while vibrating,
    => wiring does not matter

Vibrating sounds like an inadequate power problem. Or maybe a too-fast stepping problem.

Does it work properly with an unloaded motor?

This says you adjusted the voltage:

I can't find much information on this driver or stepper:

...but is the current properly adjusted?

For the potential stepping-to-fast problem, instead of:

steppers.runSpeedToPosition();

consider

steppers.runToPosition();

in order to apply acceleration instead of instant start/stop

See
runSpeedToPosition()

vs

runToPosition()

it does not work properly with an unloaded motor.

my motor : https://motorbank.kr/goods/goods_view.php?goodsNo=1000017877
... sorry for non-famous motor.... :smiling_face_with_tear:

i use 24V in constant-voltage mode in DC power supply, with 0.1A.

my current experimental code :

 #include <AccelStepper.h>
 #define LX_ENA 2  
 #define LX_PUL 4
 #define LX_DIR 3
 
 AccelStepper stepper1(AccelStepper::DRIVER, LX_PUL, LX_DIR);   
  
 void setup()
 {  
     stepper1.setMaxSpeed(3200.0);
     stepper1.setAcceleration(100.0);
     stepper1.moveTo(1600);
     
 }
  
 void loop()
 {
     // Change direction at the limits
     if (stepper1.distanceToGo() == 0)
         stepper1.moveTo(-stepper1.currentPosition());
     stepper1.runToPosition();
 
 }

direction does not change even if i use runToPosition with setAcceleration() instead of runSpeedToPosition().

I tried your code, it works fine here. I don't think it is a code problem.

0.1A is not enough. At least 1A, but not more than 2A.

1 Like

The problem was the attached motor driver "SBD-10".
I used TB6600 motor driver instead of using that, it works fine.

but still 0.1A LOL

Where did you set/measure this.

The TB6600 has no setting for 0.1A. How did you set the current at the TB6600?

I just checked. I set current for 1.5A and peak current for 1.7A.
when i turn on the power supply, current is about 0.4A.
And it changes between 0.4~1A.
It works fine but I wonder why is different between set current(1.5A) and measured current(0.4~1A)?




This is the setting for the coil current ( per coil!).

These current controlling stepper drivers ( like the TB6600 ) work similary to a ( short-circuited / current limiting ) step down converter. So the higher the voltage from the PSU, the lower the current from the PSU.

You must consider the power needed by the motor coils to select a proper PSU ( and interpret the measured current correctly )

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