Partage
  • Partager sur Facebook
  • Partager sur Twitter

Probleme de code Arduino et Processing

ne sais pas d'ou vient l'erreur

    8 janvier 2013 à 12:07:36

    Bonjour a tous ,
    Je suis nouveau sur le Forum , je m'apelle Dylan et j'ai 17 ans.

    Bon alors voila ,

    En ce moment je construit un robot , qui est en fait une base avec deux servomoteurs a l'arriere et une roue folle a l'avant et par dessus est place une pince "OWI ARM" qui utilise 5 moteurs DC(j'utilise aussi des drivers L293D). le tout controler par Bluetooth via mon ordinateur et une carte arduino mega2560.

    Donc pour l'instant je n'ai que la pince , l'arduino Mega2560 et les drivers L293D.

    En ce moment je fais le controle de ma pince (a 5 moteurs) avec ma carte arduino brancher au PC.
    Pour cela j'utilise l'interface Arduino et Processing.

    Mais voila le probleme :
    quand j'upload mon code sur ma carte arduino, ensuite j'ouvre le logiciel processing.
    Je met en route le code (Processing) et quand la fenetre s'ouvre avec les fleches de directions pour controler la pince et que je clique sur une des fleches cela ne fonctionne pas.

    Donc je vous poste les 2 codes et si quelqu'un peux juste m'indiquer ou est l'erreur ou plutot pourquoi cela ne fonctionne pas, sachant je j'ai tester mes moteurs un par un avec ma carte Arduino ?

    Code Arduino :
    int baseMotorEnablePin = 2;
    int baseMotorPin1 = 3;                             
    int baseMotorPin2 = 4;                           
    int shoulderMotorEnablePin = 5;
    int shoulderMotorPin1 = 6;                             
    int shoulderMotorPin2 = 7; 
    int elbowMotorEnablePin = 11;
    int elbowMotorPin1 = 12;                             
    int elbowMotorPin2 = 13;                           
    int wristMotorEnablePin = A0;
    int wristMotorPin1 = A1;                             
    int wristMotorPin2 = A2;
    int handMotorEnablePin = 8;
    int handMotorPin1 = 9;
    int handMotorPin2 = 10;
    int LedBlanche = 52;
    
    // set a variable to store the byte sent from the serial port
    int incomingByte;
     
    void setup() {
      // set the SN754410 pins as outputs:
      pinMode(baseMotorPin1, OUTPUT);
      pinMode(baseMotorPin2, OUTPUT);
      pinMode(baseMotorEnablePin, OUTPUT);
      digitalWrite(baseMotorEnablePin, HIGH);
      pinMode(shoulderMotorPin1, OUTPUT);
      pinMode(shoulderMotorPin2, OUTPUT);
      pinMode(shoulderMotorEnablePin, OUTPUT);
      digitalWrite(shoulderMotorEnablePin, HIGH);
      pinMode(elbowMotorPin1, OUTPUT);
      pinMode(elbowMotorPin2, OUTPUT);
      pinMode(elbowMotorEnablePin, OUTPUT);
      digitalWrite(elbowMotorEnablePin, HIGH);
      pinMode(wristMotorPin1, OUTPUT);
      pinMode(wristMotorPin2, OUTPUT);
      pinMode(wristMotorEnablePin, OUTPUT);
      digitalWrite(wristMotorEnablePin, HIGH);
      pinMode(handMotorPin1, OUTPUT);
      pinMode(handMotorPin2, OUTPUT);
      pinMode(handMotorEnablePin, OUTPUT);
      digitalWrite(handMotorEnablePin, HIGH);
      pinMode(LedBlanche, OUTPUT);
      
      Serial.begin(9600);
    }
     
    void loop() {
    
      if (Serial.available() > 0) {
        
        incomingByte = Serial.read();
    
        if (incomingByte == 'Q') {
        digitalWrite(baseMotorPin1, LOW);   
        digitalWrite(baseMotorPin2, HIGH);
        digitalWrite(LedBlanche, LOW);    
        } 
        if (incomingByte == 'W') {
        digitalWrite(baseMotorPin1, HIGH);   
        digitalWrite(baseMotorPin2, LOW);
        digitalWrite(LedBlanche, LOW);    
        }
        if (incomingByte == 'E') {
        digitalWrite(shoulderMotorPin1, LOW);   
        digitalWrite(shoulderMotorPin2, HIGH); 
        digitalWrite(LedBlanche, LOW);   
        } 
        if (incomingByte == 'R') {
        digitalWrite(shoulderMotorPin1, HIGH);   
        digitalWrite(shoulderMotorPin2, LOW);
        digitalWrite(LedBlanche, LOW);    
        }
        if (incomingByte == 'A') {
        digitalWrite(elbowMotorPin1, LOW);   
        digitalWrite(elbowMotorPin2, HIGH);
        digitalWrite(LedBlanche, LOW);    
        } 
        if (incomingByte == 'S') {
        digitalWrite(elbowMotorPin1, HIGH);   
        digitalWrite(elbowMotorPin2, LOW);
        digitalWrite(LedBlanche, LOW);    
        }
        if (incomingByte == 'D') {
        digitalWrite(wristMotorPin1, LOW);   
        digitalWrite(wristMotorPin2, HIGH); 
        digitalWrite(LedBlanche, HIGH);  
        } 
        if (incomingByte == 'F') {
        digitalWrite(wristMotorPin1, HIGH);   
        digitalWrite(wristMotorPin2, LOW);
        digitalWrite(LedBlanche, HIGH); 
        }
        if (incomingByte == 'Z') {
        digitalWrite(handMotorPin1, LOW);   
        digitalWrite(handMotorPin2, HIGH);
        digitalWrite(LedBlanche, LOW);    
        } 
        if (incomingByte == 'X') {
        digitalWrite(handMotorPin1, HIGH);   
        digitalWrite(handMotorPin2, LOW);
        digitalWrite(LedBlanche, LOW);  
        }
       
        if (incomingByte == 'O') {
        digitalWrite(baseMotorPin1, LOW);   
        digitalWrite(baseMotorPin2, LOW);  
        digitalWrite(shoulderMotorPin1, LOW);   
        digitalWrite(shoulderMotorPin2, LOW); 
        digitalWrite(elbowMotorPin1, LOW);   
        digitalWrite(elbowMotorPin2, LOW);  
        digitalWrite(wristMotorPin1, LOW);   
        digitalWrite(wristMotorPin2, LOW); 
        digitalWrite(handMotorPin1, LOW);   
        digitalWrite(handMotorPin2, LOW);
        digitalWrite(LedBlanche, LOW);  
        }
      }
    }
    


    Code Processing
    int controls[13] = { 0x47, 0x67, 0x57, 0x77, 0x45, 0x65, 
                       0x53, 0x73, 0x42, 0x62, 0x4c, 0x6c, 0x58 };
    
    // Base
    int baseEnablePin = 3;
    int basePin1      = 16;
    int basePin2      = 17;
    
    // Shoulder
    int shoulderEnablePin = 14;
    int shoulderPin1      = 2;
    int shoulderPin2      = 4;
    
    // Elbow
    int elbowEnablePin = 6;
    int elbowPin1      = 7;
    int elbowPin2      = 15;
    
    // Wrist
    int wristEnablePin = 11;
    int wristPin1      = 8;
    int wristPin2      = 12;
    
    //Grip
    int gripEnablePin = 10;
    int gripPin1      = 9;
    int gripPin2      = 5; 
    
    int ledPin = 13;
    
    // set a variable to store the byte sent from the serial port
    int incomingByte;
    
    void setup() {
      // set light LED 
      pinMode(ledPin, OUTPUT);
      digitalWrite(ledPin, LOW);
      
      // set the SN754410 pins as outputs:
      pinMode(basePin1, OUTPUT);
      pinMode(basePin2, OUTPUT);
      pinMode(baseEnablePin, OUTPUT);
      
      pinMode(shoulderPin1, OUTPUT);
      pinMode(shoulderPin2, OUTPUT);
      pinMode(shoulderEnablePin, OUTPUT);
      
      pinMode(elbowPin1, OUTPUT);
      pinMode(elbowPin2, OUTPUT);
      pinMode(elbowEnablePin, OUTPUT);
      
      pinMode(wristPin1, OUTPUT);
      pinMode(wristPin2, OUTPUT);
      pinMode(wristEnablePin, OUTPUT);
      
      pinMode(gripPin1, OUTPUT);
      pinMode(gripPin2, OUTPUT);
      pinMode(gripEnablePin, OUTPUT);
      
      // start sending data at 115200 baud rate
      // I set my Xbee Baud Rate at 115200 bps,
      // change the Baud Rate according to your XBee
      Serial.begin(115200);
    }
    
    void loop() {
        // check that there's something in the serial buffer
      if (Serial.available() > 0) {
        // read the byte and store it in our variable 
        // the byte sent is actually an ascii value
        incomingByte = Serial.read();
        // note the upper casing of each letter!
        // each letter turns a motor different way.
        
        //===== Grip
        // Grip in
        if (incomingByte == controls[0]) {
          gripIn();
        }
        // Grip Out
        if (incomingByte == controls[1]) {  
          gripOut();
        } 
        
        //Wrist
        if (incomingByte == controls[2]) {
        //digitalWrite(wristPin1, LOW);   
        //digitalWrite(wristPin2, HIGH);  
        wristUp();
        } 
        if (incomingByte == controls[3]) {    
          wristDown();
        }
        
        //===== Elbow
        // Elbow Up
        if (incomingByte == controls[4]) {
          elbowUp(); 
        }
        // Elbow Down
        if (incomingByte == controls[5]) {
          elbowDown();
        }
        
        //===== Shoulder
        // Shoulder Up
        if (incomingByte == controls[6]) {
          shoulderUp();
        }
        // Shoulder Down
        if (incomingByte == controls[7]) { 
          shoulderDown();
        }
        
        //===== Base
        // Base Right
        if (incomingByte == controls[8]) {
          baseRight();  
        }
        // Base Left
        if (incomingByte == controls[9]) {
          baseLeft();
        }
    
        // Light ON
        if (incomingByte == controls[10]) {
          digitalWrite(ledPin, HIGH);
        }
        // Light OFF
        if (incomingByte == controls[11]) {
          digitalWrite(ledPin, LOW);
        }
        
        // if a O is sent make sure the motors are turned off
        if (incomingByte == controls[12]) {
          allStop();
        }
        
        delay(100);
      }
    }
    
    void gripIn() {
        digitalWrite(gripEnablePin, HIGH);
        digitalWrite(gripPin1, LOW);
        digitalWrite(gripPin2, HIGH);
    }
    
    void gripOut() {
        digitalWrite(gripEnablePin, HIGH);
        digitalWrite(gripPin2, LOW);
        digitalWrite(gripPin1, HIGH);
    }
    
    void wristUp() {
        digitalWrite(wristEnablePin, HIGH);
        digitalWrite(wristPin1, LOW);
        digitalWrite(wristPin2, HIGH);
    }
    
    void wristDown() {
        digitalWrite(wristEnablePin, HIGH);
        digitalWrite(wristPin2, LOW);
        digitalWrite(wristPin1, HIGH);
    }
    
    void elbowUp() {
        digitalWrite(elbowEnablePin, HIGH);
        digitalWrite(elbowPin1, LOW);
        digitalWrite(elbowPin2, HIGH);
    }
    
    void elbowDown() {
        digitalWrite(elbowEnablePin, HIGH);
        digitalWrite(elbowPin2, LOW);
        digitalWrite(elbowPin1, HIGH);
    }
    
    void shoulderUp() {
        digitalWrite(shoulderEnablePin, HIGH);
        digitalWrite(shoulderPin1, LOW);
        digitalWrite(shoulderPin2, HIGH);
    }
    
    void shoulderDown() {
        digitalWrite(shoulderEnablePin, HIGH);
        digitalWrite(shoulderPin2, LOW);
        digitalWrite(shoulderPin1, HIGH);
    }
    
    void baseRight() {
        digitalWrite(baseEnablePin, HIGH);
        digitalWrite(basePin1, LOW);
        digitalWrite(basePin2, HIGH);
    }
    
    void baseLeft() {
        digitalWrite(baseEnablePin, HIGH);
        digitalWrite(basePin2, LOW);
        digitalWrite(basePin1, HIGH);
    }
    
    void allStop() {
        digitalWrite(baseEnablePin, LOW);
        digitalWrite(basePin1, LOW);   
        digitalWrite(basePin2, LOW);
        
        digitalWrite(shoulderEnablePin, LOW);
        digitalWrite(shoulderPin1, LOW);   
        digitalWrite(shoulderPin2, LOW); 
        
        digitalWrite(elbowEnablePin, LOW);
        digitalWrite(elbowPin1, LOW);   
        digitalWrite(elbowPin2, LOW);  
        
        digitalWrite(wristEnablePin, LOW);
        digitalWrite(wristPin1, LOW);   
        digitalWrite(wristPin2, LOW); 
        
        digitalWrite(gripEnablePin, LOW);
        digitalWrite(gripPin1, LOW);   
        digitalWrite(gripPin2, LOW); 
    }
    


    Merci d'avance pour vos reponses !
    • Partager sur Facebook
    • Partager sur Twitter
      8 janvier 2013 à 13:28:36

      Euh ton code "Processing" devrait plutôt se trouver dans l'arduino en fait.

      Processing c'est un langage de programmation comme le C, le java, etc.
      Donc dire "digitalWrite(...)" à ton ordinateur je doute qu'il comprenne.
      Ton programme processing présent sur ton PC doit juste servir à récupérer les touches que tu tapes et à envoyer cette information en bluetooth à l'Arduino.

      Or là tu semble faire du traitement qui doit être présent sur l'Arduino.
      • Partager sur Facebook
      • Partager sur Twitter

      Probleme de code Arduino et Processing

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown