AccelStepper college project

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 –

How stuck on AccelStepper are you? I find the MobaTools stepper libraray easier to use. Steps are generated in background, No need to constantly call a "run" type function. That makes things easier.

Have you set the coil current limits on all the drivers? It is important that you fo so.

Which motor has the TMC driver? Have you tried the TMC2208 driver library so you can set it up with serial port?

What are the remaining drivers and their axis?

I actually got it working last night, I don't have any difficulty with the AccelStepper.h library... my "tank" has the nema 17 and a TMC 2208 and she is perfectly coded... the other project that is stationary.. same project, I couldn't get it working properly through the CNC shield.. went back to basics last night and am running each motor through individual 48 boards.. it's a wiring nightmare.. total rats nest.. but it works now.. and code is functional.

well, "love steppers" IDK what happened.. there glitching now.. acting like a pin or step is wrong.. but I have not changed any of the wiring.. and I can't see anything wrong

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