Run stepper motor continiously with easydriver


hi all,

i've been trying run stepper motor easydriver driver. im using analog joystic input.
i want run stepper long joystick engaged, , let speed function of joystick position. above 512 forewards , belowe backwards. (i know dc motor better suited, need override function on project.)
i know connections ok, since setup running normaly on "sex , cigar" setup page https://www.norwegiancreations.com/2014/12/arduino-tutorial-stepper-motor-with-easydriver/

could point out whats wrong/missing in code?
arduino uno r3
ide 1.8.3



code: [select]

int stick = a0;
int val = 0;
int dir = 3;
int stp = 4;
int enb = 5;
int smdirectionpin = 2; //direction pin
int smsteppin = 3; //stepper pin
int smenablepin = 7; //motor enable pin
const int stepsperrevolution = 200;

void setup() {

  pinmode(smdirectionpin, output);
  pinmode(smsteppin, output);
  pinmode(smenablepin, output);
  pinmode(stick, input);
  digitalwrite(smenablepin, high); //disables motor, can rest untill called uppond
  serial.begin(9600);     
}

 
void loop()  {

val = analogread(stick);
dir = digitalread(smdirectionpin);
stp = digitalread(smsteppin);
enb = digitalread(smenablepin);
serial.print(val);
serial.print("  ");
serial.print(dir);
serial.print("  ");
serial.print(stp);
serial.print("  ");
serial.println(enb);

//int speed = map(stick, 0, 1023, 0, 100);
//int step = map(stick, 0, 1023, 0, 50);

 if (serial.available()>9) {
val = serial.read();
  if (val > 562 ) {
digitalwrite(smenablepin, low);
digitalwrite(smdirectionpin, high);
digitalwrite(smsteppin, high);
delay(1000);

  }
 
else if (val < 462 ) {
digitalwrite(smenablepin, low);
digitalwrite(smdirectionpin, low);
digitalwrite(smsteppin, high);
delay(1000);
 }
 
else  {
digitalwrite(smenablepin, high);
  }
}
}

you using 'val' when read serial, not value joystick. if want act on joystick value, put code after 'if (serial.available()' statement, not inside it.


Arduino Forum > Using Arduino > Programming Questions > Run stepper motor continiously with easydriver


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts