Easy driver and sparkfun pro micro issues with heat

Hello.

I have created a project that uses an easy driver, a pro micro and a simple power supply.

I have some experience in programming, mostly basic and c#, and a fair amount in electronics.

I used the wonderful demo for the ED as a framework to create a program that uses 2 switches to control a stepper and turns it at about 5.4mS per pulse. I know the electronics is OK because with the ED demo it works perfectly. Oh sorry, I use the internal pullups of the 32u4 for the switches, and they are connected to the star point of the circuit.

At least that's what I thought I had created...after some minor bug hunting I got a clean compile and uploaded it. Uploaded effortlessly... and just sits there. No action when I press a button, no movement when it should be running normally. I have already tried changing the delay times for the step commands, but as the ED has a fmax of 500kHz I didn't think that was the issue.

The ED and stepper motor are both getting very warm over the space of 30 odd seconds, but like I said with the demo running it works like a charm...so it's not a short.

If I had to guess I'd wonder if it's some kind of 'race' condition, trying to jump between forwards and backwards really quickly perhaps, but I can't figure out why it's happening. I'd be grateful for any advice, or recommendations...it's probably staring me in the face. :slight_smile:
I've removed the preamble from the top of the source, but will acknowledge authors as necessary in the final build.

#define stp 2  // ed connection
#define dir 3  // ed connection
#define MS1 4  // ed connection  
#define MS2 5  // ed connection 
#define EN  6  // ed connection
#define pk 7  // "park" switch, stops the mount when fully rewound.
#define Rst 8 // "Reset" switch, allows the user to send the mount back to the start of its travel.

//Declare variables for functions

int x;



void setup() {
  pinMode(stp, OUTPUT); // All these ports are outputs...
  pinMode(dir, OUTPUT);
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  pinMode(EN, OUTPUT); // ...Down to this one.
  pinMode(pk, INPUT_PULLUP); // set pin 7 as input, use internal pullup resistor so only switch needed to ground.
  pinMode(Rst, INPUT_PULLUP); // set pin 8 as input, use internal pullup resistor so only switch needed to ground.

  resetEDPins(); //Set step, direction, microstep and enable pins to default states
  Serial.begin(9600); //Open Serial connection for debugging. May remove this once functional.
}



//Main loop
void loop() {

  int Park = digitalRead(7);
  int Reset = digitalRead(8);

 
  digitalWrite(EN, LOW); //Pull enable pin low to allow motor control
  if (Park == LOW && Reset == HIGH) // If parked, start tracking
  {
    StepForwardDefault();
  }
  else if (Park == HIGH && Reset == LOW) // If Reset pushed, rewind
  {
    delay (500); // half second pause. Debounce coding is so last year.
    ReverseStepFast();
  }
  else if (Park == HIGH && Reset == HIGH) // normal running.
  {
    StepForwardDefault();
  }
  else if (Park == LOW && Reset == LOW) // Unusual condition
  {
    Serial.println("I'm already Reset and Parked.");
  }
  else // Nothing seems to fit, error message...
  {
    Serial.println("Something Is Wrong.");
  }
  resetEDPins();
}


//Reset Easy Driver pins to default states
void resetEDPins()
{
  digitalWrite(stp, LOW);
  digitalWrite(dir, LOW);
  digitalWrite(MS1, LOW);
  digitalWrite(MS2, LOW);
  digitalWrite(EN, HIGH);
}

//Forward function
void StepForwardDefault()
{
  int Reset = digitalRead(8);
  if (Reset == HIGH)
  {
    digitalWrite(dir, LOW); //Pull direction pin low to move "forward"
    for ( x = 0; x <= 4000000; x++) // count for 6 hours.
      delayMicroseconds(3400); // Takes one step every 5.4mS to work. Your results will vary depending on the stepper motor.
    digitalWrite(stp, HIGH); //Trigger one step forward
    delay(1);                // taken as 1000uS for timing purposes.
    digitalWrite(stp, LOW); //Pull step pin low so it can be triggered again
    delay(1);                // taken as 1000uS for timing purposes.
  }
  else if (Reset == LOW)
  {
    delay (500); // Half second pause. Debounce coding is so last year.
    ReverseStepFast();
  }

}

//Reverse function
void ReverseStepFast()
{
  int Park = digitalRead(7);
  digitalWrite(dir, HIGH); //Pull direction pin high to move in "reverse"
  if (Park == HIGH) //Loop until parked and ready to start again
  {
    digitalWrite(stp, HIGH); //Trigger one step
    delay (1); // Stepper controller can function @ 500kHz, no delay needed.
    digitalWrite(stp, LOW); //Pull step pin low so it can be triggered again
    delay (1);
  }
  else if (Park == LOW)  // Parked, time to start again.
  {
    StepForwardDefault();
  }
}

Hi,
have you used a DMM to see if any signals coming out of the arduino to the ESD?
Can your steppers work at that speed?
have you checked the specs?

Tom... :slight_smile:

Hi Tom,

I never have less than 1mS delay, which is what the maker uses in his test code so I don't think it's that. I'm not getting any signals from the micro, but it seems to be pulling everything low. The H bridge and motor are warming up, but there is no movement from the motor.
I'm going to try adding some terminal debug stuff, I will let you know what I find out.
Thank you.

Try this Simple Stepper Code - it should be suitable to prove the motor works.

It is quite normal for a stepper driver and stepper motor to be hot and uncomfortable to touch with your finger.

Maybe your motor requires more current than the Easydriver can provide. Post a link to the datasheet for your motor.

How have you set the current limit on the Easydriver board?

What motor power supply are you using - volts and amps?

...R
Stepper Motor Basics

Hello Robin :slight_smile:

