I have an unusual dilemma. I have a project that uses 2 Nema 17 stepper motors that I created about 4 years ago and it has worked great. The other day I re-uploaded (long story as to why) the same exact Arduino code, without changing a single thing to the wiring, motors, drivers, or code itself, and now the stepper motors won't work properly. Previously we were using them at 200 rpm, and now they won't even spin when set to that speed, they just make an awful grinding noise. They will spin at lower speeds (~50-100rpm), but still loud and vibrating like something is wrong.
I have tried replacing the motor with a brand new one just in case. That changed nothing. Also tried replacing the driver ( TB6612) just in case that was it and changed nothing.
The ONLY thing I can possibly think of is that when I re-uploaded the code, it would have pulled from the most recent Arduino libraries, not whatever was used a few years back when I originally wrote the code. However, reviewing the most recent documentation with my code I can't find an obvious incompatibility. It's a very simple program.
Is anyone aware of any changes to the stepper library over the last few years that would cause a problem? Or have any other thoughts as to what my issue is?
This is my code for reference:
#include <Stepper.h>
#include <Servo.h>
/****** CONSTANTS ********/
const int
LEDBUTTON1 = 0, // pin for LED of button 1
LEDBUTTON2 = 1, // pin for LED of button 2
BUTTON1 = 2, // pin for button 1 that runs the liquid sequence
BUTTON2 = 3, // pin for button 2 that runs the solid sequence
StepsPerRevolution = 200, // Our motors have 200 steps/rotation
// setup pins for each stepper motor and the servo:
// Lift Motor pins ~ IN1, IN2, IN3, IN4 (pins 4 - 7)
LiftIN1 = 4,
LiftIN2 = 5,
LiftIN3 = 6,
LiftIN4 = 7,
// Push Motor pins ~ IN1, IN2, IN3, IN4 (pins 8 - 11)
PushIN1 = 8,
PushIN2 = 9,
PushIN3 = 10,
PushIN4 = 11,
// Servo Pin
PinServo = 12,
// Motor Speeds in RPM
LiftSpeed = 200, // Set between 0 and 200 RPM
PushSpeed = 45, // Set between 0 and 60 RPM
// Step movements for the stepper motors
LiftSteps = 2780,
PushSteps = 475,
// Position constants for the Servo
PosServo = 130, // set an initial poisiton of the servo
// Time constants
sec = 1000; // in milliseconds
/**************Wire Connections from Arduino to plate**************
* Pin 0 - LED Button (Directly connected to button wires)
* Pin1 - LED Button (Directly connected to button wires)
* Pin 2 - 25A (Button 1)
* Pin 3 - 26A (Button 2)
* Pin 4 - 20A (Lift AIN2)
* Pin 5 - 19A (Lift AIN1)
* Pin 6 - 17A (Lift BIN1)
* Pin 7 - 16A (Lift BIN2)
* Pin 8 - 9A (Push AIN2)
* Pin 9 - 8A (Push AIN1)
* Pin 10 - 6A (Push BIN2)
* Pin 11 - 5A (Push BIN1)
* Pin 12 - 28A (Servo)
*/
/**********PORT Functions**********
* The PORTB/PORTD functions allow the manipulation of pins on
* the Arduino uno. Each pin can be set to either High (1) or Low (0).
* The correlation between functions and pins:
*
* PORTD (pins 0-7)
* Value PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0
* Pin 7 6 5 4 3 2 1 0
*
* PORTB (pins 8-13)
* Value PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0
* Pin X X 13 12 11 10 9 8
*/
Servo DumperServo;
Stepper LiftStepper(StepsPerRevolution, LiftIN1, LiftIN2, LiftIN3, LiftIN4);
Stepper PushStepper(StepsPerRevolution, PushIN1, PushIN2, PushIN3, PushIN4);
void setup(){
pinMode(LEDBUTTON1, OUTPUT);
pinMode(LEDBUTTON2, OUTPUT);
pinMode(BUTTON1, INPUT_PULLUP);
pinMode(BUTTON2, INPUT_PULLUP);
delay(5*sec); // delay initial raising to account for human error
LiftStepper.setSpeed(LiftSpeed); // set the speed of the motors here (rpm)
PushStepper.setSpeed(PushSpeed);
DumperServo.attach(PinServo);
DumperServo.write(-PosServo);
delay(sec);
DumperServo.write(PosServo);
delay(sec);
LiftStepper.step(LiftSteps);
// line sets pins high or low, killing current to stepper motors. Turns on LED Buttons connected to pins 0,1
PORTD = B00000011;
PORTB = B00000000; // enter standby mode
}
void loop()
{
if(digitalRead(BUTTON1) == HIGH){ /********** LIQUID PROGRAM **********/
digitalWrite(LEDBUTTON1, LOW); // turns off the LED buttons
digitalWrite(LEDBUTTON2, LOW);
LiftStepper.step(-LiftSteps); // down
delay(sec);
PORTD = B00000000; // kills current to LiftStepper, allowing more torque in PushStepper
PushStepper.step(PushSteps); // push
LiftStepper.step(LiftSteps); // up
PushStepper.step(-PushSteps); // pull
PORTD = B00000011; // sets pins 0,1 high, turning on the LED buttons, and setting all other pins low
PORTB = B00000000; // cycle complete, returns to standby mode
}
if(digitalRead(BUTTON2) == HIGH){ /********** SOLID PROGRAM **********/
digitalWrite(LEDBUTTON1, LOW); // turns off the LED buttons
digitalWrite(LEDBUTTON2, LOW);
LiftStepper.step(-LiftSteps); // down
delay(sec);
PORTD = B00000000; // kills current to LiftStepper, allows more current to servo
DumperServo.write(-PosServo); //dump
delay(sec);
LiftStepper.step(LiftSteps); // up
DumperServo.write(PosServo); // reset servo position
PORTD = B00000011; // sets pins 0,1 high, turning on the LED buttons, and setting all other pins low
PORTB = B00000000; //cycle complete, returns to standby mode
}
}