CNC drawing machine with joysticks
CNC drawing machine controlled by joysticks .
Components and supplies
1
Arduino UNO
3
NEMA 17 Stepper Motor
2
Analog joystick (Generic)
3
Stepper motor driver board A4988
3
Capacitor 47 µF
6
LED (generic)
6
Resistor 1k ohm
Project description
Code
CNC drawing machine
c_cpp
1// 10/08/2017 - Programme C - Traceur X Y commande par joystick 2// MATERIEL : 3 moteurs pas a pas NEMA 17 3// 3 drivers A4988 4// 1 alimentation 12 V 1A + alimentation arduino 5// resistances 6// 6 leds 7// Ce programme a pour objectif de : 8// - commander les moteurs pas a pas avec les joysticks pour ecrire sur un support papier 9// - lorsqu'un fin de course est actionné, une led s'allume et le joystick ne permet plus d'aller dans la direction du fin de course 10// 11// Programme réalisé par Techno_Fabrik 12 13//********************BIBLIOTHEQUES**************************** 14//********************DECLARATIONS**************************** 15 16int A4988_pas2 = 6; // moteur pas a pas nema 17 commande par le pas ( nombre de tours ) et la direction ( HIGH ou LOW) 17int A4988_direction2 = 7; 18int A4988_pas = 9; 19int A4988_direction = 10; 20int A4988_pas1 = 11; 21int A4988_direction1 = 12; 22int joystick1,joystick2,joystick3;// valeur des joysticks 23int findecourseGD, findecourseHB, findecoursestylo; 24int findecourseHB_bug_H=0, findecourseHB_bug_B=0, findecoursestylo_bug_B=0, findecoursestylo_bug_H=0, findecourseGD_bug_G=0, findecourseGD_bug_D=0; // permet de ne pas prendre en compte les faux contacts 25 26 27 28 //********************SETUP*********************************** 29void setup() // On initialise les pins 2 et 3 en sortie 30{ 31pinMode(A4988_pas,OUTPUT); 32pinMode(A4988_direction,OUTPUT); 33pinMode(A4988_pas1,OUTPUT); 34pinMode(A4988_direction1,OUTPUT); 35pinMode(A4988_pas2,OUTPUT); 36pinMode(A4988_direction2,OUTPUT); 37Serial.begin(250000); 38} 39 40//************************** FONCTIONS *********************************** 41 42// *********** BLOQUER LE MOTEUR LORS DE L'ACTIVATION DES FIN DE COURSE ******************* 43 44int fdcbug (int x,int fdc, int mini, int maxi)// fonction permettant d'éviter les faux contacts 45{ 46 if ( (fdc>mini) && (fdc < maxi) ) 47 { 48 x = 30; 49 } 50 else 51 { 52 x = x-1; 53 if (x<0) x=0; 54 } 55 return x; 56} 57 58int interrupteur_max (int fdc_bug, int joystick, int joystickmax) 59{ 60 if (fdc_bug>1) 61 { 62 if ( joystick>joystickmax ) 63 { 64 joystick = joystickmax; 65 } 66 } 67 return joystick; 68} 69int interrupteur_min (int fdc_bug, int joystick, int joystickmin) 70{ 71 if (fdc_bug>1) 72 { 73 if ( joystick<joystickmin ) 74 { 75 joystick = joystickmin; 76 } 77 } 78 return joystick; 79} 80 81 82// *********** COMMANDER LES MOTEURS GRACE AUX JOYSTICKS ******************* 83 84void moteur ( int J, int J_min, int J_max, int dir_pap, int step_pap ) 85{ 86 if( J > J_max) 87 { 88 digitalWrite(dir_pap,HIGH); 89 for(int x = 0; x < 1; x++) 90 { // Permet de faire un PAS à une certaine allure. Pour tourner plus vite, changer le delay jusqu'à 1 , pour ralentir, le changer jusqu'à 30 91 digitalWrite(step_pap,HIGH); // On fait un tour avec 200 pas pour le Nema 17 92 delay(5); 93 digitalWrite(step_pap,LOW); 94 delay(5); 95 96 } 97 } 98 if( J < J_min) 99 { 100 digitalWrite(dir_pap,LOW); 101 for(int x = 0; x < 1; x++) 102 { // Permet de faire un PAS à une certaine allure. Pour tourner plus vite, changer le delay jusqu'à 1 , pour ralentir, le changer jusqu'à 30 103 digitalWrite(step_pap,HIGH); // On fait un tour avec 200 pas pour le Nema 17 104 delay(5); 105 digitalWrite(step_pap,LOW); 106 delay(5); 107 108 } 109 } 110} 111 112 113 114// **************************** BOUCLE ************************** 115 116void loop() { 117// *********** LECTURE DES ENTREE ANALOGIQUES : joystick + capteur de fin de course *************** 118 119 joystick1=analogRead(A0); 120 joystick1=map(joystick1,0,525,0,100); 121 joystick2=analogRead(A1); 122 joystick2=map(joystick2,0,525,0,100); 123 joystick3=analogRead(A2); 124 joystick3=map(joystick3,290,1025,0,100);//5 95 125 findecourseGD=analogRead(A3); 126 findecourseHB=analogRead(A4); 127 findecoursestylo=analogRead(A5); 128 129// *********** BLOQUER LE MOTEUR LORS DE L'ACTIVATION DES FIN DE COURSE ******************* 130 131findecoursestylo_bug_H= fdcbug(findecoursestylo_bug_H,findecoursestylo,300,500); 132findecoursestylo_bug_B=fdcbug(findecoursestylo_bug_B,findecoursestylo,15,300); 133joystick3=interrupteur_max(findecoursestylo_bug_H,joystick3,59); 134joystick3=interrupteur_min(findecoursestylo_bug_B, joystick3,11); 135 136 137findecourseGD_bug_D= fdcbug(findecourseGD_bug_D,findecourseGD,100,200); 138findecourseGD_bug_G= fdcbug(findecourseGD_bug_G,findecourseGD,230,500); 139joystick2=interrupteur_max(findecourseGD_bug_G,joystick2,65); 140joystick2=interrupteur_min(findecourseGD_bug_D,joystick2,65); 141findecourseHB_bug_H= fdcbug(findecourseHB_bug_H,findecourseHB,200,500); 142findecourseHB_bug_B= fdcbug(findecourseHB_bug_B,findecourseHB,30,200); 143joystick1=interrupteur_max(findecourseHB_bug_H,joystick1,65); 144joystick1=interrupteur_min(findecourseHB_bug_B,joystick1,65); 145 146// *********** COMMANDER LES MOTEURS GRACE AUX JOYSTICKS ******************* 147 148moteur(joystick3,10,60,A4988_direction2,A4988_pas2); 149moteur(joystick1,40,80,A4988_direction,A4988_pas); 150moteur(joystick2,40,80,A4988_direction1,A4988_pas1); 151 152}
CNC drawing machine
c_cpp
1// 10/08/2017 - Programme C - Traceur X Y commande par joystick 2// MATERIEL : 3 moteurs pas a pas NEMA 17 3// 3 drivers A4988 4// 1 alimentation 12 V 1A + alimentation arduino 5// resistances 6// 6 leds 7// Ce programme a pour objectif de : 8// - commander les moteurs pas a pas avec les joysticks pour ecrire sur un support papier 9// - lorsqu'un fin de course est actionné, une led s'allume et le joystick ne permet plus d'aller dans la direction du fin de course 10// 11// Programme réalisé par Techno_Fabrik 12 13//********************BIBLIOTHEQUES**************************** 14//********************DECLARATIONS**************************** 15 16int A4988_pas2 = 6; // moteur pas a pas nema 17 commande par le pas ( nombre de tours ) et la direction ( HIGH ou LOW) 17int A4988_direction2 = 7; 18int A4988_pas = 9; 19int A4988_direction = 10; 20int A4988_pas1 = 11; 21int A4988_direction1 = 12; 22int joystick1,joystick2,joystick3;// valeur des joysticks 23int findecourseGD, findecourseHB, findecoursestylo; 24int findecourseHB_bug_H=0, findecourseHB_bug_B=0, findecoursestylo_bug_B=0, findecoursestylo_bug_H=0, findecourseGD_bug_G=0, findecourseGD_bug_D=0; // permet de ne pas prendre en compte les faux contacts 25 26 27 28 //********************SETUP*********************************** 29void setup() // On initialise les pins 2 et 3 en sortie 30{ 31pinMode(A4988_pas,OUTPUT); 32pinMode(A4988_direction,OUTPUT); 33pinMode(A4988_pas1,OUTPUT); 34pinMode(A4988_direction1,OUTPUT); 35pinMode(A4988_pas2,OUTPUT); 36pinMode(A4988_direction2,OUTPUT); 37Serial.begin(250000); 38} 39 40//************************** FONCTIONS *********************************** 41 42// *********** BLOQUER LE MOTEUR LORS DE L'ACTIVATION DES FIN DE COURSE ******************* 43 44int fdcbug (int x,int fdc, int mini, int maxi)// fonction permettant d'éviter les faux contacts 45{ 46 if ( (fdc>mini) && (fdc < maxi) ) 47 { 48 x = 30; 49 } 50 else 51 { 52 x = x-1; 53 if (x<0) x=0; 54 } 55 return x; 56} 57 58int interrupteur_max (int fdc_bug, int joystick, int joystickmax) 59{ 60 if (fdc_bug>1) 61 { 62 if ( joystick>joystickmax ) 63 { 64 joystick = joystickmax; 65 } 66 } 67 return joystick; 68} 69int interrupteur_min (int fdc_bug, int joystick, int joystickmin) 70{ 71 if (fdc_bug>1) 72 { 73 if ( joystick<joystickmin ) 74 { 75 joystick = joystickmin; 76 } 77 } 78 return joystick; 79} 80 81 82// *********** COMMANDER LES MOTEURS GRACE AUX JOYSTICKS ******************* 83 84void moteur ( int J, int J_min, int J_max, int dir_pap, int step_pap ) 85{ 86 if( J > J_max) 87 { 88 digitalWrite(dir_pap,HIGH); 89 for(int x = 0; x < 1; x++) 90 { // Permet de faire un PAS à une certaine allure. Pour tourner plus vite, changer le delay jusqu'à 1 , pour ralentir, le changer jusqu'à 30 91 digitalWrite(step_pap,HIGH); // On fait un tour avec 200 pas pour le Nema 17 92 delay(5); 93 digitalWrite(step_pap,LOW); 94 delay(5); 95 96 } 97 } 98 if( J < J_min) 99 { 100 digitalWrite(dir_pap,LOW); 101 for(int x = 0; x < 1; x++) 102 { // Permet de faire un PAS à une certaine allure. Pour tourner plus vite, changer le delay jusqu'à 1 , pour ralentir, le changer jusqu'à 30 103 digitalWrite(step_pap,HIGH); // On fait un tour avec 200 pas pour le Nema 17 104 delay(5); 105 digitalWrite(step_pap,LOW); 106 delay(5); 107 108 } 109 } 110} 111 112 113 114// **************************** BOUCLE ************************** 115 116void loop() { 117// *********** LECTURE DES ENTREE ANALOGIQUES : joystick + capteur de fin de course *************** 118 119 joystick1=analogRead(A0); 120 joystick1=map(joystick1,0,525,0,100); 121 joystick2=analogRead(A1); 122 joystick2=map(joystick2,0,525,0,100); 123 joystick3=analogRead(A2); 124 joystick3=map(joystick3,290,1025,0,100);//5 95 125 findecourseGD=analogRead(A3); 126 findecourseHB=analogRead(A4); 127 findecoursestylo=analogRead(A5); 128 129// *********** BLOQUER LE MOTEUR LORS DE L'ACTIVATION DES FIN DE COURSE ******************* 130 131findecoursestylo_bug_H= fdcbug(findecoursestylo_bug_H,findecoursestylo,300,500); 132findecoursestylo_bug_B=fdcbug(findecoursestylo_bug_B,findecoursestylo,15,300); 133joystick3=interrupteur_max(findecoursestylo_bug_H,joystick3,59); 134joystick3=interrupteur_min(findecoursestylo_bug_B, joystick3,11); 135 136 137findecourseGD_bug_D= fdcbug(findecourseGD_bug_D,findecourseGD,100,200); 138findecourseGD_bug_G= fdcbug(findecourseGD_bug_G,findecourseGD,230,500); 139joystick2=interrupteur_max(findecourseGD_bug_G,joystick2,65); 140joystick2=interrupteur_min(findecourseGD_bug_D,joystick2,65); 141findecourseHB_bug_H= fdcbug(findecourseHB_bug_H,findecourseHB,200,500); 142findecourseHB_bug_B= fdcbug(findecourseHB_bug_B,findecourseHB,30,200); 143joystick1=interrupteur_max(findecourseHB_bug_H,joystick1,65); 144joystick1=interrupteur_min(findecourseHB_bug_B,joystick1,65); 145 146// *********** COMMANDER LES MOTEURS GRACE AUX JOYSTICKS ******************* 147 148moteur(joystick3,10,60,A4988_direction2,A4988_pas2); 149moteur(joystick1,40,80,A4988_direction,A4988_pas); 150moteur(joystick2,40,80,A4988_direction1,A4988_pas1); 151 152}
Downloadable files
CNC machine
The fritzing CNC machine
CNC machine

Comments
Only logged in users can leave comments