The easy driver and stepper motor work perfectly with the demo code from the ED website, the controller, psu and motor are all fine. the motor control code I took directly from that demo.PSU is a fixed 5v/3a for the micro, 4*18650 lithium batteries in series for the ED. (it sets the voltage automatically).
The motor and controller get hot quickly, but nothing physical happens, no motor movement that I can see.

Here is the demo I used to get working code for the stepper:

/****************************************************************************** 
SparkFun Easy Driver Basic Demo
Toni Klopfenstein @ SparkFun Electronics
March 2015
https://github.com/sparkfun/Easy_Driver

Simple demo sketch to demonstrate how 5 digital pins can drive a bipolar stepper motor,
using the Easy Driver (https://www.sparkfun.com/products/12779). Also shows the ability to change
microstep size, and direction of motor movement.

Development environment specifics:
Written in Arduino 1.6.0

This code is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round!
Distributed as-is; no warranty is given.

Example based off of demos by Brian Schmalz (designer of the Easy Driver).
http://www.schmalzhaus.com/EasyDriver/Examples/EasyDriverExamples.html
******************************************************************************/
//Declare pin functions on Redboard
#define stp 2
#define dir 3
#define MS1 4
#define MS2 5
#define EN  6

//Declare variables for functions
char user_input;
int x;
int y;
int state;

void setup() {
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  pinMode(EN, OUTPUT);
  resetEDPins(); //Set step, direction, microstep and enable pins to default states
  Serial.begin(9600); //Open Serial connection for debugging
  Serial.println("Begin motor control");
  Serial.println();
  //Print function list for user selection
  Serial.println("Enter number for control option:");
  Serial.println("1. Turn at default microstep mode.");
  Serial.println("2. Reverse direction at default microstep mode.");
  Serial.println("3. Turn at 1/8th microstep mode.");
  Serial.println("4. Step forward and reverse directions.");
  Serial.println();
}

//Main loop
void loop() {
  while(Serial.available()){
      user_input = Serial.read(); //Read user input and trigger appropriate function
      digitalWrite(EN, LOW); //Pull enable pin low to allow motor control
      if (user_input =='1')
      {
         StepForwardDefault();
      }
      else if(user_input =='2')
      {
        ReverseStepDefault();
      }
      else if(user_input =='3')
      {
        SmallStepMode();
      }
      else if(user_input =='4')
      {
        ForwardBackwardStep();
      }
      else
      {
        Serial.println("Invalid option entered.");
      }
      resetEDPins();
  }
}

//Reset Easy Driver pins to default states
void resetEDPins()
{
  digitalWrite(stp, LOW);
  digitalWrite(dir, LOW);
  digitalWrite(MS1, LOW);
  digitalWrite(MS2, LOW);
  digitalWrite(EN, HIGH);
}

//Default microstep mode function
void StepForwardDefault()
{
  Serial.println("Moving forward at default step mode.");
  digitalWrite(dir, LOW); //Pull direction pin low to move "forward"
  for(x= 1; x<1000; x++)  //Loop the forward stepping enough times for motion to be visible
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delay(1);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delay(1);
  }
  Serial.println("Enter new option");
  Serial.println();
}

//Reverse default microstep mode function
void ReverseStepDefault()
{
  Serial.println("Moving in reverse at default step mode.");
  digitalWrite(dir, HIGH); //Pull direction pin high to move in "reverse"
  for(x= 1; x<1000; x++)  //Loop the stepping enough times for motion to be visible
  {
    digitalWrite(stp,HIGH); //Trigger one step
    delay(1);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delay(1);
  }
  Serial.println("Enter new option");
  Serial.println();
}

// 1/8th microstep foward mode function
void SmallStepMode()
{
  Serial.println("Stepping at 1/8th microstep mode.");
  digitalWrite(dir, LOW); //Pull direction pin low to move "forward"
  digitalWrite(MS1, HIGH); //Pull MS1, and MS2 high to set logic to 1/8th microstep resolution
  digitalWrite(MS2, HIGH);
  for(x= 1; x<1000; x++)  //Loop the forward stepping enough times for motion to be visible
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delay(1);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delay(1);
  }
  Serial.println("Enter new option");
  Serial.println();
}

//Forward/reverse stepping function
void ForwardBackwardStep()
{
  Serial.println("Alternate between stepping forward and reverse.");
  for(x= 1; x<5; x++)  //Loop the forward stepping enough times for motion to be visible
  {
    //Read direction pin state and change it
    state=digitalRead(dir);
    if(state == HIGH)
    {
      digitalWrite(dir, LOW);
    }
    else if(state ==LOW)
    {
      digitalWrite(dir,HIGH);
    }
    
    for(y=1; y<1000; y++)
    {
      digitalWrite(stp,HIGH); //Trigger one step
      delay(1);
      digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
      delay(1);
    }
  }
  Serial.println("Enter new option:");
  Serial.println();
}

Funwithautomation:
The easy driver and stepper motor work perfectly with the demo code

....

The motor and controller get hot quickly, but nothing physical happens, no motor movement that I can see.

I can't reconcile those two statements - do they relate to the same program or to two different programs?

If they are different programs, what is different about them?

If they are the same program, what other things are different?

...R

The code that controls the stepper in my program is taken from the demo. It's identical, if you have a look at my code vs the demo you'll see what I mean. That's what is so confusing, unless I've done something stupid with a loop (which I can't spot) I can't figure it out either :slight_smile:

I confess I don't see identical functions in the two programs.

This

    for ( x = 0; x <= 4000000; x++) // count for 6 hours.
      delayMicroseconds(3400); // Takes one step every 5.4mS to work. Your results will vary depending on the stepper motor.

is very impractical.

Have a look at the second example in my Simple Stepper Code which uses millis() and micros() to manage timing without using delay() or blocking FOR loops.

...R