Hello there,
I am working with a NEMA-17 Motor (17PM-K310-32VS) with motor driver DRV8225 for which I am following this guide with the exact same circuit they have given but with a addition of one push button programmed to start and stop the motor. I am using AccelStepper and EzButton library for driver and button respectively.
Arduino IDE Code
#include <AccelStepper.h>
#include <ezButton.h>
#define MOTOR_SPEED 200
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
ezButton motor_switch(4);
void setup()
{
stepper.setMaxSpeed(200);
stepper.setSpeed(0);
}
void loop()
{
motor_switch.loop();
if(motor_switch.isPressed())
{
stepper.speed()==0 ? stepper.setSpeed(MOTOR_SPEED) : stepper.setSpeed(0);
}
if(stepper.speed()==0)
{
stepper.stop();
//stepper.disableInputs();
}
else
{
//stepper.enableInputs();
stepper.runSpeed();
}
}
Problem: Circuit and Code works as intended as I am able to start and stop the motor with the push button but I am facing one problem. My NEMA-17 Motor vibrates randomly at idle. Frequency of vibration is also random that is sometimes it vibrates for a very short time (less than a second) but other times it vibrates for 5-10 seconds. Also I observed that motor is getting hot even at idle.
Why is this happening and how to fix this?
Things I have done so far: In order to troubleshoot this, I tried many things:
- Changing Arduino, I have tried with UNO, NANO and MEGA.
- Changing driver Library and even uploading an empty sketch.
(I tried Accelstepper's disableInputs functions as well) - Reviewing connections.
- Changing motors.
- Replacing Motor driver with another DRV8225 module.
- Changing driver's current limit using its potentiometer.
Please help me fix this problem,
Thank you.
UPDATE
I have been able to fix the problem. Thing I found was motor was not sleeping, I read about SLP and reset pins in DRV8225's manual and found out that SLEEP mode can be controlled using the SLP pin. SLP must be HIGH to disable SLEEP mode and LOW to enable it.
Original guide and many other guides online I found shows direct connection with SLP and RST pins of DRV8825 for easy connections probably targeting beginners. But none of them mentioned the consequences this direct connection and at best few of them just mentioned the default state for these pins.
So I connected the sleep pin to Arduino digital pins and now I can control the sleep through sketch and have to make sure to enable the SLEEP mode every time I want my motor to STOP and remain idle. So updated code is as follows.
#include <AccelStepper.h>
#include <ezButton.h>
#define MOTOR_SPEED 200
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
#define SLEEP_PIN 5
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
ezButton motor_switch(4);
void setup()
{
pinMode(SLEEP_PIN,OUTPUT);
digitalWrite(SLEEP_PIN,LOW);
delay(2);
motor_switch.setDebounceTime(50);
stepper.setMaxSpeed(200);
stepper.setSpeed(0);
}
void loop()
{
motor_switch.loop();
if(motor_switch.isPressed())
{
if(stepper.speed()==0)
{
digitalWrite(SLEEP_PIN,HIGH);
delay(2);
stepper.setSpeed(MOTOR_SPEED)
}
else
{
digitalWrite(SLEEP_PIN,LOW);
delay(2);
stepper.setSpeed(0);
}
}
if(stepper.speed()==0)
{
stepper.stop();
}
else
{
stepper.runSpeed();
}
}
Since motor is now sleeping, both vibrations and heat dissipation at idle motor has been gone. I don't know if this heat was the exact reason for vibrations but its fixed as of now.