Experimentelle Ansteuerung der CUT2000

Aus FabLab Rothenburg
Zur Navigation springen Zur Suche springen

Experimentelle Ansteuerung

CNC mit Arduino ansteuern

Um die Ansteuerung der Leistungselektronik zu testen wurde folgende neben der notwendigen Verkabelung folgender Code verwendet:

   int pin_refX = 11;
   int pin_dirX = 12;    // LOW = Vom Motor weg
   int pin_clkX = 13;
   
   int pin_refY = 08;
   int pin_dirY = 09;    // LOW = Vom Motor weg. Gedreht, eigentlich zum Motor hin.
   int pin_clkY = 10;
   
   int pin_refZ = 05;
   int pin_dirZ = 06;    // LOW = Vom Motor weg
   int pin_clkZ = 07;
   
   int pin_refT = 02;
   int pin_dirT = 03;    // LOW = Vom Motor aus gesehen im Uhrzeigersinn
   int pin_clkT = 04;
   
   int pin_anaX = 00;
   int pin_anaY = 01;
   int pin_anaZ = 02;
   int pin_anaT = 03;
   
   void setup() {
       pinMode(pin_refX, INPUT_PULLUP);
       pinMode(pin_refY, INPUT_PULLUP);
       pinMode(pin_refZ, INPUT_PULLUP);
       pinMode(pin_refT, INPUT_PULLUP);
     
       pinMode(pin_dirX, OUTPUT);
       pinMode(pin_dirY, OUTPUT);
       pinMode(pin_dirZ, OUTPUT);
       pinMode(pin_dirT, OUTPUT);
 
       pinMode(pin_clkX, OUTPUT);
       pinMode(pin_clkY, OUTPUT);
       pinMode(pin_clkZ, OUTPUT);
       pinMode(pin_clkT, OUTPUT);
   }
   
   void driveX(int dir) {
       digitalWrite(pin_dirX, dir);
       digitalWrite(pin_clkX, HIGH);
       delayMicroseconds(1);
       digitalWrite(pin_clkX, LOW);
   }
   
   void driveY(int dir) {
       digitalWrite(pin_dirY, dir);
       digitalWrite(pin_clkY, HIGH);
       delayMicroseconds(1);
       digitalWrite(pin_clkY, LOW);
   }
   
   void driveZ(int dir) {
       digitalWrite(pin_dirZ, !dir); // Achtung, hier Richtung gedreht
       digitalWrite(pin_clkZ, HIGH);
       delayMicroseconds(1);
       digitalWrite(pin_clkZ, LOW);
   }
   
   void driveT(int dir) {
       digitalWrite(pin_dirT, dir);
       digitalWrite(pin_clkT, HIGH);
       delayMicroseconds(1);
       digitalWrite(pin_clkT, LOW);
   }
   
   void loop() {
       analogReference(DEFAULT);
       int anaX = analogRead(pin_anaX);
       int anaY = analogRead(pin_anaY);
       int anaZ = analogRead(pin_anaZ);
       int anaT = analogRead(pin_anaT);
       
       if(anaX < 340) { driveX( LOW); } else if(anaX > 680) { driveX(HIGH); }
       if(anaY < 340) { driveY( LOW); } else if(anaY > 680) { driveY(HIGH); }
       if(anaZ < 340) { driveZ( LOW); } else if(anaZ > 680) { driveZ(HIGH); }
       if(anaT < 340) { driveT(HIGH); } else if(anaT > 680) { driveT( LOW); }
      
       delayMicroseconds(1000); // 1000 als Wert zeigt in sicherer Geschwindigkeit eine bewegung
   }