Mirroring X axis without GRBL

Hello. I'm trying to use a CNC shield v3 for a robotics application. I would like to write my own code for now, using the AccelStepper library. Unfortunately, I can't seem to get the A axis to mirror the X axis.

My setup is as follows:
Arduino board: Arduino Uno Rev 3
Shield: CNC shield v3
Motors: NEMA17 (rated for 350mA)
Motor controllers: DRV8825 (Vref set to 0.17 V)
Power supply: 12V DC, 6A

The corresponding pins that mirror the A axis and the X axis are jumpered together.
The motor connected to the X axis moves on it's own just fine. The motor connected to the A axis doesn't move at all. I tried running the code below and also running it just with the commands for motorA.

The code I'm running as a test:

#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

#define MOTOR_A_ENABLE_PIN 8
#define MOTOR_A_STEP_PIN 12
#define MOTOR_A_DIR_PIN 13

AccelStepper motorX(1, MOTOR_X_STEP_PIN, MOTOR_X_DIR_PIN);
AccelStepper motorA(1, MOTOR_A_STEP_PIN, MOTOR_A_DIR_PIN);

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

   motorX.setEnablePin(MOTOR_X_ENABLE_PIN);
   motorX.setPinsInverted(false, false, true);
   motorX.setAcceleration(500);
   motorX.setMaxSpeed(2000);
   motorX.setSpeed(1000);
   motorX.enableOutputs();

   motorA.setEnablePin(MOTOR_X_ENABLE_PIN);
   motorA.setPinsInverted(false, false, true);
   motorA.setAcceleration(500);
   motorA.setMaxSpeed(2000);
   motorA.setSpeed(1000);
   motorA.enableOutputs();
}

void loop()
{
   motorX.move(3000);
   motorX.run();
   motorA.move(3000);
   motorA.run();
}

Hi @claim_7z ,

the code you posted cannot be the one that's running your test :wink:

motorA.setEnablePin(MOTOR_Z_ENABLE_PIN);

MOTOR_Z_ENABLE_PIN is not defined (but MOTOR_A_ENABLE_PIN !).

After correcting this your sketch runs on Wokwi: https://wokwi.com/projects/419975573394419713

Wokwi provides a A4988 driver board only but that should not be of importance as your motor X moves and motor A does not ...

What happens if you replace motor X by motor A? Does A work when wired to the DRV8825 board that is connected to pins 2 and 5?

You are correct, sorry! Code has been modified.

   motorA.setEnablePin(MOTOR_X_ENABLE_PIN);
   motorA.setPinsInverted(false, false, true);
   motorA.setAcceleration(500);
   motorA.setMaxSpeed(2000);
   motorA.setSpeed(1000);
   motorA.enableOutputs();

I also switched the motors around just in case something was faulty but the motors work ok. It's when I connect them to the A axis slot that the issues appear.

So both motors are stepping if wired to "X driver" but both don't when wired to the "A driver"?

Yup, that's correct.

Okay ... Now if you replace the "X driver" by the "A driver" do they still work?

If not, there must be something different with your "A driver" board ... :wink:

So I've done all combinations (switched around motors and motor drivers) and it turns out one of the motors had failed. Not entirely sure why - probably something I did while setting up, I'm still getting the hang of this.

The code works now, even managed to move stuff around. Have new problems now, but it's a step forward.

Thank you, @ec2021 !

You are welcome; sorry for the new problems

However, if it was easy what be the fun? :wink:

Good luck and success!
ec2021

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