drv8825 sleep

154 views
Skip to first unread message

Ericka Mora

unread,
Apr 27, 2021, 11:56:19 PM4/27/21
to accelstepper
Hello, 
I would like to know how I can set the stepper in idle state, after the assigned task. I control it with a touch interrupter, which with a touch  turn right and with another turn left. Thanks

#include <AccelStepper.h>

AccelStepper motor1(1, 50, 48);

int pos1 = 2000;
int pos0 = -2000;

int contador1 = 0;

void setup() {
  Serial.begin(9600);
  pinMode (51, INPUT);  //touch1
  motor1.setEnablePin(52);
  //motor1.setPinsInverted(false, false, true);
  motor1.setMaxSpeed(1000);
  motor1.setAcceleration(300);
}

void loop() {
  to1();
  mot1();
}

void to1() {
  int tou1 = digitalRead(51);
  if (tou1 == 0) {
    contador1++;
    if (contador1 == 2) {
      contador1 = 0;
    }
    Serial.println(contador1);
    while (!digitalRead(51));
    motor1.enableOutputs();
  }
}

void mot1() {
  if (contador1 == 1) {
    if (motor1.distanceToGo() == 0)
    {
      motor1.moveTo(pos1);
    }
    motor1.run();
  } else if (contador1 == 0) {
    if (motor1.distanceToGo() == 0)
    {
      motor1.moveTo(pos0);
    }
    motor1.run();
  }
}


Ben Hudson

unread,
Apr 29, 2021, 11:01:47 AM4/29/21
to accelstepper
One way to do this is to disable the driver, another is to use its sleep mode. You can use disableOutputs(), or you can drive the enable pin or sleep pin outside of the AccelStepper library. You will need to look at the datasheet for your specific driver carrier board to determine the pins and their states. 

Ericka Mora

unread,
Apr 29, 2021, 9:09:37 PM4/29/21
to accelstepper
thanks, I already used this options, and they did not work. The sleep pin of the DRV8825 never reach to 0  volts  when disableOutputs()  is executed, this stays in 1.89 volts. 

This is the code that I am using for testing.

#include <AccelStepper.h>

AccelStepper motor1(1, 50, 48);

//int pos1 = 20000;
int pos0 = -2000;

//int contador1 = 0;

void setup() {
  Serial.begin(9600);
  //pinMode (51, INPUT);  //touch1
  motor1.setPinsInverted(false, false, true);
  motor1.setEnablePin(52);
  motor1.setMaxSpeed(1000);
  motor1.setAcceleration(300);
}

void loop(){
      motor1.disableOutputs();  
    if (motor1.distanceToGo() == 0)
    {
      motor1.enableOutputs();
      motor1.moveTo(pos0);
    }
      { 
      motor1.run();
      } 
}


Also in the attached video I am taking the measurements of sleep pin and GND  
WhatsApp Image 2021-04-29 at 6.39.47 PM.jpeg
WhatsApp Video 2021-04-29 at 6.39.47 PM.mp4
WhatsApp Image 2021-04-29 at 6.39.47 PM (1).jpeg

Ben Hudson

unread,
Apr 29, 2021, 9:49:15 PM4/29/21
to accelstepper
It sounds like your output pin is floating. it looks like you have the ground on the stepper driver connected to the ground pin on the DRV8825 board, so you will probably also need to have enabled or added pull-down resistors on the pins on the Arduino that you are using to control the DRV8825 pins. Pull-down resistors are usually about 100K resistors between the digital pin and ground to pull the voltage of the pin to ground when it is not driven high.

roxy_s...@hotmail.com

unread,
May 2, 2021, 8:17:01 AM5/2/21
to accelstepper
you seem to set
motor1.setEnablePin(52);
to pin 52 yet from looking at your photo you dont have the enable pin connected to 52 you have the sleep pin which are different things.
the enable pin is the pin close to the pot on the corner.

if you do want to use sleep instead of enable i think you just need to wire the 5v to rst and then control the sleep pin from the digital pin 52 like your trying but id put the rst pin on a seperate line so its not effected by your sleep pin logic.
try that.

i think the jumper between rst and sleep is only for people that dont want to control sleep and just want it enabled.if you want to control it rst should be on another line.

i think.
Reply all
Reply to author
Forward
0 new messages