Stepper motor doesn't work with CNC shield and DRV8825 driver

Hi everybody,

I am trying to control a stepper motor with my Arduino Uno, with a CNC shield and a DRV8825 stepper driver, but I am having troubles for quite some time now. I have been searching for solutions on the internet and tried several configurations, but it just doesn’t work. Hopefully someone out here can help me out.

My set-up:

  • Arduino Uno. Power supplied by my PC via USB

  • CNC Shield. Power supplied by external power supply; AC TO DC 12V 3A Adapter

  • DRV 8825. VREF set on 0.75 Volts

  • One NEMA 17 bipolar Stepper motor, model 42BYGH47-401A

The code I tried to control the stepper motor with, is from this site Arduino CNC shield control Stepper motor with DRV8825 And is inserted here:

#define EN        8  

//Direction pin
#define X_DIR     5 
#define Y_DIR     6
#define Z_DIR     7

//Step pin
#define X_STP     2
#define Y_STP     3 
#define Z_STP     4 


//DRV8825
int delayTime=30; //Delay between each pause (uS)
int stps=6400;// Steps to move


void step(boolean dir, byte dirPin, byte stepperPin, int steps)

{

  digitalWrite(dirPin, dir);

  delay(100);

  for (int i = 0; i < steps; i++) {

    digitalWrite(stepperPin, HIGH);

    delayMicroseconds(delayTime); 

    digitalWrite(stepperPin, LOW);

    delayMicroseconds(delayTime); 

  }

}

void setup(){

  pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);

  pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);

  pinMode(Z_DIR, OUTPUT); pinMode(Z_STP, OUTPUT);

  pinMode(EN, OUTPUT);

  digitalWrite(EN, LOW);

}

void loop(){

  step(false, X_DIR, X_STP, stps); //X, Clockwise
  step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
  step(false, Z_DIR, Z_STP, stps); //Z, Clockwise

  delay(100);

  step(true, X_DIR, X_STP, stps); //X, Counterclockwise
  step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
  step(true, Z_DIR, Z_STP, stps); //X, Counterclockwise

  delay(100);

}

This did not make the stepper motor rotate, it vibrated and beeped a bit, but that was it. So I tried a few things

  • to increase the VREF, but it didn’t make any difference
  • changed the wiring of the bipolar stepper motor, because according to a wiring image from the internet (see attachments), the order should be the same at the CNC Shield as at the motor, but it was in a different order when received. See the images below (the pictures taken are my stepper motor wiring currently and the image is from the internet)

Again; this made no difference, except that my driver became really hot. Still my motor is not rotating, only vibrating and some beeps can be heard.

Now I don’t know what to do anymore. Hopefully someone can help me out! Also I hope everything is clear enough!

Thanks a lot in advance

img1.png

img2.jpg

img1.png

img2.jpg

Start with a simpler program - see this Simple Stepper Code. You may have to edit it to match the step and direction pins you are using. Also, my simple code does not set the enable pin and you probably need that for the CNC shield.

I note in your program that you have only identified one enable pin. AFAIK each DRV8825 will have its own enable pin.

...R

Thank you Robin2, going to try it right now.
By the way, do you think the wiring that i changed (see the pictures in the first post) is done correctly?

And I am only using one motor, therefore only one DRV8825 has to be enabled.

