Steppers Getting Hot

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
evanmorris
 
Posts: 11
Joined: Wed Jan 28, 2015 12:24 am

Steppers Getting Hot

Post by evanmorris »

I am using the Adafruit Motor shield v2.3 with the Nema-17 stepper motor from adafruit. I am noticing after I run my code once my stepper motors get really hot. It's like the stepper is holding on tight to the position and is getting really hot because of it. If I hit the reset button on the arduino the steppers seem to "let go" and cool down. Is there any way in code I can make the steppers release so they stay cool in downtime?

Here is my code. Newbie here so I'm sure it's a mess.

Code: Select all

/* 
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2 
---->	http://www.adafruit.com/products/1438
*/


#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotorD1 = AFMS.getStepper(200, 2);
Adafruit_StepperMotor *myMotorD2 = AFMS.getStepper(200, 1);

const int Derby2pin = 5;
const int Derby1pin = 13;

boolean resetD2 = false;    // should reverse motor Derby2
boolean resetD1 = false;    // should reverse motor Derby1

int distance = 8000;

// Variables will change:
int buttonStateD1;   // the current reading from the input pin
int buttonStateD2;
int lastButtonStateD1 = HIGH;   // the previous reading from the input pin
int lastButtonStateD2 = HIGH;

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTimeD1 = 0;  // the last time the output pin was toggled
long lastDebounceTimeD2 = 0;  // the last time the output pin was toggled
long debounceDelayD1 = 50;    // the debounce time; increase if the output flickers
long debounceDelayD2 = 50;    // the debounce time; increase if the output flickers

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Derby Stepper");
  pinMode(Derby2pin, INPUT_PULLUP);           // set pin to input
  pinMode(Derby1pin, INPUT_PULLUP);           // set pin to input

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  myMotorD1->setSpeed(300);  // 300 rpm 
  myMotorD2->setSpeed(300);  
}

void loop() {
  
  //Start Derby 1 Motor Code
  int Derby1val = digitalRead(Derby1pin);
  
    if (Derby1val != lastButtonStateD1) {
    // reset the debouncing timer
    lastDebounceTimeD1 = millis();
  } 
  
  
  Serial.println(lastDebounceTimeD1);
  Serial.println(millis());
  if ((millis() - lastDebounceTimeD1) > debounceDelayD1) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    Serial.println("Debouncing");
    
    // if the button state has changed:
    if (Derby1val != buttonStateD1) {
      buttonStateD1 = Derby1val;
Serial.println("Switch On " + buttonStateD1);
      // only toggle the motor if the new button state is HIGH
      if (buttonStateD1 == LOW  && resetD1 == false) {
            myMotorD1->step(distance, FORWARD, DOUBLE);
            resetD1 = true;
      }
      
      if (buttonStateD1 == HIGH && resetD1 == true){
        
        Serial.println("Switch Off");
            myMotorD1->step(distance, BACKWARD, DOUBLE);
            resetD1 = false;
      }
    }
  }

  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonStateD1 = Derby1val;

  
  
  //Start Derby2 Motor Code
  int Derby2val = digitalRead(Derby2pin);
  
  
  if (Derby2val != lastButtonStateD2) {
    // reset the debouncing timer
    lastDebounceTimeD2 = millis();
  } 
  
  
  Serial.println(lastDebounceTimeD2);
  Serial.println(millis());
  if ((millis() - lastDebounceTimeD2) > debounceDelayD2) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    Serial.println("Debouncing");
    // if the button state has changed:
    if (Derby2val != buttonStateD2) {
      buttonStateD2 = Derby2val;
Serial.println("Switch On " + buttonStateD2);
      // only toggle the motor if the new button state is HIGH
      if (buttonStateD2 == LOW  && resetD2 == false) {
            myMotorD2->step(distance, FORWARD, DOUBLE);
            resetD2 = true;
      }
      
      if (buttonStateD2 == HIGH && resetD2 == true){
        
        Serial.println("Switch Off");
            myMotorD2->step(distance, BACKWARD, DOUBLE);
            resetD2 = false;
      }
    }
  }

  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonStateD2 = Derby2val;
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Steppers Getting Hot

Post by adafruit_support_bill »

It's like the stepper is holding on tight to the position and is getting really hot
That is normal for steppers. It is called "holding current". That motor is rated for a 70C temperature rise above up to 50C ambient temperature. In other words, the coils are designed for operation up to 120C.
Is there any way in code I can make the steppers release so they stay cool in downtime?
Yes. There is a "release()" function in the stepper class.

User avatar
evanmorris
 
Posts: 11
Joined: Wed Jan 28, 2015 12:24 am

Re: Steppers Getting Hot

Post by evanmorris »

Ok thanks. Do I just call release(); in my loop? I tried that and I code this compiler error
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Mac OS X), Board: "Arduino Uno"
Derby_keys.ino: In function 'void loop()':
Derby_keys:93: error: 'release' was not declared in this scope
Derby_keys:136: error: 'release' was not declared in this scope

User avatar
evanmorris
 
