as the subject says I'm trying to write a code for a device I made for a school project. I have two, one I'm using this same code with one step motor though a TMC 2208 wire directly and it works perfect.. stepper goes one way, then the other. BUT on my 2nd project same line of code going through a CNC board on an Arduino Uno and the board does not reverse directions.. It has a few times, and then I don't change the code and run another test and it stops switching direction. Any ideas?!? I can not find ANYTHING online about it..here is my code
#include <AccelStepper.h>
AccelStepper stepperx(1, 2, 5);
AccelStepper steppery(1, 3, 6);
AccelStepper stepperz(1, 4, 7);
const int stepX = 2;
const int dirX = 5;
const int stepY = 3;
const int dirY = 6;
const int stepZ = 4;
const int dirZ = 7;
const int enPin = 8;
void setup() {
// Sets the two pins as Outputs
pinMode(stepX,OUTPUT);
pinMode(dirX,OUTPUT);
pinMode(stepY,OUTPUT);
pinMode(dirY,OUTPUT);
pinMode(stepZ,OUTPUT);
pinMode(dirZ,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
stepperx.setMaxSpeed(1000);//set max speed
stepperx.setAcceleration(500);//set acceleration
stepperx.setCurrentPosition(0);//set current position to zero
steppery.setMaxSpeed(1000);//set max speed
steppery.setAcceleration(500);//set acceleration
steppery.setCurrentPosition(0);//set current position to zero
stepperz.setMaxSpeed(1000);//set max speed
stepperz.setAcceleration(500);//set acceleration
stepperz.setCurrentPosition(0);//set current position to zero
stepperz.moveTo(-7200);
stepperz.runToPosition();
delay(1000);
stepperz.move(500);
stepperz.run();
steppery.moveTo(-2125);
steppery.runToPosition();
delay(1000);
stepperx.moveTo(-4500);
stepperx.runToPosition();
delay(1000);
}
void loop(){}
the device is a scoop that will pick up 3 quarters, one motor (stepper_X) will start at a 90 degree vertical position and lower the arm through a worm gear to lower the shovel to the ground, then (stepper_Y) will run a rack n pinion to pull the scoop towards the shovel to collect the quarters, then I need stepper_X to raise slightly so stepper_Z can pull the sled a a hundred or so millimeters and the open the scoop and lower the shovel to release the quarters – Richard Beetle 1 hour ago
stepper_x and stepper_y I have fine.. no issues.. it's stepper_z that's giving me issues, I just tried a "runToNewPosition" line of code.. and the first test at (-7200) and then (-6800) it worked.. then I changed the second value to a greater number to raise it slightly higher.. and now the code is broken again.. it only pushes the shovel down and not up –