how to control stopping and holding Stepper

I hope someone can point me in the proper direction here.

The situation is that I am using and RC radio to control a camera pan and tilt gimbal. I am using two bipolar steppers to move the axes.

Where I am now.
I can receive the RC pulses into the arduino on digital pins 14, 15 and decode the pulsewidths. I have decoded the pulsewidths into two variables: Direction and steps. I am using the EasyDriver boards from Sparkfun and they drive the steppers in the proper directions, but here is where the problem rears its head.

When I move the pan control it is decoded to the proper direction and the stepper moves in the proper direction. When the number of steps have been reached, it does not stop but continues in the same direction as it was moving. If I move the stick to the opposite direction, the motor stops and then moves in the opposite direction. This is also the case if I use a channel that uses a Pot(channel 6).

From the information on the EasyDriver board, it says that the stepper moves one step for every step input. If I use MEM's code for step and direction using serial commands, the board and steppers work properly but I want to replace the stepper commands with RC commands. I realize there is no feedback element with the steppers to confirm movement to a set value, but the open loop method of counting steps works well enough in principle to achieve what I am after. The Knob sample with 0015 works well also and it stops when the value is reached.

The next stage after the movement issue is resolved if for the code to be usable when using a joystick that centers and to have the stepper remain "at the "moved to" position.

Code sample below.

Thank you in advance for any insight provided.

Jim

// define global variables
  int potPin = 0;       // Analog pin 0
  int potVal = 0;     // Variable to store input data
  //----------------------------------
  int pPin = 14;      // Set input pin to digital pin 14 analog 0
  int previous = 0;     // the previous reading from the analog input
  int pDPin = 3;
  int pSPin = 10;
  int pSteps = 0;
  int ledPin = 13;
  
  //------------------------------ Setup  -------------------------
 void setup()
{
    Serial.begin(9600); // Open serial port for debugging
    pinMode(pPin, INPUT);
    pinMode(pDPin, OUTPUT);
    pinMode(pSPin, OUTPUT);
}    
  
 //-------------------------------  Loop  -------------------------
  void loop()
{  
    // read RC Signal
    int pVal = 0;           // declare icoming value to zero
    pVal = pulseIn(pPin, HIGH); // Read RC value
    potVal = map(pVal, 1100, 1950, 0, 1023);    // set value conversion to analog range
                                              // ** need to smooth pulse. Too jumpy around center
    //int pSteps = 0;
    //int pSteps = potVal - previous;
//*******************************************************************        
    // Set direction of Direction Pin
    if (potVal <= 505 ) {
      digitalWrite(pDPin, LOW);
      digitalWrite(ledPin, LOW);
      Serial.println("left");
    } else if(potVal >= 519){
      digitalWrite(pDPin, HIGH);
      digitalWrite(ledPin, LOW);
      Serial.println("right");
      }else
      {
       digitalWrite(ledPin, HIGH);
       Serial.println("Center");
      }
       // set value for steps around/from center  
      if(potVal <= 510){
        pSteps = 1024 - potVal;
      } else if(potVal >= 513){
        pSteps = potVal;
    }
//*******************************************************************
     // move a number of steps equal to the change in the
     // sensor reading
    int i;
    //digitalWrite(pDPin, LOW);
    //digitalWrite(pSPin, LOW);
    //delay(50);
  
   for (i = 0; i<pSteps; i++)
{
    digitalWrite(pSPin, LOW);
    digitalWrite(pSPin, HIGH);
    delayMicroseconds(180);
    
}
//*****************************************************************
    Serial.print(" Pot Value: ");
    Serial.print(potVal);
    Serial.print('\t');
    Serial.print("Pan Steps: ");
    Serial.print(pSteps);
    Serial.println();
    //digitalWrite(pSteps);

    // remember the previous value of the sensor
    previous = potVal;
}
//-------------------------------- End of File  -----------------------

Well your code is doing exactly what you tell it to. Problem is you are not specifying the right thing. There is no path through your loop() where the motor will not turn. So instead write it so that you don't use the 'else' part but put another test for that section for when you want the motor to move in the other direction.

Have a look at this thread:- http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1243450963

Hello Grumpy_Mike.

Thank you for taking the time to comment. Sometimes it just takes a fresh set of eyes to spot a gremlin.

If I understand correctly then, I need to write a bit of code to check the state of the move and then once it is completed, stop the movement?

Thank you for the link to the other thread also. I will be studying it and see the correlation. I am no longer as agile mentally as a few years ago so I will have to dig down deeply for insight.

Jim

I need to write a bit of code to check the state of the move and then once it is completed, stop the movement?

Yes sort of :-
while(the button is held down){ give steps to the motor }
while(the other button is held down){ give opposite direction steps to the motor }

this will then only feed movement steps for the time a button is held down.