Slight Problem with Stepper Motor Controlled by Joystick.


good day.  i'm trying build clock drive homemade telescope using stepper motor. thought convenient have joystick control easy slewing , forth.

i using seeed motor shield v1.0, adafruit analog thumb joystick, ming jong st28 12v stepper motor, 8 aa batteries, , arduino uno.

my code follows:

code: [select]
// include arduino stepper library
#include <stepper.h>
 
const int stepsperrevolution = 2048;  // specific motor
 
// initialize stepper library on pins 8 through 11:
stepper mystepper(stepsperrevolution, 8,11,12,13); 

//joystick on analog pin 0
int joypin1 = 0;
 
void setup() {

// activate motor shield setting pins 9 , ten digital high, per shield's specs.
  pinmode(9,output);
  pinmode(10,output);
  digitalwrite(9,high);
  digitalwrite(10,high);
 
}


 
void loop() {
  top:
  // read joystick's analog signal
  float xjoy = analogread(joypin1);
 
  // set speed accordingly .(i want motor spin @ 4 1/6 rpm when joystick @ rest,
  // telescope counteract earth's rotation. other operations process
  // joystick readings reasonable.)
  mystepper.setspeed(abs(4.1667 + (xjoy-525)/50));
 
  // if speed greater zero, move counterclockwise
  if (((xjoy-525)/50) > -4.1667)  {
    mystepper.step(64);
  }
  // otherwise, move clockwise.
  else  {
//unless speed zero
    if ((abs(4.1667 + (xjoy-525)/50)) != 0)  {
      mystepper.step(-64);
    }
    // in case, start over.
    else  {
      goto top;
    }

  }
}


however, when joystick in position , motor speed zero, takes infinitely long move sixty-four steps has to, , motor stops indefinitely.  shown above, tried bit of code address issue:

code: [select]
//unless speed zero
    if ((abs(4.1667 + (xjoy-525)/50)) != 0)  {
      mystepper.step(-64);
    }
    // in case, start over.
    else  {
      goto top;
    }


unfortunately, doesn't seem work.  ideas? thanks!

however, when joystick in position , motor speed zero, takes infinitely long move sixty-four steps has to, , motor stops indefinitely.
your description not make sense. if motor speed 0 should stop indefinitely , take infinitely long (literally) move 64 steps.

maybe more accurate description worth studying code.

...r


Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Slight Problem with Stepper Motor Controlled by Joystick.


arduino

Comments