NEMA 34 stepper with DQ860MA driver

Greetings, all

I have to program a test setup using a large NEMA 34 stepper motor and a DQ860MA driver with 8A drive current. DQ860MA is powered by a 10A 24VDC power source.

The driver is set up for 400 pulses/rev and I need to drive the motor at 330rpm. I need to drive the motor a number of revolutions in one direction, then stop for maybe a second, then drive the motor in the opposite direction the same number of revolutions. I don't know how many revolutions to each side yet, and I may have to ramp up and ramp down the motor due to the load it will be moving. I will also have to repeat this cycle a number of times, which I believe I could place in a "For" loop.

The system is connected as follows:

  • Pulse+ and Direction+ are connected to Arduino ground

  • Pulse- is connected to Arduino pin 9

  • Direction- is connected to Arduino pin8

I followed the instructions according to this video: Use Arduino to Control a Large Stepper Motor! Part 1 However, I do not have a potentiometer or a push button, so I don't know how to apply the code in this video to my project.

How do I assign CCW or CW rotation? How do I set the speed?

Thank you in advance

The connections of PUL and DIR looks all wrong to me. Connect the minus to GND and positive to the controller output pin.
A real wiring is always appreciated...

OK, I have looked at my connections and it seems like I made an error in the first post.

  • Pulse+ and Direction+ are connected to Arduino 5V+

Apologies

That's also possible. A negative (GND level) on the controller output will be the active signal.

The DIR signal orders CW or CCW.
To speed control applications DC motors are preferable in my opinion.
However steppers can run at different speeds. Just control the number of pulses per second.
To achieve the higher speeds acceleration must be used. Pulsrate has to be ramped up. Else the stepper will sing but not start.

Here is what I've got so far, as per the video:

void setup() {
  // put your setup code here, to run once:
pinMode(8, OUTPUT); //direction
pinMode(9, OUTPUT); //step
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(9, HIGH);
delayMicroseconds(1000);
digitalWrite(9, LOW);
delayMicroseconds(1000);

}

This gets the motor running at a fixed speed in one direction. So I would need to make it stop for, say, 1000 000 milliseconds, then

digitalWrite(9, HIGH);

before making it turn again using

digitalWrite(9, HIGH);
delayMicroseconds(1000);
digitalWrite(9, LOW);
delayMicroseconds(1000);

}
  1. How do I make it stop?

  2. How do I control the number of steps, e.g. the number of revolutions?

Of course, if you can suggest better code for me to use, I'd be very happy to do so. This seems rather fundamental.

You could use my MobaTools library to control the stepper. You can specify the speed directly in rpm. Ramping up and down the speed can be defined also.
Several examples for driving a stepper motor are included.

The code You have in loop, make it a function, let's name it stepmotor.
Then make loop use a for loop running the desired amount of steps. This for loop calls stepmotor.
When the for loop is finished, the motor stops.
I'm using the phone so no code tags, no easy copy and paste...

Recommend You to take a look at the lib suggested above.

I have run minimumStepper, but it only ramps up in speed then continues running. How do I make it stop? How do I make it ramp down?

Sorry, I am new to all this motor stuff.

It depends on what condition you want to stop the motor at. The 'minimumStepper' is really just a minimum to show that the motor is working.
There are two main modes of operation: let the motor run until an event occurs, such as a button being pressed - then you can stop it with rotate(0). Or you want the motor to make a predefined number of steps or revolutions and then stop it automatically. Then you should use doSteps(stepsToDo), write( anglePosition) or writeSteps(stepPositon) instead of rotate.

