IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Arduino UNO et HC-06


Sujet :

Arduino

  1. #1
    Membre actif
    Inscrit en
    Juillet 2004
    Messages
    762
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 762
    Points : 230
    Points
    230
    Par défaut Arduino UNO et HC-06
    Bonjour à tous

    je souhaiterai commander une simple lampe LED via une application Android
    qui comporte des "commandes"
    la réponse à ces commandes est sous la forme <t> , <r> etc ....
    malheureusement je n'arrive pas à exécuter ces commandes au travers du croquis test suivant
    car je n'arrive pas traduire ces caractères émis

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    #include <SoftwareSerial.h>
    ///////////////////////// Creates the bluetooth object:
    #define RxD 5 //Pin 5 pour RX (pin0=serial) vert
    #define TxD 6 //Pin 6 pour TX, on peut changer noir
    SoftwareSerial HC06(RxD,TxD);
     
     
    String c_bt; //commande bouton
    String data_bt = ""; 
    char cMaster; // retour
     
    void setup() {
         Serial.begin(9600);
         HC06.begin(115200);
    }
     
    void loop() {
         if (HC06.available()) {
     
            cMaster = 'x';  // retour
            while (HC06.available()) {
               char char_bt = (HC06.read());
               c_bt += char_bt;
              if (cMaster == 'x') {
                    cMaster = char_bt;
              }   
     
            }
     
            data_bt = c_bt.substring(1); 
            Serial.println("data_bt = "+data_bt); 
     
        }
     
        while (cMaster != 'x') 
        {
            if (cMaster == 'u') {
               Serial.println("Commande u active "); 
               cMaster = 'x';
               break;
            }
            if (cMaster == 'r') {
              Serial.println("Commande r active "); 
              cMaster = 'x';
              break;
            }
            if ( cMaster == 't') {
               Serial.println("Commande t active "); 
               cMaster = 'x';
               break;
            }
            if (cMaster == 'm') {
                Serial.println("Commande m active "); 
                cMaster = 'x';
                break;
            }
            if (cMaster == 'e') {
               Serial.println("Commande e active "); 
               cMaster = 'x';
               break;
            }    
            if (cMaster == 'k') {  
              Serial.println("Commande k active "); 
               cMaster = 'x';
               break;          
     
             }
            cMaster = 'x';
            delay(200);
       } 
    }
    pouvez-vous m'aider svp à trouver ce qui ne va pas
    je précise aussi que HC06 est bien reconnu par l'arduino et le tout est correctement appairé


    encore merci par avance
    pascal

  2. #2
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    27
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 27
    Points : 33
    Points
    33
    Par défaut
    Voici un code de test seulement avec le port série dans un premier temps:
    - configurer la vitesse du port série à 9600 et mettre la valeur du combo à 'Pas de fin de ligne'
    - exemple d'utilisation, vous envoyer u1 active u; envoyer u0 cela désative u; idem pour les autres commandes

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    char commande = '\0';
    int donnees = 0;
     
    void setup() {
      Serial1.begin(9600);
     
    }
     
    void loop() {
      if (Serial.available()) {
        commande = Serial.read();
        donnees = Serial.parseInt();
        Serial.print("commande: "); Serial.println(commande);
        Serial.print("donnees: "); Serial.println(donnees);
     
        if (commande == 'u') {
          if (donnees == 0){
            Serial.println("Commande u desactive ");
          }else if (donnees == 1){
            Serial.println("Commande u actif ");
          }
     
        } else if (commande == 'r') {
          if (donnees == 0){
            Serial.println("Commande r desactive ");
          }else if (donnees == 1){
            Serial.println("Commande r actif ");
          }
     
        } else if (commande == 't') {
          if (donnees == 0){
            Serial.println("Commande t desactive ");
          }else if (donnees == 1){
            Serial.println("Commande t actif ");
          }
     
        } else if (commande == 'm') {
          if (donnees == 0){
            Serial.println("Commande m desactive ");
          }else if (donnees == 1){
            Serial.println("Commande m actif ");
          }
     
        } else if (commande == 'e') {
          if (donnees == 0){
            Serial.println("Commande e desactive ");
          }else if (donnees == 1){
            Serial.println("Commande e actif ");
          }
     
        } else if (commande == 'k') {
          if (donnees == 0){
            Serial.println("Commande k desactive ");
          }else if (donnees == 1){
            Serial.println("Commande k actif ");
          }
     
        }
        commande = '\0';
        donnees = 0;
      }
    }


    Code avec le bluetooth (non testé):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    #include <SoftwareSerial.h>
    ///////////////////////// Creates the bluetooth object:
    #define RxD 5 //Pin 5 pour RX (pin0=serial) vert
    #define TxD 6 //Pin 6 pour TX, on peut changer noir
    SoftwareSerial HC06(RxD, TxD);
     
    char commande = '\0';
    int donnees = 0;
     
    void setup() {
      Serial.begin(9600);
      HC06.begin(9600);
    }
     
    void loop() {
      if (HC06.available()) {
        commande = HC06.read();
        donnees = HC06.parseInt();
        Serial.print("commande: "); Serial.println(commande);
        Serial.print("donnees: "); Serial.println(donnees);
     
        if (commande == 'u') {
          if (donnees == 0){
            Serial.println("Commande u desactive ");
          }else if (donnees == 1){
            Serial.println("Commande u actif ");
          }
     
        } else if (commande == 'r') {
          if (donnees == 0){
            Serial.println("Commande r desactive ");
          }else if (donnees == 1){
            Serial.println("Commande r actif ");
          }
     
        } else if (commande == 't') {
          if (donnees == 0){
            Serial.println("Commande t desactive ");
          }else if (donnees == 1){
            Serial.println("Commande t actif ");
          }
     
        } else if (commande == 'm') {
          if (donnees == 0){
            Serial.println("Commande m desactive ");
          }else if (donnees == 1){
            Serial.println("Commande m actif ");
          }
     
        } else if (commande == 'e') {
          if (donnees == 0){
            Serial.println("Commande e desactive ");
          }else if (donnees == 1){
            Serial.println("Commande e actif ");
          }
     
        } else if (commande == 'k') {
          if (donnees == 0){
            Serial.println("Commande k desactive ");
          }else if (donnees == 1){
            Serial.println("Commande k actif ");
          }
     
        }
        commande = '\0';
        donnees = 0;
      }
    }

Discussions similaires

  1. Bluetooth Module Pro et Arduino Uno
    Par benimut2012 dans le forum Arduino
    Réponses: 1
    Dernier message: 07/09/2016, 09h09
  2. Réponses: 6
    Dernier message: 30/08/2016, 14h07
  3. Recyclage de clavier d'ordi portable avec Arduino Uno
    Par jeremygosset dans le forum Arduino
    Réponses: 3
    Dernier message: 24/06/2016, 23h58
  4. arduino uno et xbee
    Par rakiii dans le forum Sécurité
    Réponses: 0
    Dernier message: 12/04/2015, 22h19
  5. Acquisition de signal Labview et Arduino uno
    Par zangetsum dans le forum LabVIEW
    Réponses: 2
    Dernier message: 25/03/2014, 13h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo