Steeper motor control code

I trying to control a stepper motor (NEMA23) with Arduino UNO and a DB6600 driver.

I've saw several tutorials about how to do that... the only one I succeed in having some control, the code is this:

int pinPulse = 2;
int pinDirection = 3;

void setup() {
  pinMode(pinPulse, OUTPUT);
  pinMode(pinDirection, OUTPUT);
  digitalWrite(pinDirection, HIGH);
}

void loop() {
  digitalWrite(pinPulse, LOW);
  digitalWrite(pinPulse, HIGH);
  delayMicroseconds(2500);
}

However, in most tutorials, there is also delay after the digitalWrite LOW

void loop() {
  digitalWrite(pinPulse, LOW);
  delayMicroseconds(2500);
  digitalWrite(pinPulse, HIGH);
  delayMicroseconds(2500);
}

and if I use this later code, the motor only makes noise and don't spin. Why?

I wonder if the motor has some problem, or I doing something wrong!

I'd tried the some coding with the stepper library, but again, got only 'noises'!

All switches of the DB6600 are 'on'.

You need to set the switches properly.

Look at the motor data sheet. It should list the coil current limit, Use the DIP switches to a smaller number so that the motor and driver will not run too hot.

Use the DIP switches to set in some microstepping, say 4. Microstepping will allow the motor to run smoother and mitigate resonance affects,

You should use a stepper-motor-library.

The code you have posted is the most rudimentary and simple code to to eaxch detail new from scratch.
Well for learning what happends inside a motor-stepper-library this is good.

If you are interested in making it work without knowing the details use a stepper-motor-library

I recommend using the MobaTools-Library for the following reasons:

The MobaTools-library creates the step-pulses in the "background" based on a timer-interrupt.
The motor-position in relation to a zero-point is always updated internally and you can use absolute positions or a number of steps for relative moving.

The library takes care which way round (clockwise or counter-clockwise) the motor has to turn to reach this position.
It includes acceleration and deceleration.

Once you have understood the "commands" writing code becomes much easier

You can intall the MobaTools from the library-manager of the Arduino-IDE

So the most rudimentary code for simply make the motor rotate with a certain rpm looks like this

/* ====== 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 = 2;
const byte dirPin = 3;

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() {
}

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