Most of the code was cobbled together to get the Nema 23 steppers working the way I want.
I am using the Serial Monitor to start the code that runs three stepper motors.
When I hit 'D' the motors run their routine. If I hit 'enter' on my keyboard a second time Lstepper and Rstepper have to reverse 8,000 to get back to position zero.
I know why it does that but I haven't found an alternative to 'positions'....so I'd like help with an alternative, or code that will set the three stepper positions to zero.
The second thing I need help with is in releasing power to the steppers so they aren't using any power.
Nothing is being held so free-wheeling is a good thing.
I've been trying a few different things but just have not found anything that works.
Regarding releasing the steppers, I can get the motors to NOT move when placed in the first location here.
example;
AccelStepper Gstepper = AccelStepper(motorInterfaceType, GuideEna, GuideStep, GuideDir);
GuideEna in that first spot keeps the motors from turning but they still make sound.
See the whole code below;
/* Example sketch to control a stepper motor with TB6560 stepper motor driver, AccelStepper library and Arduino: acceleration and deceleration. More info: https://www.makerguides.com */
// Include the AccelStepper library:
#include <AccelStepper.h>
#include <MultiStepper.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define GuideEna 7
#define GuideDir 6
#define GuideStep 5
#define LEna 10
#define LDir 9
#define LStep 8
#define REna 4
#define RDir 3
#define RStep 2
#define motorInterfaceType 1
int length = 1800; //steps per revolution
// Create a new instance of the AccelStepper class:
AccelStepper Gstepper = AccelStepper(motorInterfaceType, GuideStep, GuideDir, GuideEna);
AccelStepper Lstepper = AccelStepper(motorInterfaceType, LStep, LDir, LEna);
AccelStepper Rstepper = AccelStepper(motorInterfaceType, RStep, RDir, REna);
MultiStepper steppers;
void setup() {
Serial.begin(9600);
// Set the maximum speed and acceleration:
Gstepper.setMaxSpeed(1000);
Gstepper.setAcceleration(10000);
Lstepper.setMaxSpeed(10000);
Lstepper.setAcceleration(10000);
Rstepper.setMaxSpeed(10000);
Rstepper.setAcceleration(10000);
steppers.addStepper(Lstepper);
steppers.addStepper(Rstepper);
steppers.addStepper(Gstepper);
digitalWrite(LEna, HIGH);
}
void loop() {
// Set the target position:
char rx_byte;
int i;
if (Serial.available() >1) {
rx_byte = Serial.read();
if (rx_byte == 'D')
delay(10);
for (i = 0; i<2; i++) //SET TO NUMBER OF FIGURE EIGHTS
{
Gstepper.moveTo(200);
Gstepper.runToPosition();
Lstepper.moveTo(800);
Lstepper.runToPosition();
Rstepper.moveTo(-800);
Rstepper.runToPosition();
Gstepper.moveTo(-200);
Gstepper.runToPosition();
Lstepper.moveTo(-30); //Ends pointing forward. Larger negative points the tip lower
Lstepper.runToPosition();
Rstepper.moveTo(30); //Ends pointing forward. Larger positive points the tip lower
Rstepper.runToPosition();
}
delay(10);
Gstepper.moveTo(100);
Gstepper.runToPosition();
// MOVING BOTH MOTORS AT THE SAME TIME
long positions[3]; // Array of desired stepper positions
positions[0] = 8000;
positions[1] = -8000;
positions[2] = -100; //As rope wraps around bundle this is the target before it jumps back to starting point
steppers.moveTo(positions);
steppers.runSpeedToPosition(); // Blocks until all are in position
delay(10);
//Resets back to zero location
// positions[0] = 8000;
// positions[1] = -8000;
positions[2] = 0;
steppers.moveTo(positions);
steppers.runSpeedToPosition(); // Blocks until all are in position
// delay(10);
}
}
This looks like bloatware but that's ok.....I know there are better way's to write this but it's outside of my comprehension.
Any help on the two topics would be much appreciated.