intervalStepper is an example to move a stepper back and forth at regular intervals. It is a combination of the conditions above. It stops automatically after a predefined number of steps has been done, and it starts moving again after a predefined time.

  1. I want the motor to accelerate in one direction, say CCW, for a number of pulses, say 200 (motor is 400 Puls/rev) up to 330RPM

  2. I want the motor to continue turning at 330RPM for n revolutions (I don't know yet, but let's say n = 10 rev = 4000 steps).

  3. I want the motor to ramp down from 330RPM to standstill in a number of pulses, maybe the same as the ramp-up.

  4. I want the motor to turn off for a second - no current, no heat (e.g. stepper.disableOutputs(); //disable outputs, so the motor is not getting warm (no current))

  5. I want the motor to ramp up to 330RPM in the opposite direction, say CW, for 200 pulses again.

  6. I want the motor to continue turning at 330RPM in that direction for n revolutions (I don't know yet, but let's say n = 10 rev).

  7. I want the motor to ramp down from 330RPM to standstill in a number of pulses, maybe the same as the ramp-up.

  8. I want the motor to turn off

If I can do this once, I can put these 8 steps in a "for"-loop and control the number of cycles. No push buttons, no limit switches, just counters in the code.

Thanks

I'd suggest looking at the AccelStepper library in the first instance. Try some of the examples.

That's nearly what intervallStepper does, so you could use it as a base to start. Change the constants to your needs at first, and than you can do some final adjustments to the code to support your needs.

I changed the intervall example to your needs. What is missing is a restart after the number of cycles. I don't know how you will restart this ( a button?). As it is now it stops forever.

/* Move a stepper motor in regular intervals
 */
#include <MobaTools.h>

// Adjust pins, steps and time as needed
const byte stepPin = 9;
const byte dirPin  = 8;
const byte enaPin  = 12;
const int stepsPerRev = 400;   // Steps per Revolution ( exammple with 1/4 microsteps )
const int rampLen = 200;
int stepsPerTick = 4000;         // Steps to be executed every cycle
const int intervallTime = 4000; // Steps are executed every 4 seconds
const byte maxCycle = 8;     // count of cycles until stop

byte cycleCounter;

MoToStepper myStepper ( stepsPerRev, STEPDIR );
MoToTimebase intervall;

void setup() {
    myStepper.attach( stepPin, dirPin );
    myStepper.setSpeed( 3300 );  // 330 revolutions / min
    myStepper.setRampLen( rampLen );
    myStepper.attachEnable( enaPin, 20, LOW );  // to disable stepper driver in standstill
    intervall.setBasetime( intervallTime );
}

void loop() {
    if ( intervall.tick() ) {
        myStepper.doSteps( stepsPerTick );
        stepsPerTick = -stepsPerTick;
        if ( ++cycleCounter >= maxCycle ) {
            intervall.stop();   // stop intervalls, no tick is generated anymore
        }
    }
    
    // additional tasks to be done
    // The sketch is not blocked during the waiting time or during step execution.
}
1 Like

That's OK, I'll probably reset it manually every time I increase the number of cycles.

That could all be done in the sketch. A small 7-segment display, up/down button and start button :wink:

Please post the code. No helper knows how You used that library.

'minimumStepper' is an example of the library, that does exactly what PlaneCrazy wrote: it speeds the stepper up and gets it running. It only shows the minimum to get a stepper turning.
It is as usefull as the blink sketch of the IDE :wink:

1 Like
/* ====== minimumStepper =======================================
 *  Bare minimum to get a stepper with step/dir driver turning
 */
#include <MobaTools.h>
// Stepper connections - Please adapt to your own needs.
//const byte stepPin = 6;
//const byte dirPin = 5;
const byte stepPin = 9;
const byte dirPin = 8;

const int stepsPerRev = 200;    // Steps per revolution - may need to be adjusted

MoToStepper stepper1( stepsPerRev, STEPDIR );  // create a stepper instance

void setup() {
  stepper1.attach( stepPin, dirPin );
  stepper1.setSpeed( 300 );              // 30 rev/min (if stepsPerRev is set correctly)
  stepper1.setRampLen( stepsPerRev / 2); // Ramp length is 1/2 revolution
  stepper1.rotate(1);                    // start turning, 1=vorward, -1=backwards                    
}

void loop() {
}

The only thing I changed was the pin numbers

If I can't make my own code, then I will just use this one, thanks. I don't understand all of the parameters and what they do, but I can control the speed, acceleration and number of cycles, so thank you.