Go Down

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

#### 3SPIN3T3

##### Jun 19, 2014, 12:10 am
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 takenvoid 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

#1
##### Jun 19, 2014, 12:17 am
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

#### 3SPIN3T3

#2
##### Jun 19, 2014, 12:49 am
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

#3
##### Jun 19, 2014, 06:11 am
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