Trouble Shooting - CNC Shield or ME?

Hey All

I have copied a code using an A4988 set up on a bread board and was able to get a result i was after.

I have since put together my CNC shield on a UNO with DRV8825 drivers and have copied the code and just changed the Pin config to suit the pinout on the shield but I have no movement. I have attached the motor to to X axis

can you please assist and tell me if the issues in the code or its hardware related. I'm new to both aspects.

DayRayCncShieldSngleMotor.ino (1.9 KB)

Thank you for any help in advance.

Please post your code in a post instead of attaching it. People that use cell phones can't view your code.

I'm not familiar with motors and drivers so can't advise further.

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

const int stepPin = 2;         //Assign Stepper Motor Steps, to input 12 on Arduino
const int dirPin = 5;          //Assign Stepper Motor Direction, to Pin input 11 on Arduino

void setup() 
{
  pinMode(stepPin, OUTPUT);     //Puts power onto Pin 12 
  pinMode(dirPin, OUTPUT);      //Puts power onto Pin 11
}


void loop()                     // THIS IS THE SECTION OF THE CODE THAT TELLS HOW MANY STEPS TO MOVE
{                               
  stepperFWD();                 //This instructs the Stepper motor to move a defined amount of steps in 'Forward' Direction
  for(int i = 0; i < 200; i++)  // This is the logical counter to see how many steps the motor must move before moving forward
  {
    motorStep();                //Instructs the motor to make a step
    delay(1);                   //gives the motor a split second to finish its step
  }

  stepperREV();                 //This instructs the Stepper motor to move a defined amount of steps in 'Reverse' Direction
  for(int i = 0; i < 200; i++)  // This is the logical counter to see how many steps the motor must move before moving in Reverse
  {
    motorStep();                //Instructs the motor to make a step
    delay(1);                   //gives the motor a split second to finish its step
  }


}

void stepperFWD()
{
  digitalWrite(dirPin, HIGH);   //Turns the Direction pin 11 on High 'On/Forward'
}

void stepperREV()
{
  digitalWrite(dirPin, LOW);    //Turns the Direction pin 11 on High 'On/Forward'
}

void motorStep()                //Controls the time it takes for the Stepper to move one step
{
  digitalWrite(stepPin, HIGH); //Start Step - Turns the Pulse on to the stepper motor to start the step
  delay(100);                  //Time Delay - This is the time delay between the pulse been turned on and then off
  digitalWrite(stepPin, LOW);  //Stop Step - Turns the pulse off to the stepper motor to stop the step
}

1 Like

Well the code should work because of two silly mistakes that cancel each other out. In your loop function you have:-

1mS is far too short a time for a stepping motor to move. But then you have :-1:

and 100mS is far too long to ensure a pulse. What it does in effect is to make the time between steps 101 mS.

So first swap those delays over. Then the delay in your loop function is actually controlling your motor speed. If you have no motor movement then you might want to make this longer.

If there is still no movement but just a vibration you might want to swap over the wires to one of the motor's coils.

The steppers are disabled by default by a pullup on the CNC shield. You need to make pin 8 an output and set it to LOW to enable the motors in software or jumper the EN header to permanently enable the motors.

image

I will try and alter those parameters and see how it goes.

I have tested the motors using UGS so I can confirm the wiring is correct… so I’m assuming it’s somewhere in the code now.

Thanks for the reply.

Do I have to assign pin 8 like this?

const int enable = 8;

Void set up

pinMode (enable, OUTPUT);

Yes, but I would do:

const byte enablePin = 8;  // byte saves 2 bytes of memory
                           // enablePin more descriptive of usage.
void setup()
{
     pinMode(enablePin, OUTPUT);
     digitalWrite(enablePin, LOW); // enable steppers
}

your a legend, thank you very much it is now working i can get all four stepper motors to move, i just need to work out how to make then move in unison... 1 or 2 don't move as much as the others.

Happy to have been of help. :slight_smile:

Are some of the motors missing steps? The MultiStepper library does not use accelerstion so speeds are limited. Motors may miss steps if asked to go too fast. Otherwise, if you want, post the code and a detailed description of what is happening. Maybe we can help.

Have the coil current limits on the stepper drivers been set carefully and properly? Which drivers are younusing?

If your question has been answered to your satisfaction, please mark the thread as solved so that other users that may want to help will not waste time opening the thread to help only to find the question has been answered.

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