Unfortunately the code did not work :(. Nothing happens. I also tried this code, which looks simple and straight forward to me (checked the pins as well), but again, nothing…

// AccelStepper - Version: Latest 
#include <AccelStepper.h>
 
// Voor de Arduino Uno + CNC shield V3
#define MOTOR_X_ENABLE_PIN 8
#define MOTOR_X_STEP_PIN 2
#define MOTOR_X_DIR_PIN 5

 
AccelStepper motorX(1, MOTOR_X_STEP_PIN, MOTOR_X_DIR_PIN); 

 
void setup() {
  pinMode(MOTOR_X_ENABLE_PIN, OUTPUT);

  motorX.setEnablePin(MOTOR_X_ENABLE_PIN);
  motorX.setPinsInverted(false, false, true);  
  //motorX.setAcceleration(100);
  //motorX.setMaxSpeed(100);
  motorX.setSpeed(100);
  motorX.enableOutputs();
}
 
void loop() {
  motorX.move(6000);
  motorX.run();
}

storm_chabot:
Unfortunately the code did not work :(. Nothing happens. I also tried this code,

This is what I call the scatter gun approach to debugging - it rarely works and generally just causes more confusion.

Stick to the code in my simple example until you get the motor moving.

Use your multimeter to identify which pair of wires from the motor is for each coil. Then connect the wires for one coil to the A connections for the DRV8825 and connect the wires for the other coil to the B connections.

Be VERY CAREFUL never to connect or disconnect the wires between the motor and the stepper driver while the driver is powered up. The driver will be instantly destroyed.

...R

Expecting a stepper motor to respond to 16000 steps a second from stationary is your mistake,
this is physically impossible as it would require massive torque way beyond the motor's ability to
respond that fast.

Start with AccelStepper library, you need speed ramping and this library is the easiest way
to get started with ramped step rates.

Be much less ambitious about step rate initially. I'd suggest x8 microstepping too, and
perhaps 100 steps a second in your first test code, with acceleration or 1000 steps/s/s or less.

Tuning a stepper involves pushing up the acceleration until it misbehaves, then dialling the acceleration
back 20% or so, then dialing up the max speed to find its limit, then backing that down 20% or
so, all with the actual physical load on the motor.

Unloaded steppers are very resonant and often skip badly at certain speeds if you don't have
a load or microstepping selected.

Robin2:
Use your multimeter to identify which pair of wires from the motor is for each coil. Then connect the wires for one coil to the A connections for the DRV8825 and connect the wires for the other coil to the B connections.

Good one, I'll try to fix the wiring this afternoon.

MarkT:
I'd suggest x8 microstepping too, and
perhaps 100 steps a second in your first test code, with acceleration or 1000 steps/s/s or less.

Microstepping is not possible for me right now, as I haven't received those jumpers with my CNC shield, but I will soon order them as well then. But it should be fixable without microstepping as well, right.
I'm going to have another try today!

Your FRITZING pic shows direct wiring.
The CNC SHIELD is a different animal.

Ensure you are using the correct pins for the stepper driver/s that is installed on the shield.

ballscrewbob:
Your FRITZING pic shows direct wiring.
The CNC SHIELD is a different animal.

Ensure you are using the correct pins for the stepper driver/s that is installed on the shield.

yeah, I knew about that, so fortunately I didn't do that wrong!!
I finally got my stepper motor running!!! Indeed I coded to many steps in the loop, so that was one thing, and I also rearranged the polarities (by measuring the coils with the multimeter), so that definitely was one problem as well!
Now I will try to get good control over the stepper motor haha

Thanks for all the help so far!! Really appreciate it!

One more question, is there any book or guide to learn how to code with CNC shields and DRV8825 for bipolar motors.
I finished a arduino project book, where I learned some coding and building projects and because of my study I understand some coding and the components, but I was wondering, are there any books written about learning to code CNC controlled bipolar motors, because from scratch it is a bit too hard and on the internet I do not find the right sources... does anyone has a good recommendation?

Also, I thought I needed to use the CNC shield as a 12 volt 3 ampere power supply is too much for a breadboard, otherwise I would code the arduino without a CNC shield and only with the drv 8825 on the breadboard, but is that actually true?

It may be Easier to code for the shield once you have identified the correct pinouts.

As you will have noticed the shield has some more components on them that help with the drivers and some other aspects such as microstepping etc.

It also means you could at any time upload GRBL to the Arduino and go almost full CNC.

Generating G-CODE can in a lot of cases be a simpler method of control and speed up overall movements of the X,Y, Z axis as a lot of work is done for you by GRBL in terms of accelerations rapid or slow feeds etc etc.

A more complete description of what you finally want to do with your project would be very beneficial at this point ?

Bob.

Hi Bob,

Thanks for your reply. I want to use my bipolar motor to rotate in one direction and at some point stop and rotate in the other direction. There is a pulley mounted on the shaft of the motor and via pulley wiring a linear rail is connected. I need to move this rail back and forth. Later on I want to use a sensor to make the bipolar motor stop and return in the other direction.
For this purpose, is that G-CODE not too complicated??

G-CODE can be very simple to both learn and use.

Sensors can also be incorporated by way of either limit switches so that a home position is always known.
Or as soft limits so that a temporary point will be used as a position parameter.

Lots depend on how easy or complex you want things to be.

Some pictures may also be a good reference about now.

By way of example this short piece of GCode is all that is needed to traverse a rectangle

; simple code to draw a rectangle 30mm x 30mm
G90 ; absolute positions
G1 X0 Y0 F500
G1 X30 Y0 
G1 X30 Y30
G1 X0 Y30
G1 X0 Y0

...R

Thanks Robin that's a good example.

Note that with Robins example there is no need apart from the feed rate "F500" (how fast from point a to b) to bother with pulses, timing, acceleration, deceleration, etc as that is all taken care of in the background with GRBL.

G-code uses a mostly standardised approach to movements and can be used with offsets and other referential positions such as the G90 command or others.