Go Down

Topic: Stepper Motor + EasyDriver (Read 2482 times) previous topic - next topic

3SPIN3T3

Hi again I'm having some issues to get right this code:
I'm ussing a easydriver but I can make it right...

Code: [Select]
int Distance = 0;  // Record the number of steps we've taken
void setup() {               
  pinMode(8, OUTPUT);     
  pinMode(9, OUTPUT);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);

}
void loop() {
  digitalWrite(9, HIGH);
  delayMicroseconds(100);         
  digitalWrite(9, LOW);
  delayMicroseconds(100);
  Distance = Distance + 1;   // record this step
  if (Distance == 3600)
  {
    if (digitalRead(8) == LOW)
    {
      digitalWrite(8, HIGH);
    }
   else
    {
      digitalWrite(8, LOW);
    }
    Distance = 0;
    delay(500);
  }
}


The Issue is I want to add 2 buttons but when I add this function... all gone bad... this is crazy

polymorph

You want to add two buttons... to do what? How are you adding them?

First step, study and learn the Blink Without Delay example sketch. So you can get rid of those delay() functions.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

3SPIN3T3

I.m Sorry to move the stepper Front (Clockwise) and Back (CounterClockSwise)
The Issue is I was trying with the arduino examples and just one direction this can happend...  also the easydriver is reallyhot and this is how I wire it.




polymorph

If it is getting hot, you should turn the current down a bit.

So.... study the Blink Without Delay, and use micros() instead of millis() to time your stepper motor. One button will pull the DIR HIGH, the other will pull DIR LOW, and you want the STEP to be enabled if and only if one and only one button is pressed.

I strongly suggest you use distance >= 3600 rather than ==. If for some reason it passes 3600, it won't get stuck forever counting.

You could also use the tone() command. Either run it for a fixed time, or turn it on only when just one button is pressed. Harder to get an accurate count of the steps, although you can get close using micros().
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Go Up