Go Down

Topic: Reverse Operation (HELP) (Read 354 times) previous topic - next topic

Iz_Meister

Hi to anyone who reads this,

I'm currently doing a project and currently stuck. I'm using UNO Arduino, Easydriver stepper motor and a stepper motor.
I've managed to program and tested included wiring.
My current issue is it can foward and reverse even when i place the alt switch in series with the motor.
But however when i want to reverse, i want it to reverse when i press a button/key thus never foward anymore till i switch back.
Can anyone please advise on how to solve the problem??

My current wiring is as follows

A1 to switch N/C
B1 to switch N/O 

rogue_wraith

You need to provide more detail if you want an accurate answer, but here's a shot.

Psuedo code:

LOOP:

Go direction

Check if front bumper hit
  If hit, reverse direction

Check if back bumper hit
  If hit, forward direction

END LOOP

With this, you'd basically just need a variable called "Direction," which is only changed if the switch is hit.  If the switch is not hit, the bot will continue in "Direction."

robtillaart

be sure to debounce that switch, or at least allow change of directions only once per (estimate) 25 millisecs.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Iz_Meister

Hi, rogue_wraith,

Thanks for getting back to me. Can you elaborate more on the code as I've never used this code before.
This is my current code:

#define DIR_PIN 2
#define STEP_PIN 3

void setup() {
  pinMode(DIR_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
}

void loop(){
 

  //rotate a specific number of microsteps (8 microsteps per step)
  //a 200 step stepper would take 1600 micro steps for one full revolution
  rotate(3200, .5);
  delay(1000);

  rotate(-3200, .5); //reverse
  delay(1000);
}

void rotate(int steps, float speed){
  //rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
  //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
  int dir = (steps > 0)? HIGH:LOW;
  steps = abs(steps);

  digitalWrite(DIR_PIN,dir);

  float usDelay = (1/speed) * 70;

  for(int i=0; i < steps; i++){
    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(usDelay);

    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(usDelay);
  }
}

void rotateDeg(float deg, float speed){
  //rotate a specific number of degrees (negitive for reverse movement)
  //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
  int dir = (deg > 0)? HIGH:LOW;
  digitalWrite(DIR_PIN,dir);

  int steps = abs(deg)*(1/0.225);
  float usDelay = (1/speed) * 70;

  for(int i=0; i < steps; i++){
    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(usDelay);

    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(usDelay);
  }
}

Pls can you advise on how to add your code in?

Thanks Again
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Btw ,my man from Netherlands thank you as well
i can't figure out its hardware or software prob.

Go Up