Posts: 11
Joined: Wed Jan 28, 2015 12:24 am

Re: Steppers Getting Hot

Post by evanmorris »

Nevermind. I didn't do MyMotorD1->release(); that worked.

User avatar
evanmorris
 
Posts: 11
Joined: Wed Jan 28, 2015 12:24 am

Re: Steppers Getting Hot

Post by evanmorris »

So I got the release(); to work when I was using the original step() function for the motorshield v2, but I found the quickstep() function from this post.

viewtopic.php?f=31&t=57041&start=15

and now when I tell the stepper to release it becomes unresponsive. Any ideas?

Code: Select all

/* 
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2 
---->	http://www.adafruit.com/products/1438
*/


#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotorD1 = AFMS.getStepper(200, 1);
Adafruit_StepperMotor *myMotorD2 = AFMS.getStepper(200, 2);

const int Derby2pin = 5;
const int Derby1pin = 13;

boolean resetD2 = false;    // should reverse motor Derby2
boolean resetD1 = false;    // should reverse motor Derby1

int distance = 1000;

// Variables will change:
int buttonStateD1;   // the current reading from the input pin
int buttonStateD2;
int lastButtonStateD1 = HIGH;   // the previous reading from the input pin
int lastButtonStateD2 = HIGH;

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTimeD1 = 0;  // the last time the output pin was toggled
long lastDebounceTimeD2 = 0;  // the last time the output pin was toggled
long debounceDelayD1 = 50;    // the debounce time; increase if the output flickers
long debounceDelayD2 = 50;    // the debounce time; increase if the output flickers

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Derby Stepper");
  TWBR = ((F_CPU /400000l) - 16) / 2; // Change the i2c clock to 400KHz
  pinMode(Derby2pin, INPUT_PULLUP);           // set pin to input
  pinMode(Derby1pin, INPUT_PULLUP);           // set pin to input

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  //myMotorD1->setSpeed(400);  // 300 rpm 
  //myMotorD2->setSpeed(400);  
  
  myMotorD1->onestep(FORWARD, DOUBLE);
  myMotorD1->onestep(BACKWARD, DOUBLE);
}

void loop() {
  
  //Start Derby 1 Motor Code
  int Derby1val = digitalRead(Derby1pin);
  
    if (Derby1val != lastButtonStateD1) {
    // reset the debouncing timer
    lastDebounceTimeD1 = millis();
  }
  
  
  //Serial.println(lastDebounceTimeD1);
  //Serial.println(millis());
  if ((millis() - lastDebounceTimeD1) > debounceDelayD1) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    //Serial.println("Debouncing");
    
    // if the button state has changed:
    if (Derby1val != buttonStateD1) {
      buttonStateD1 = Derby1val;
//Serial.println("Switch On " + buttonStateD1);
      // only toggle the motor if the new button state is LOW
      if (buttonStateD1 == LOW  && resetD1 == false) {
        Serial.println("Move Forward");
        
        for(int i = 0; i < distance; i++){
          //Serial.println(i);
          myMotorD1->quickstep(FORWARD);
          delayMicroseconds(400);
      }
          resetD1 = true;
          
      }
      
      if (buttonStateD1 == HIGH && resetD1 == true){
        
        Serial.println("Move Backward");  
        for(int i = 0; i < distance; i++){
          //Serial.println(i);
          myMotorD1->quickstep(BACKWARD);
          delayMicroseconds(400);
      }
      
        resetD1 = false;
        //myMotorD1->release();
        Serial.println("Release");
        Serial.println(resetD1);
      
    }
  }
  }
  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonStateD1 = Derby1val;

  
  /*
  //Start Derby2 Motor Code
  int Derby2val = digitalRead(Derby2pin);
  
  
  if (Derby2val != lastButtonStateD2) {
    // reset the debouncing timer
    lastDebounceTimeD2 = millis();
  } 
  
  
  Serial.println(lastDebounceTimeD2);
  Serial.println(millis());
  if ((millis() - lastDebounceTimeD2) > debounceDelayD2) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    Serial.println("Debouncing");
    // if the button state has changed:
    if (Derby2val != buttonStateD2) {
      buttonStateD2 = Derby2val;
Serial.println("Switch On " + buttonStateD2);
      // only toggle the motor if the new button state is HIGH
      if (buttonStateD2 == LOW  && resetD2 == false) {
            myMotorD2->step(distance, FORWARD, DOUBLE);
            resetD2 = true;
      }
      
      if (buttonStateD2 == HIGH && resetD2 == true){
        
        Serial.println("Switch Off");
            myMotorD2->step(distance, BACKWARD, DOUBLE);
            resetD2 = false;
            myMotorD2->release();
      }
    }
  }

  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonStateD2 = Derby2val;
  */
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Steppers Getting Hot

Post by adafruit_support_bill »

See this post: viewtopic.php?f=31&t=57041&start=30#p308248
Quickstep is able to achieve faster step rates because it doesn't set the PWM duty cycle on each step like the oneStep command. Since release turns the PWM off completely, you need to re-initialize the PWM before calling quickstep again.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”