Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Life Cycle Test


#1

My hardware is the DRV8825 Stepper Motor Driver Carrier, High Current: an A-Star 32U4 Prime SV microSD with LCD and a Stepper Motor - Unipolar -/Bipolor, 200 Steps/Rev, 57x76mm, 8.6v, 1 A/Phase (item numbers 2133 and 3115 1477 respectively).

This application is a Life Cycle test. The entire travel requirement for this stepper motor is to go from:

  1. Start/Home position
  2. Rotate 180 degrees
  3. Stop
  4. Reverse direction
  5. Return to Start/Home

…and repeat this for a minimum of 400,000 times. This will be done for five (5) separate sessions for a total of 2,000,000 cycles. Therefore, each of the five sessions will run continuously at 1.5 sec/cycle for about seven (7) straight days.

Using the bottom part of the following code I have made 60,000 partial cycles (approx. 160 degrees) just to check out the mechanics. Now I need to add a front end loop, that moves in one direction (ccw) until it finds the Home Switch, and then proceed to the last loop that will be repeated for 400,000 cycles.

Since doing the following, I have heard that Pin 1 could possibly be problematic and should use another pin. Pin 5 for example is available. Thank you in advance for your collective collaboration.

   #define HOME_PIN 1
   #define STEP_PIN 2
   #define DIR_PIN 3
   
  bool dirHigh;
   
  void setup()
  {
    dirHigh = true;
    digitalWrite(DIR_PIN, HIGH);
    digitalWrite(STEP_PIN, LOW);
    pinMode(DIR_PIN, OUTPUT);
    pinMode(STEP_PIN, OUTPUT);
    digitalWrite(HOME_PIN, HIGH);
    pinMode(HOME_PIN, INPUT);
  }


  void loop()
{  int HOME_PIN = 1;
  int val = 0;
}
    if(HOME_PIN LOW)
    {
      digitalWrite(dir_Pin, HIGH);
    }
  void loop()
  {
    if(dirHigh)
    {
      dirHigh = false;
      digitalWrite(DIR_PIN, LOW);
    }
    else
    {
      dirHigh = true;
      digitalWrite(DIR_PIN, HIGH);
    }
   
    for(int i = 0; i < 50; i++)
    {
      digitalWrite(STEP_PIN, HIGH);
      delay(250);
      digitalWrite(STEP_PIN, LOW);
      delay(250);
    }
  }

#2

Hello.

After briefly looking at your code, I noticed several different issues with it. I have listed the issues and explanations in descending order starting from the top of your code:

  1. In the first line of your code, you have defined a macro named HOME_PIN as a constant containing the value 1. Then you later defined another variable with the same name as that macro. This cannot be done. #define is a macro definition, which are not variables, and cannot be changed by your program code like variables. (This post on stackoverflow might help better your understanding.) I suggest removing the line int HOME_PIN = 1.

  2. You have two loop functions. This will cause a compilation error, because the compiler will not know which of the two functions to use when calling loop(). You should consider removing one of the void loop() declarations. Also, please double-check that all curly braces and parentheses pair up. See this page about “Curly Braces” in the “Reference” section on the Arduino website for more information.

  3. From this line of code if(HOME_PIN LOW), it looks like you are trying to check if your switch is LOW. First, you will need to read from HOME_PIN using the digitalRead method. Then you will need to use an equal operator (’==’) to check if HOME_PIN’s status is LOW. For example:

if (digitalRead(HOME_PIN) == LOW)

  1. This line digitalWrite(dir_Pin, HIGH) will probably throw an error, since you define DIR_PIN in all caps. The programming language is case sensitive.

You could try calling the function below while stepping your motor to continually check if the switch is active (HIGH):

void stepperHome(){
  // Check if HOME_PIN reads HIGH
  if (digitalRead(HOME_PIN) == HIGH)
  {
     // Toggle direction pin
     if(dirHigh)  // dirHigh is true
     {
        dirHigh = false;
        digitalWrite(DIR_PIN, LOW);
     }
    else  // dirHigh is false
    {
       dirHigh = true;
       digitalWrite(DIR_PIN, HIGH);
    }
  }
}

The stepperHome function will read the status of your switch, and if HOME_PIN is HIGH, toggle the direction pin of your DRV8825.

- Amanda