A3967 easydriver ver4.4 two stepper motor NEMA17
- Войдите на сайт для отправки комментариев
Вс, 27/04/2014 - 21:41
поругайте код
//art100 20140426 for joystick/usb - arduinouno - A3967 easydriver ver 4.4 2pins - two Stepper Motor(1.8 gradus=1 step) // http://www.aliexpress.com/item/Dual-axis-XY-Joystick-Module-for-Arduino-... // http://www.aliexpress.com/item/5pcs-4-lead-Nema17-Stepper-Motor-42-motor... // http://www.aliexpress.com/item/5pcs-lot-EasyDriver-Stepper-Motor-Driver-... // // pins--------------------------------------- // joystick -------------------------- int joypinx = A0; //joystick pin int joypiny = A1; //joystick pin int joypinf = 10; //joystick pin // lasers leds ---------------- int led3 = 3; //laser red work // stepper motors ------------ int dir_Pin1 = 4;// table int stepPin1 = 5;// int dir_Pin2 = 6;// laser int stepPin2 = 7;// int stepxcor =10;// for correction >0< int stepycor =10;// for correction >0< // constants for scan------------------------------------- int steptable =400;// 3200/8 gear 160/18=8,88 3200 steps full return int speetable =100; //very speed follow int steplaser =1000;// gear 5.22 2000 steps full return int speelaser =20000;//very slow to work int retulaser =100; //very speed return // constants for joystick ------------------------------------------- int sp1table =1000;//slow int sp2table = 100;//speed int sp1laser =1000;//slow int sp2laser = 100;//speed int joyx = 0; //joystick int joyy = 0; //joystick int joyf = 0; //joystick // usb------------------------------ int commandusb = 0; // //--------------------------- void setup() { pinMode(joypinx, INPUT); //joystick X pinMode(joypiny, INPUT); //joystick Y pinMode(joypinf, INPUT_PULLUP); //joystick fire pin pinMode(led3,OUTPUT); //laser // pinMode(led8, OUTPUT);//on shield // pinMode(led9, OUTPUT);//on shield // pinMode(but5,INPUT_PULLUP);//joystickfire digitalWrite(led3, HIGH); //laser to work befor start // digitalWrite(led8, HIGH); //laser to work befor start // digitalWrite(led9, HIGH); //laser to work befor start pinMode(dir_Pin1, OUTPUT);//table pinMode(stepPin1, OUTPUT);//table pinMode(dir_Pin2, OUTPUT);//laser pinMode(stepPin2, OUTPUT);//table Serial.begin(9600); } // stepper motor 1 table for A3987 easydriver 2 pins------------------------------------ void step1(boolean dir1,int steps1,int msec1){ digitalWrite(dir_Pin1,dir1); // direction for(int i=0;i<steps1;i++){ digitalWrite(stepPin1,HIGH); delayMicroseconds(msec1); digitalWrite(stepPin1, LOW); delayMicroseconds(msec1); } } // stepper motor 2 laser for A3987 easydriver 2 pins------------------------------------ void step2(boolean dir2,int steps2,int msec2){ digitalWrite(dir_Pin2,dir2); // direction for(int i=0;i<steps2;i++){ digitalWrite(stepPin2,HIGH); delayMicroseconds(msec2); digitalWrite(stepPin2, LOW); delayMicroseconds(msec2); } } //======================================================================== void loop(){ // joystick ---------------------------------------------------------- joyx = analogRead(joypinx)>>7; // shift 7 0.1.2.3.4.5.6.7 sanks for speed registry shift Dimax joyy = analogRead(joypiny)>>7; // shift 7 0.1.2.3.4.5.6.7 sanks for speed registry shift Dimax // Serial.print('X');Serial.print(joyx);Serial.print(';'); Serial.print('Y');Serial.print(joyy);Serial.println(';'); //test if(joyx==0){step1(false,stepxcor,sp1table);}//speed if(joyx==7){step1(true ,stepxcor,sp1table);}//speed if(joyy==0){step2(false,stepycor,sp2laser);}//speed if(joyy==7){step2(true ,stepycor,sp1laser);}//speed !!! sp1laser !!! slow down // laser and led -------------------------------------------------------- if(digitalRead(joypinf)==LOW) { digitalWrite(led3, LOW); } // laser to work else { digitalWrite(led3,HIGH); } // laser to work // if(digitalRead(joypinf)==LOW) { digitalWrite(led9, LOW); } // led control for test // else { digitalWrite(led9,HIGH); } // led control for test // joystick ---------------------------------------------------------- // usb ---------------------------------------------------------------- if (Serial.available() > 0) { commandusb = Serial.read(); if (commandusb==76 ) {digitalWrite(led3, HIGH);}//digitalWrite(led9, HIGH);} // Laser on L if (commandusb==108) {digitalWrite(led3, LOW);}//digitalWrite(led9, LOW);} // laser off l if (commandusb==47 ) {step2(true, stepxcor,sp2table);} // table / if (commandusb==42 ) {step2(false,stepxcor,sp2table);} // table * if (commandusb==45 ) {step1(true, stepycor,sp2laser);} // laser down+ if (commandusb==43 ) {step1(false,stepycor,sp2laser);} // laser up - //Serial.print("commanda usb received: "); Serial.println(commandusb); } // usb ---------------------------------------------------------------- //.... } //======================================================================== // for L298 4 pins-------------------------- //// for (o=0; o<stepsmotor1; o++) { // 360 gradus table // for (m=0; m<step1Laser/8; m++) { // 200step/8=25step 25step*1.8gradus/step = 45 gradus scanning low // digitalWrite(led3, HIGH); //laser on and down // //myStepper2.step(+1); // step2(true, steptable,speetable); //// delay(100); //for computer tormoz 0,01 sek // delay(500); //for computer tormoz 0,01 sek //// delay(1000); //for computer tormoz 1 sek // } // //return on start // for (m=0; m<step1Laser/8; m++) { // 200step/8=25step 25step*1.8gradus/step = 45 gradus return // digitalWrite(led3, LOW); // //myStepper2.step(-1); // laser up // //myStepper1.step(+1); // table 45 gradus // step2(false,steptable,speetable); // step1(true, steptable,speetable); // } // delay(1000); //for computer tormoz 1 5 sek //------------------------------------------ //DEC Char D Ch D Ch D Ch //0 null 32 sp 64 @ 96 ` //1 33 ! 65 A 97 a //2 34 " 66 B 98 b //3 35 # 67 C 99 c //4 36 $ 68 D 100 d //5 37 % 69 E 101 e //6 38 & 70 F 102 f //7 39 ' 71 G 103 g //8 40 ( 72 H 104 h //9 tab 41 ) 73 I 105 i //10 line 42 * 74 J 106 j //11 43 + 75 K 107 k //12 44 , 76 L 108 l //13 retur 45 - 77 M 109 m //14 46 . 78 N 110 n //15 47 / 79 O 111 o //16 48 0 80 P 112 p //17 49 1 81 Q 113 q //18 50 2 82 R 114 r //19 51 3 83 S 115 s //20 52 4 84 T 116 t //21 53 5 85 U 117 u //22 54 6 86 V 118 v //23 55 7 87 W 119 w //24 56 8 88 X 120 x //25 57 9 89 Y 121 y //26 58 : 90 Z 122 z //27 59 ; 91 [ 123 { //28 60 < 92 \ 124 | //29 61 = 93 ] 125 } //30 62 > 94 ^ 126 ~ //31 63 ? 95 _ 127 //----------------------------------------
начало отладки easydriver http://arduino.ru/forum/apparatnye-voprosy/easydriverver4steppermotors