Bender Machine motor problems

Hi everyone!
So I am building up a bender machine, taking this webpage as a reference:

-http://howtomechatronics.com/projects/arduino-3d-wire-bending-machine/

The changes made were:

  • Changing the frame to a metal one to make the machine more sturdy
  • In consequence of it, we changed the motors to:
  • We changed the Motor drivers to a TB6600 so the Nema 23's and the Nema 17 could have the power needed, because of voltage and current.
  • Power supply was also changed to a 24V one so the motors can have the power required and for the "peak" stage for each of the motors (I already calculated this, if you want more info just pin me)

In the end this is the circuit diagram (made on OneNote, soon it will be fixed)

So the problem here it is that if I connect a motor individually like in this diagram:

With the following code (im using Accelstepper library):

#include <AccelStepper.h>

// Define the stepper motors and the pins the will use
AccelStepper feederStepper(2, 13, 12); // (Type:driver, STEP, DIR)
AccelStepper benderStepper(2, 9, 8);
//AccelStepper zAxisStepper(2, 8, 7);

void setup() {
 Serial.begin(9600);
 Serial.println("Testing the Stepper Motors");

 
 feederStepper.setMaxSpeed(2000);
  
 Serial.println("feeder stepper set max speed");
 feederStepper.setAcceleration(4000);

 Serial.println("feeder stepper set max speed");
 
 //zAxisStepper.setMaxSpeed(100);
 //zAxisStepper.setAcceleration(20);
 //zAxisStepper.moveTo(500);
 
 benderStepper.setMaxSpeed(2000);
 benderStepper.setAcceleration(4000);
}

void loop() {

      delay(500);                       // wait for a second
      Serial.println("first delay passed");

      feederStepper.moveTo(9000);
      feederStepper.run();
      
      benderStepper.moveTo(9000);
      benderStepper.run();
      Serial.println("run command sent");

      delay(500);                       // wait for a second
      Serial.println("second delay passed");

      benderStepper.runToNewPosition(0);
      benderStepper.disableOutputs();
      
      feederStepper.runToNewPosition(0);
      feederStepper.disableOutputs();
      Serial.println("motor stop sent");

      delay(500);                       // wait for a second

      


    //digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  //if (zAxisStepper.distanceToGo() == 0)
    //{
      //zAxisStepper.moveTo(-zAxisStepper.currentPosition());

      //zAxisStepper.run();
       //digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
       //delay(1000);                       // wait for a second
    //}

    //digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  //if (benderStepper.distanceToGo() == 0)
    //{
      //benderStepper.moveTo(-benderStepper.currentPosition());

       //digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
       //delay(1000); 
}

If you observe, the code has some stuff commented, so we can test one motor at a time.

For one motor is ok, but if I try to connect two motors at the same time, it dosent run. But the most interesting behavior is that if you connect two motors, it will work the motor on the lower pins (ex. pin 1 and pin 2) and if you move the pins to other ones or switch the motors from the pins, it will continue with that behavior. Im really out of ideas.

If you need more information about the project, just contact me.

Try this to see if both feeder and bender motors cycle back and forth with a half-second delay at each end-point.

I've never used the AccelStepper library so I have no idea what I'm doing. However, there is promising-looking signalling at both sets of motor pins.

#include <AccelStepper.h>

#define NUM_STEPPERS        2

#define FEEDER              0
#define BENDER              1

#define ST_MOVE1            0
#define ST_MOVE2            1
#define ST_WAITMOVE         2
#define ST_GENERALDELAY     3

// Define the stepper motors and the pins the will use
AccelStepper feederStepper(AccelStepper::FULL2WIRE, 13, 12); // (Type:driver, STEP, DIR)
AccelStepper benderStepper(AccelStepper::FULL2WIRE, 9, 8);
//AccelStepper zAxisStepper(2, 8, 7);

struct StepperStruct
{
    AccelStepper    *stepperChannel;
    uint8_t         stateChannel;
    uint8_t         nextState;
    uint32_t        timeChannel;
    
};

uint32_t
    timeNow;
uint8_t
    stepperIndex = 0;

StepperStruct Steppers[] = 
{
    {
        .stepperChannel = (AccelStepper *)&feederStepper,
        .stateChannel = ST_MOVE1,
        .nextState = 0,
        .timeChannel = 0ul
    },
    {
        .stepperChannel = (AccelStepper *)&benderStepper,
        .stateChannel = ST_MOVE1,
        .nextState = 0,
        .timeChannel = 0ul
    }
    
};

//AccelStepper zAxisStepper(2, 8, 7);

