Steppermotor Nema17 Homing AccelStepper

Hi!

I (also) have a question about the AccelStepper libry.
I read A LOT about this but can’t find a solution for my problem.

I’m working on an Arduino Bartender. I move a platform over two axes with a steppermotor ( cnc/3d priny likly) and i would like to have moving the platform at startup to a button to set the home position.
I found some code from brainy-bits but can’t make it work that good.
With the stepper libary in arduino it works perfect. (without the home position)

I found out that the steppen motor works best (without shaking at low speeds) at 1/32 steps. But I dont know how to set this up in this code.

My steppermotor does 200steps per revolution * 32steps/step = 3200.
In normal coditions i like to have a speed of 200rpm (work great with other code)
So 3200 * 200 = 640 000

So I filled this in by ‘stepperX.setMaxSpeed’ but the stepper turn very slowly.
I tried other numbers and setting my driver on 1/2 , 1/4, … mode but nothing realy helps.

I think i miss something small but can’t find it. Anyone who can?

my setup:
Nema 17 steppenmotor
STEPSTICK DRV8825 driver.

motor: 123-3d.nl Nema 17, 12V type: SL42S247A
driver: drv8825
code: brainy-bits.com
yt vid code : youtube

Sorry for my bad englisch, i’m Belgian. So if anyone can reply in Dutch, feel free!

#include "AccelStepper.h" 
// Library created by Mike McCauley at http://www.airspayce.com/mikem/arduino/AccelStepper/

// AccelStepper Setup
AccelStepper stepperX(1, 9, 8);   // 1 = Easy Driver interface
                                  // NANO Pin 9 connected to STEP pin of Easy Driver
                                  // NANO Pin 8 connected to DIR pin of Easy Driver

// Define the Pins used
#define home_switch 2 // Pin 2 connected to Home Switch (MicroSwitch)

// Stepper Travel Variables
long TravelX;  // Used to store the X value entered in the Serial Monitor
int move_finished=1;  // Used to check if move is completed
long initial_homing=-1;  // Used to Home Stepper at startup


void setup() {
   Serial.begin(9600);  // Start the Serial monitor with speed of 9600 Bauds
   
   pinMode(home_switch, INPUT_PULLUP);
   
   delay(5);  // Wait for EasyDriver wake up

   //  Set Max Speed and Acceleration of each Steppers at startup for homing
  stepperX.setMaxSpeed(1000);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepperX.setAcceleration(1000);  // Set Acceleration of Stepper


// Start Homing procedure of Stepper Motor at startup

  Serial.print("Stepper is Homing . . . . . . . . . . . ");

  while (digitalRead(home_switch)) {  // Make the Stepper move CCW until the switch is activated   
    stepperX.moveTo(initial_homing);  // Set the position to move to
    initial_homing--;  // Decrease by 1 for next move if needed
    stepperX.run();  // Start moving the stepper
    delay(5);
}

  stepperX.setCurrentPosition(0);  // Set the current position as zero for now
  stepperX.setMaxSpeed(1000.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepperX.setAcceleration(1000.0);  // Set Acceleration of Stepper
  initial_homing=1;

  while (!digitalRead(home_switch)) { // Make the Stepper move CW until the switch is deactivated
    stepperX.moveTo(initial_homing);  
    stepperX.run();
    initial_homing++;
    delay(5);
  }
  
  stepperX.setCurrentPosition(0);
  Serial.println("Homing Completed");
  Serial.println("");
  stepperX.setMaxSpeed(1000.0);      // Set Max Speed of Stepper (Faster for regular movements)
  stepperX.setAcceleration(1000.0);  // Set Acceleration of Stepper

// Print out Instructions on the Serial Monitor at Start
  Serial.println("Enter Travel distance (Positive for CW / Negative for CCW and Zero for back to Home): ");
}

void loop() {

 while (Serial.available()>0)  { // Check if values are available in the Serial Buffer

  move_finished=0;  // Set variable for checking move of the Stepper
  
  TravelX= Serial.parseInt();  // Put numeric value from buffer in TravelX variable
  if (TravelX < 0 || TravelX > 1350) {  // Make sure the position entered is not beyond the HOME or MAX position
    Serial.println("");
    Serial.println("Please enter a value greater than zero and smaller or equal to 1350.....");
    Serial.println("");
  } else {
    Serial.print("Moving stepper into position: ");
    Serial.println(TravelX);
  
  stepperX.moveTo(TravelX);  // Set new moveto position of Stepper
  
  delay(1000);  // Wait 1 seconds before moving the Stepper
  }
  }

  if (TravelX >= 0 && TravelX <= 1350) {

// Check if the Stepper has reached desired position
  if ((stepperX.distanceToGo() != 0)) {
    
    stepperX.run();  // Move Stepper into position
    
  }

// If move is completed display message on Serial Monitor
  if ((move_finished == 0) && (stepperX.distanceToGo() == 0)) {
    Serial.println("COMPLETED!");
    Serial.println("");
     Serial.println("Enter Travel distance (Positive for CW / Negative for CCW and Zero for back to Home): ");
    move_finished=1;  // Reset move variable
  }
  }
}

Your link says that your motor draws 2.5 amps. That is well beyond the capability of a DRV8825. I suggest you get a stepper driver than can handle at least 4 amps to give a bit of headroom.

200 * 32 = 6400

The AccelStepper library may not be able to operate fast enough for your microstepping. 200 RPM = 3.33 rps and at 6400 steps per revolution you would need a step rate of 21120 steps per second.

It is not difficult to write your own stepper code. Have a look at the second example in this Simple Stepper Code. And it is not difficult to write your own acceleration code.

There is nothing wrong with your English, but there is a Dutch section of the Forum if you would prefer it.

...R Stepper Motor Basics

Robin2: Your link says that your motor draws 2.5 amps. That is well beyond the capability of a DRV8825. I suggest you get a stepper driver than can handle at least 4 amps to give a bit of headroom.

200 * 32 = 6400

The AccelStepper library may not be able to operate fast enough for your microstepping. 200 RPM = 3.33 rps and at 6400 steps per revolution you would need a step rate of 21120 steps per second.

It is not difficult to write your own stepper code. Have a look at the second example in this Simple Stepper Code. And it is not difficult to write your own acceleration code.

There is nothing wrong with your English, but there is a Dutch section of the Forum if you would prefer it.

...R Stepper Motor Basics

Hi thans for your answer. I bought the stepper and driver togheter, they use it always like that? The driver can handle 2,5A. I don't use all the power from the stepper so that isn't a problem i guess? (I will measure how many amps the stepper takes)

I don't need 1/32 steps, I now tested (basicstepperdriver libry) with 1/8 steps and this works fine between 50-500RPM. But you think this libary can't handle this? It would be nice if I can use this code with the homing. I'm not pro enough to write it myself.

sambaluniek: (I will measure how many amps the stepper takes)

That is not easy to do - you would probably need an oscilloscope.

Be VERY CAREFUL never to disconnect the wires between the motor and the stepper driver while the driver is powered up. The driver will be instantly destroyed,

...R