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();
}