Problems with CNC shield and Arduino

Hi

For the last few weeks I have been trying to get my cnc shield with arduino and stepper motors working, but I’ve had no luck sadly.

I’m using grbl with the universal gcode sender. I’m just trying to get one motor working. The problem is when I tell the motor to go forward with the jog control. At the first click it may go forward, then at the second click backwards etc. This video shows the prolem more clearly: https://youtube.com/shorts/A25_cwJE-5A

I have tried using different stepper motors and drivers(same model) but that doesn’t make a difference.

I have also tried sending test code to the arduino, but then the stepper motor doesn’t move at all.

I am using a 30v power supply connected to an arduino uno with an cnc shield v3, a4988 stepper drivers and a 2A bipolar stepper motor.

Thanks for any help!

I faced problems using that driver board and a 24 volt power supply. It added extra steps. Using 12 volt supply it worked perfect. Don't ask me why.

What current are the drivers set to?

Which drivers do You use?

I am using A4988 drivers and they are set to 2 amps. I don’t have a 12 volt supply to test, but thanks for the tip.

I put some batteries together and got 14 volts. It kind of did the same thing still.

Do You use heatzinks and forced cooling too? That' was needed here.

Are they specified to deliver 2 Amp? Else, the test should fail.

The controlers have heatzinks and they aren’t getting that hot during my tests. No the aren’t specified to deliver two amps, but if they didn’t provide enough amps, wouldn’t the motor then not move, now they move, only in that weird way I described.

You have a point but it’s not a satisfactory test.

Could You put the GRBL aside for a moment and try some conventional DIR/STEP test code to verify the integrity of the hardware?

I did use a GRBL sender for rig bought from eBay, or what it was, but I have no deep knowledge about GRBL.

The problem is that I have only gotten the motor moving using grbl, nothing happens when I try to directly control the motor with code.

This is the code I’m using:

#define X_STEP_PIN 2
#define X_DIR_PIN  5
#define ENABLE_PIN 8

void setup() {
  pinMode(X_STEP_PIN, OUTPUT);
  pinMode(X_DIR_PIN, OUTPUT);
  pinMode(ENABLE_PIN, OUTPUT);

  // Enable stepper drivers (LOW = enabled)
  digitalWrite(ENABLE_PIN, LOW);
}

void loop() {
  // Move X forward
  digitalWrite(X_DIR_PIN, HIGH);
  moveSteps(1000, 800);

  delay(1000);

  // Move X backward
  digitalWrite(X_DIR_PIN, LOW);
  moveSteps(1000, 800);

  delay(1000);
}

void moveSteps(int steps, int speedDelay) {
  for (int i = 0; i < steps; i++) {
    digitalWrite(X_STEP_PIN, HIGH);
    delayMicroseconds(speedDelay);
    digitalWrite(X_STEP_PIN, LOW);
    delayMicroseconds(speedDelay);
  }
}

800 microseconds is too low. Go for some 100 steps per second giving each step 10 000 microsecond period => speedDelay = 5 000.

Okay, now something is actually happening. Now it makes a quite loud screen, like it’s trying to move.

Just to make sure I understood correctly

#define X_STEP_PIN 2
#define X_DIR_PIN  5
#define ENABLE_PIN 8

void setup() {
  pinMode(X_STEP_PIN, OUTPUT);
  pinMode(X_DIR_PIN, OUTPUT);
  pinMode(ENABLE_PIN, OUTPUT);

  // Enable stepper drivers (LOW = enabled)
  digitalWrite(ENABLE_PIN, LOW);
}

void loop() {
  // Move X forward
  digitalWrite(X_DIR_PIN, HIGH);
  moveSteps(5000, 100);

  delay(1000);

  // Move X backward
  digitalWrite(X_DIR_PIN, LOW);
  moveSteps(5000, 100);

  delay(1000);
}

void moveSteps(int steps, int speedDelay) {
  for (int i = 0; i < steps; i++) {
    digitalWrite(X_STEP_PIN, HIGH);
    delayMicroseconds(speedDelay);
    digitalWrite(X_STEP_PIN, LOW);
    delayMicroseconds(speedDelay);
  }
}

That’s to be expected.

You were told to increase the stepDelay parameter but You decreased it from 800 to 100. Use 5000.

Altering the number of steps makes no change.

This usually happens due to incorrect wiring or GRBL settings. Check that the stepper motor coils are wired correctly in pairs, the DIR pin isn’t loose, and the driver microstepping/jumper settings are correct. Also verify the $3 direction invert setting in GRBL and ensure the A4988 driver current (Vref) is set properly.

I checked the motor coil wiring, and it seems weird. First on the stepper motor: The first and third wires are connected, and the second and fourth. But on the stepper driver it says that the coils should be 1b 1a 2a 2b. Then in the manual for the cnc shield it says that the coils should be wired B2 B1 A1 A2. Is this wrong and how should I correct it?

After increasing it to 5000, the motor now does nothing…

Please dig up the datasheet for that motor, its name, something.

What You described sounds worrying.

This is the datasheet for the stepper motor. It confirmes my findings with the multimeter…

Connected to what? Your words are confusing. Please use drawings to explain.

What is Your acting upon reply #14? No reply from You there.

Please the code showing how.

You have verified coil integrity using a DMM in Ohm mode?

Sorry for not being so clear.

I got everything working. The problem was the wires that were in the wrong order for the cnc shield.

Thank you for all the help!

Thanks, great to read.

That simple. Many ways to make mistakes.