Trouble Running Stepper: DRV8825 and Teensy 3.2

Hello all!

I am a student in the U.S., and I’ve been trying to run my stepper motor using a Teensy 3.2 and the Pololu DRV8825 driver board. My stepper motor is from Nanotec, and I’m using a gearbox with a 25.2:1 gear ratio:

https://us.nanotec.com/products/2450-sc2818s1504-b/

My code is as follows:

// Initialize variables
const int ledPin = 13;
const int sleepReset = 15;
const int stepDrive = 9;
const int counter = 10;
const int dirDrive = 8;

int dutyCycle = 120;
int stepperDirection = 1;
volatile int stepsTaken = 0;

void setup() {
  pinMode(ledPin, OUTPUT);

  // Pull sleepReset high
  pinMode(sleepReset, OUTPUT);
  digitalWrite(sleepReset, HIGH);

  // Setup stepper settings
  pinMode(dirDrive, OUTPUT);
  pinMode(stepDrive, OUTPUT);
  pinMode(counter, INPUT_PULLUP);
  attachInterrupt(counter, stepInterrupt, RISING);

  // Setup Serial
  Serial.begin(9600);
  while (!Serial);
}

void loop() {
  digitalWrite(ledPin, HIGH);   // set the LED on
  Serial.println("Enter any letter key to start code");
  String entry = "";
  
  while (entry.length() < 2){
    if (Serial.available()){
      char inChar = Serial.read();
      entry += inChar;
      }
  }
  Serial.println("Running script now.");

  int steps_current = 0;
  int steps = 2000;
  int steps_vel = 600;

  // Set direction
  digitalWrite(dirDrive, HIGH);
  stepperDirection = 1;

  analogWriteFrequency(stepDrive, steps_vel);
  analogWrite(stepDrive, dutyCycle);

  while (steps_current <= steps){
      Serial.println(steps_current);
      steps_current += stepsTaken;
    } 

  analogWrite(stepDrive, 0);

}

void stepInterrupt(){
  stepsTaken += stepperDirection;
}

In short, I’m just trying to get the motor to move a certain number of steps. I’ve made sure that the current limit is set correctly (VREF = 0.75V for a 1.5A current limit), but my current script causes the motor to only move a small bit. If I remove the while loop and just have the motor run continuously, my motor is very jittery and vibrates a lot (and it moves pretty slow). Currently, M0, M1, and M2 are all disconnected. Additionally, the sleep and reset pins are set to HIGH via pin 15. A, A, B, and B\ wires on my stepper motor are attached to A1, A2, B1, and B2, respectively.

Does anyone have any insight on what I might be doing wrong or what I need to change? Please let me know if you need any more information. Thank you!

I actually managed to get it working using the AccelStepper library, so no worries with coding.

However, I did notice that my stepper motor still vibrates a decent amount, so I’ll see if I can reduce the noise and vibrations via microstepping. Additionally, the stepper motor and the driver get pretty hot within 1-2 minutes, even though I set the current limit to 1.5A (0.75 VREF). Does anyone have any suggestions on why this is the case? According to the data sheet for the driver board, I shouldn’t need any external cooling…

Hello.

I am glad switching to the library got it working better for you. I suspect you might have been seeing problems with your original code because you were just using analogWrite() to generate the step signal, which would just be using the Teensy’s default frequency that might be too fast for your motor (or need some ramping).

It is normal for stepper motors to make a whining noise when they are energized. As far as the vibrations, in general microstepping can help get smoother motion. You could also try increasing your operating voltage (as long as you stay below the driver’s maximum). It is hard to have any more specific advice than that without seeing it and knowing more about your system. It is normal for the driver to get hot when operating near it’s upper limits; you could try lowering the current limit slightly if you are concerned about it.

If you are still having problems after trying those adjustments, could you post more details such as your operating voltage, power supply, and updated code? Also, could you post (or link to) a video showing the problem?

Brandon

Thanks for the response! I smoothed out the motion with some microstepping and faster velocities, and the vibration is a lot less noticeable now. As for the temperature of the driver, I think I’ll just lower the current limit–I think that’s all I can do besides slapping a heat sink on top of the chip. Would you have any other suggestions to reduce the heat?

In my experience, forced airflow seems to help with the heat build-up more than just a heat sink. However, as I mentioned before, it is normal for the driver to get hot (e.g. hot enough to burn you). As long as you are staying within the limits of the driver, you do not need to use additional cooling.

Our stepper motor drivers with a higher maximum continuous current per phase, such as the TB67S128FTG or High-Power Stepper Motor Driver 36v4 would run cooler at 1.5A per phase. So if you want the components to run a little cooler, you might consider switching to one of those if your application allows for it. However, please note that those drivers are a larger form factor than the DRV8825 and have a different set of features. If you are considering this, I recommend looking through their product pages and user’s guides to make sure they would be appropriate for your application.

Brandon