Problem with using a Mega 2560 instead of a Uno with a CNC Shield

Using a Mega 2560 instead of a Uno with a CNC Shield

I have a robotic arm project using stepper motors

I set it up with 2 steppers and a DRV8825 Arduino shield from Protoneer on a Uno.

I have attached the code I used to test the motors based on AccelStepper.

Works fine .

But I need some analog inputs for sensors (shield covers Uno input pins) so I tried to use a Mega 2560 by just transferring the shield to the Mega and altering the sketch to Mega. Sketch uploads OK but it does not work.

I have read in the forum about pinouts on Uno and Mega not being the same. I have looked at the Forum notes on comparison of the two Arduinos and the color coded diagram of differences but it is not obvious to me that differences are significant for the CNC shield. I have also read the post (about GRBL) about different port mapping but I do not understand ports. I am not of course using GRBL

I previously set up steppers using the Mega 2560 and a breadboard prior to ordering the shield (which is a neater set up) and motors worked OK

My question is can I simply change the sketch to make the shield work on a Mega (not a Uno)? Perhaps by changing the pin number?

#include <AccelStepper.h>

// Define some steppers and the pins the will use
AccelStepper stepper1(1, 3, 6);   //  Stepper Y (Stage 2) 1 = Control by a dedicated driver board (DRV8825) 3 = Arduino pin connected to STEP  6 = Arduino pin connected to DIR
AccelStepper stepper2(1, 2, 5);   // Stepper X (Stage 1)
#define EN        8


void setup()
{  
    stepper1.setMaxSpeed(600.0);
    stepper1.setAcceleration(550.0);
    stepper1.moveTo(100);

    stepper2.setMaxSpeed(600.0);
    stepper2.setAcceleration(500.0);
    stepper2.moveTo(400);
    
    pinMode(EN, OUTPUT);

  digitalWrite(EN, LOW);
   
}

void loop()
{
    // Change direction at the limits
    if (stepper1.distanceToGo() == 0)
  stepper1.moveTo(-stepper1.currentPosition());
    
 if (stepper2.distanceToGo() == 0)
  stepper2.moveTo(-stepper2.currentPosition());
 
    stepper1.run();
   
    stepper2.run();
}

But I need some analog inputs for sensors (shield covers Uno input pins)

Which shield does that without passing the pins through? Piece of crap if that really IS the case.

Sketch uploads OK but it does not work.

It does something. You expect it to do something. You completely failed to describe either thing.

My question is can I simply change the sketch to make the shield work on a Mega

That depends on what didn't work, which pins you are using, and for what.

Thank you for replies

There are spare pins passing through CNC shield but would require soldering. Using MEGA would be easier - plug in

The sketch which I attached tests two steppers to just simultaneously rotate back and forward (to ensure CNC shield / Arduino works)
Works as required using shield plugged into UNO

Swapping MEGA for UNO (and plugging Shield into MEGA) and changing sketch to MEGA results in motors not moving, vibrating, anything. They are of course supposed to operate back and forward

I have used the MEGA previously without the Shield and using breadboard. Using basic sketch (no AccelStepper) to prove both MEGA and motors are not faulty

Pins (Step and direction) are defined in the sketch. Other pins are set out in the Shield documentation - doc file attached)

USING PROTONEER CNC SHIELD ON ARDUINO MEGA.doc (1.08 MB)

If you can't post a link to the shield you are using, you can't expect help with using it.

I am using Protoneer shield V 3.0

with DRV8825 driver modules