AccelStepper Again

All
I have read through others and have tried multiple different codes. I can not get the motor to turn. I can get it to lock and unlock, and i can see the code go by the stepper.move but it doesnt turn.

#include <AccelStepper.h>

int motorDirPin = 3;
int motorStepPin = 4;
const byte stepperEnablePin = 5;                  // need the enable pin
const byte button1Pin = 6;                        // button to move platform in
const byte button2Pin = 7;                        // button to move platform in
const byte selector1Pin = 8;                      // Selector up position for lock motors only
const byte selector2Pin = 9;                      // Sekectir right position for moving platform
const byte Estop1Pin = 10;                      // Sekectir right position for moving platform

byte button1State;   // waiting for a change
byte button2State;   // waiting for a change
byte selector1State;   // waiting for a change
byte selector2State;   // waiting for a change
byte Estop1State;   // waiting for a change

long stepsToMove = 16000000000000000000000;

int motorSpeed = 9600;
int motorAccel = 80000;
AccelStepper stepper(1, motorDirPin, motorStepPin);

void setup(){

  pinMode(button1Pin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);
  pinMode(selector1Pin, INPUT_PULLUP);
  pinMode(selector2Pin, INPUT_PULLUP);
  pinMode(Estop1Pin, INPUT_PULLUP);
  pinMode(stepperEnablePin, OUTPUT);
  digitalWrite(stepperEnablePin, HIGH);
  
  stepper.setMaxSpeed(motorSpeed);
  stepper.setAcceleration(motorAccel); 
  Serial.begin(9600);
  Serial.println("ARDUINO ON");
  stepper.moveTo(32000);
}


void selectorSwitch() {

  Estop1State = digitalRead(Estop1Pin);
  selector1State = digitalRead(selector1Pin);
  selector2State = digitalRead(selector2Pin);
  if(selector1State==LOW){                                  //selector in left position (Locked motors only)
    digitalWrite(stepperEnablePin, LOW);
    Serial.println("LOCK MOTORS");
  }
  else if(selector2State==LOW){                             //selector in right position (Move Platform)
    digitalWrite(stepperEnablePin, LOW);
    Serial.println("LOCK MOTORS - MOVE PLATFORM");
  }
  else if(selector1State==HIGH && selector2State==HIGH){    //selector in middle position (OFF)
    digitalWrite(stepperEnablePin, HIGH);
    Serial.println("MOTORS OFF");
    
  }
}

void checkButton() {

  if(selector2State==LOW){
    button1State = digitalRead(button1Pin);
    button2State = digitalRead(button2Pin);
    actionMove ();     // only runs when button is pressed to low
  }
}

void actionMove() {
 
  if (button1State==LOW && button2State==HIGH){
   
 
    Serial.println("                                 MOVING IN");
    stepper.move(stepsToMove);  // or whatever action you want the stepper to do
  }
  
  else if (button2State==LOW && button1State==HIGH){
      Serial.println("                                 MOVING OUT");
    stepper.move(-1*stepsToMove);  // or whatever action you want the stepper to do
    
  }
  else if (button2State==HIGH && button1State==HIGH){
      Serial.println("                                 STOPPING");
    stepper.stop();  //from accelstepper file
  }
  else if (button2State==LOW && button1State==LOW){
      Serial.println("                                  ERROR");
    stepper.stop();  //from accelstepper file
  }
}

void loop(){   // loops between these two actions

  selectorSwitch(); // sets operation to OFF, LOCK, and MOVE
  checkButton ();   // monitors and waits for button press

}

Drive_control.ino (3.33 KB)

What Arduino? What motor? What motor driver? What motor power supply?

Please post links to the above and a clear, hand drawn wiring diagram. Image posting guide

Before trying your own complex code can you get the examples that come with the AccelStepper library to work?

If you have trouble getting the examples to work then try the first example in this Simple Stepper Code which does not need any library and is about as simple as you can get.

Plus what is in Reply #1

…R
Stepper Motor Basics

You are not calling stepper.run() in loop(), so nothing will happen.

The whole design of AccelStepper is based around calling run() method as frequently as possible.

Did you look at any of the examples?

jremington:
What Arduino? What motor? What motor driver? What motor power supply?

Please post links to the above and a clear, hand drawn wiring diagram. Image posting guide

I am using an Arduino Uno, cloudray DM860S, Nema34 1200oz-in. The power supply is a custom 36v i built from 2 Milwaukee batteries.

Robin2:
Before trying your own complex code can you get the examples that come with the AccelStepper library to work?

If you have trouble getting the examples to work then try the first example in this Simple Stepper Code which does not need any library and is about as simple as you can get.

Plus what is in Reply #1

…R
Stepper Motor Basics

Yes i have the motor working without the accelstepper library but we are wanting to add acceleration. If you would like i can post the code without the library as that is what we are running now.

platform drive.jpg

Landonbayger:
Yes i have the motor working without the accelstepper library but we are wanting to add acceleration.

That does not make much sense. There are acceleration examples with the library - after all acceleration is the principal purpose of the library.

...R

Robin2:
That does not make much sense. There are acceleration examples with the library - after all acceleration is the principal purpose of the library.

…R

Robin
I can run the program without the library. Using delays and for statements like the link you posted. I want to use accelstepper library for the acceleration functions.

Landonbayger:
I want to use accelstepper library for the acceleration functions.

I do understand that.

In Reply #2 I asked if you have been able to get the examples that come with the AccelStepper library to work. At this stage it seems as if you have never tried them.

If you have tried one of the examples and it has not worked then post the program and tell us what actually happens when you run it and what should happen.

...R