void setup() 
{    
    Serial.begin(115200);
    Serial.println("Testing the Stepper Motors");
    Serial.println("Setting speed and accel - FEEDER");
    Steppers[FEEDER].stepperChannel->setMaxSpeed(2000);
    Steppers[FEEDER].stepperChannel->setAcceleration(4000);
    Steppers[FEEDER].stepperChannel->setCurrentPosition(0);
    
    Serial.println("Setting speed and accel - BENDER");
    Steppers[BENDER].stepperChannel->setMaxSpeed(2000);
    Steppers[BENDER].stepperChannel->setAcceleration(4000);
    Steppers[BENDER].stepperChannel->setCurrentPosition(0);     
    
}//setup

void loop() 
{
    timeNow = millis();
    switch( Steppers[stepperIndex].stateChannel )
    {
        case    ST_MOVE1:
            Serial.print( "Index: " ); Serial.print(stepperIndex); Serial.print( "\t" );
            Serial.println("ST_MOVE1");
            Steppers[stepperIndex].stepperChannel->moveTo(9000);
            Steppers[stepperIndex].nextState = ST_MOVE2;
            Steppers[stepperIndex].stateChannel = ST_WAITMOVE;                
        
        break;

        case    ST_MOVE2:
            Serial.print( "Index: " ); Serial.print(stepperIndex); Serial.print( "\t" );
            Serial.println("ST_MOVE2");
            Steppers[stepperIndex].stepperChannel->moveTo(0);
            Steppers[stepperIndex].nextState = ST_MOVE1;
            Steppers[stepperIndex].stateChannel = ST_WAITMOVE;                            
            
        break;

        case    ST_WAITMOVE:            
            if( Steppers[stepperIndex].stepperChannel->distanceToGo() == 0 )
            {
                Serial.print( "Index: " ); Serial.print(stepperIndex); Serial.print( "\t" );
                Serial.println("ST_WAITMOVE");
                Steppers[stepperIndex].timeChannel = timeNow;
                Steppers[stepperIndex].stateChannel = ST_GENERALDELAY;
                
            }//if
            
        break;

        case    ST_GENERALDELAY:            
            if( (timeNow - Steppers[stepperIndex].timeChannel) >= 500ul )
            {
                Serial.print( "Index: " ); Serial.print(stepperIndex); Serial.print( "\t" );
                Serial.println("ST_GENERALDELAY");
                Steppers[stepperIndex].stateChannel = Steppers[stepperIndex].nextState;
                
            }//if                
                
        break;
                
    }//switch
    
    Steppers[stepperIndex].stepperChannel->run();
    
    stepperIndex++;
    if( stepperIndex == NUM_STEPPERS )
        stepperIndex = 0;
        
}//loop
AccelStepper feederStepper(2, 13, 12); // (Type:driver, STEP, DIR)
AccelStepper benderStepper(2, 9, 8);
//AccelStepper zAxisStepper(2, 8, 7);

You are using step/dir type drivers. The driver type should be DRIVER or 1.

Never uses AccelStepper, but delay (three of them) in loop doesn't sound right.
This stops everything until the delay is finished.
Could be that xxxStepper.run() needs to run for every step (fast loop time). Did when I wrote my own stepper program.
Remove the delays, and use millis() for timing.
See the BlinkWithoutDelay example in the IDE.
Leo..

You have several long delay()s in loop() - that's completely inappropriate for the AccelStepper library's run() function. loop() needs to be able to repeat as fast as possible and at least 3 times faster than the fastest step frequency,

If you want to do one move at a time maybe runToPosition() would be more appropriate - but that would mean only one motor moving at a time.

...R

Wawa:
Could be that xxxStepper.run() needs to run for every step (fast loop time).

Quite sure that is the case.
AccelStepper is also limited to some 4,000 steps per second, which I take is for all steppers combined - the two steppers set to a speed of 2,000 are between them maxing out the library's ability, leaving little to no processor cycles left to do anything else.

Thank you all that replied to this post, soon I will make up the changes and update you guys if your recommendations worked.

So I wanted to make a small comment,
groundFungus, the Drivers are in 2 because even though I tried to put them in 1, it didn't do anything, literally, they didn't make any sound or reaction to the code, so as an experiment I change it to 2, and then it worked. According to the Accelstepper library on 2, it's when it's on fullwire so:

2 wire stepper, 2 motor pins required

So I guess that maybe I have a problem with the driver? That's actually something that I was contemplating that it's making the issue on the machine.

Drivers that take step and direction signals must use the DRIVER option in AccelStepper - that is, the value 1

...R

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