I have an adafruit motor shield and attached the Nema 17 stepmotor. Now the big problem is trying to power it without it overheating. I was originally using a 12v 6a power supply but quickly switched to a 12v 2a and then a 12v 1a. All of them still make the Nema stepper motor very hot.
I'm using the accelstepper and adafruit modules on the arduino to control the stepper motor. I noted that the magnets are all always on in my code which might explain why it gets hot but I need to maintain some form of torque for the system I'm developing.
I will attach code as that might be the problem. Is there a second device I need to attach to the adafruit motor sheild and the nema stepper motor.
#include <AccelStepper.h>
#include <MultiStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
int ComControlValue = -1;
/* Define pins for motor and define step motor function */
const int SlowStepPerRev = 400; // Define slow speed constant
const int MotorB = 2;
int rpm = 60; // Rotation per minute
int acelspeed = 40; // Acceleration speed
int distrot = 200;
int destinationunknown = 0; // Destination of plate 1
/* Initialize the stepper library on the motor shield */
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotorB = AFMS.getStepper(SlowStepPerRev, MotorB);
/* you can change these to SINGLE or DOUBLE or INTERLEAVE or MICROSTEP! */
// wrappers for the motor!
void forwardstepB() {
myMotorB->onestep(FORWARD, INTERLEAVE);
}
void backwardstepB() {
myMotorB->onestep(BACKWARD, INTERLEAVE);
}
AccelStepper stepperB(forwardstepB, backwardstepB);
void setup() {
Serial.begin(115200); // Establish Serial connection to computer
Wire.begin(); // join i2c bus as master
AFMS.begin(); // Begin useage of conveyorbelt motor
stepperB.setMaxSpeed(rpm); // Initialize max speed
stepperB.setAcceleration(acelspeed); // Initialize and set speed of acceleration for spinning
}
void loop() {
switch(ComControlValue){
case -1: //wait
Serial.println("Waiting for Command");
Serial.println(stepperB.currentPosition());
while (Serial.available()==0){}
ComControlValue=Serial.parseInt(); // Pull value from serial port
break; // break loop & return to start
/* 1 : Move plates into the system */
case 1:
// Arduino using accelmotor, move to position X
if (plateNum < platelimit){
plateNum++;
ComControlValue= 11; // After establishing plate num & location, move to case 11 to start stepmotor movement
destinationunknown = destinationunknown + 200;
}
else {
ComControlValue = -1; // To many plates, cancel move command
}
stepperB.moveTo(destinationunknown);
break;
/* 2 : Move plate out of system */
case 2:
// Arduino using accelmotor, move to position Y
if (plateNum > 0){
plateNum = plateNum--;
ComControlValue= 11; // After establishing plate num & location, move to case 11 to start stepmotor movement
destinationunknown = destinationunknown - 200;
}
else {
ComControlValue = -1;
}
stepperB.moveTo(destinationunknown);
break;
/* 1 : Run Stepmotor to completion */
case 11:
// Step motor requires an uninterrupted while loop to move to completion
// code setup will utilize while loop and allow for movement
stepperB.run(); // run stepmotor
if (stepperB.distanceToGo() == 0 ){
ComControlValue = -1; // Completed movement, go back to case -1
}
break;
}
}