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 :

Liaison série qui ne fonctionne pas en bluetooth


Sujet :

Arduino

  1. #1
    Membre habitué Avatar de legrandse
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Décembre 2010
    Messages
    350
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Responsable de service informatique

    Informations forums :
    Inscription : Décembre 2010
    Messages : 350
    Points : 149
    Points
    149
    Par défaut Liaison série qui ne fonctionne pas en bluetooth
    Bonjour à tous,

    J'ai un petit soucis pour obtenir une liaison série en bluetooth avec mon Arduino Pro Mini.

    J'utilise le module BT : HC-06

    Je n'ai pas d'erreur mais une fenêtre vide.

    Pour essayer de trouver l'erreur, j'ai testé avec ce script qui me permet bien d'obtenir une liaison série en bluetooth :
    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
     
    int counter = 0;
         unsigned long time;
     
        void setup() {
            Serial.begin(9600); //Module bluetooth par défaut 9600, N, 8, 1
            pinMode(13, OUTPUT);   //Led 13 de témoin OK
        }
     
        void loop() {
            digitalWrite(13, HIGH);   // LED 13 ON
            delay(100);             
            digitalWrite(13, LOW);    // Off
     
            Serial.print("Test module HC-06 bluetooth ");
            Serial.print(++counter);
            Serial.print(" " );
            time = millis();
            Serial.println(time);
            delay(1000);  //Un envoi de données par seconde
        }
    Dans ce cas j'ai bien les données qui s'affichent dans la fenêtre.


    Mais, le problème survient lorsque je veux utiliser mon script qui est celui-ci:

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
     
    // include the library code:
    #include <Keypad.h>
    #include <Wire.h>
    #include "RTClib.h"
     
    //4x4 Matrix key pad
     
    const byte ROWS = 4; // Four rows
    const byte COLS = 3; // Four columns
     
    // buzzer
    const int buzzer = 10; //buzzer to arduino pin 9
     
    //LED
    const int greenPin = 11;
    const int orangePin = 12;
    const int redPin = 13;
     
     
    // Define the Keymap
    char keys[ROWS][COLS] = 
      {
     
      {'1','2','3'},
      {'4','5','6'},
      {'7','8','9'},
      {'*','0','#'}
     
      };
     
    // Connect keypad ROW0, ROW1, ROW2 and ROW3 to
    byte rowPins[ROWS] = { 3, 14, 15, 5 };
     
    // Connect keypad COL0, COL1, COL2 and COL3 to
    byte colPins[COLS] = { 4, 2, 6 }; 
     
    // Create the Keypad
    Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
     
    int incomingByte = 0;   // for incoming serial data
     
     
    RTC_DS3231 rtc;
     
    void setup() 
    {
    #ifndef ESP8266
      while (!Serial); // for Leonardo/Micro/Zero
    #endif
     
     
     
     
    // ------- Broches LED en sorties numériques -------  
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(orangePin, OUTPUT);  
     
    digitalWrite(greenPin,LOW);
    digitalWrite(redPin,LOW);
    digitalWrite(orangePin,LOW);
     
    //buzzer
    pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
     
    Serial.begin(9600);
     
      delay(3000); // wait for console opening
     
      if (! rtc.begin()) {
        Serial.println("Couldn't find RTC");
        digitalWrite(orangePin,HIGH);
        while (1);
      }
     
      if (rtc.lostPower()) {
        Serial.println("RTC lost power, lets set the time!");
        // following line sets the RTC to the date & time this sketch was compiled
        rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
        // This line sets the RTC with an explicit date & time, for example to set
        // January 21, 2014 at 3am you would call:
        // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
      }
     
    }
     
    void loop() 
    {
    DateTime now = rtc.now();
     
     
     
    long int mastercode = a*b*c*e;
    long int admincode = 000000;
        Serial.print("Date:");
        Serial.print(now.year(), DEC);
        Serial.print('/');
        Serial.print(now.month(), DEC);
        Serial.print('/');
        Serial.print(now.day(), DEC);
        Serial.println("\t");
        Serial.print("concat annee:");
     
        Serial.print(a);
        Serial.println("\t");
        Serial.print("concat heure:");
     
        Serial.print(h);
        Serial.println("\t");
     
    Serial.print("master: ");
    Serial.print(mastercode);
    Serial.println("\t");
    char enteredcode[10] ="";
    char *eptr;
    long result;
    // read a 6 digit code (you can have any length)
    for (int i = 0; i <=5; i++){
        char key = kpd.waitForKey();
        if(key == '#'){ // # is used to cancel
        i = 5; //skip to the end
        Serial.println("Cancelled"); // set the other reason why entry failed. You pressed # to cancel if you pressed a wrong number
     
        }
        if(key != NO_KEY){ // if you aren't reading no keypress
          Serial.print(key); // print a # to the LCD so people don't see the number but you know you pressed a button
          char str[2];   // converti char key en char key[2]  
            str[0]=key;
            str[1]='\0';
        tone(buzzer,2000); // Send 1KHz sound signal...
          delay(150);        // 1000 for 1 sec
          noTone(buzzer);     // Stop sound...
          strcat(enteredcode, str);//ajoute un digit à enteredcode.
        }
    }
      result = strtol(enteredcode, &eptr, 10); //converti enteredcode en int
        Serial.println("\t");
        Serial.print("enteredcode: ");
        Serial.print(result);
        Serial.println("\t");
     
     
    if (result == mastercode) //si code correct
       {
       delay(300);
       Serial.println("CODE CORRECT");
       Serial.println("\t");
       tone(buzzer,2000); // Send 1KHz sound signal...
       digitalWrite(greenPin,HIGH); // allume la couleur voulue
       delay(6000); // pause
       digitalWrite(greenPin,LOW); // éteint la couleur voulue
       noTone(buzzer);     // Stop sound...
       }
     
    else if (result == admincode){   //admin code
        delay(300);
        Serial.println("CODE CORRECT");
        Serial.println("\t");
        tone(buzzer,2000); // Send 1KHz sound signal...
        digitalWrite(greenPin,HIGH); // allume la couleur voulue
        delay(3000); // pause
        noTone(buzzer);     // Stop sound...
        digitalWrite(greenPin,LOW); // éteint la couleur voulue
     
      }
     
      else {  // if the code is wrong or cancelled
        // tell the user what happened
        delay(100);
        Serial.println("CODE INCORRECT");
        digitalWrite(redPin,HIGH); // allume la couleur voulue
        tone(buzzer,400,100); // Send 1KHz sound signal...
        delay(110);
        tone(buzzer,400,100); // Send 1KHz sound signal...
        delay(110);
        tone(buzzer,400,100); // Send 1KHz sound signal...
        delay (300);
        digitalWrite(redPin,LOW); // éteint la couleur voulue
        delay (100); // wait 3 seconds before allowing a retry
        Serial.println("ENTER NEW CODE");
        Serial.print("\t");
     
      }
     
    }
    Je ne comprend pas pourquoi la liaison série BT ne m'affiche pas au moins ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    Serial.print("Date:");
        Serial.print(now.year(), DEC);
        Serial.print('/');
        Serial.print(now.month(), DEC);
        Serial.print('/');
        Serial.print(now.day(), DEC);
    Je précise que ma liaison série filaire fonctionne parfaitement et que je débranche bien celle-ci lorsque j'utilise la liaison BT.



    Pouvez-vous m'aider svp

  2. #2
    Membre confirmé
    Avatar de deletme
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    257
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2011
    Messages : 257
    Points : 519
    Points
    519
    Par défaut
    Salut,

    Tu as gardé ta LED qui te fait office de heart byte pour t'assurer que ton programme tourne ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    #ifndef ESP8266
      while (!Serial); // for Leonardo/Micro/Zero
    #endif
    Ne serais tu pas bloquer ici ? car nulle par ESP8266 n'est défini donc ton code compile avec ce while.
    "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
    - Martin Golding
    Traduction obligatoire : "Toujours écrire du code en gardant en tête que le mec qui en assurera la maintenance est un psychopathe violent qui connait votre adresse"

  3. #3
    Membre habitué Avatar de legrandse
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Décembre 2010
    Messages
    350
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Responsable de service informatique

    Informations forums :
    Inscription : Décembre 2010
    Messages : 350
    Points : 149
    Points
    149
    Par défaut
    Merci pour ton aide

    J'ai essayé sans
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    #ifndef ESP8266
      while (!Serial); // for Leonardo/Micro/Zero
    #endif
    Ca ne change rien malheureusement.
    Je vais tester empiriquement pour voir ce qui pose problème.

  4. #4
    Modérateur

    Avatar de Vincent PETIT
    Homme Profil pro
    Consultant en Systèmes Embarqués
    Inscrit en
    Avril 2002
    Messages
    3 190
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Consultant en Systèmes Embarqués
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Avril 2002
    Messages : 3 190
    Points : 11 573
    Points
    11 573
    Par défaut
    Salut,
    Met des traceurs dans ton code et dans les conditions (dans le setup())

    C'est à dire, met un peu partout des Serial.println("trace1"); puis un peu plus loin Serial.println("trace2"); ainsi de suite même dans les conditions.

    Ensuite tu devrais voir où ça plante (entre là où la trace s'arrête et celle qui aurait du être là suivante)

    A+
    La science ne nous apprend rien : c'est l'expérience qui nous apprend quelque chose.
    Richard Feynman

Discussions similaires

  1. Code qui ne fonctionne pas sur Mac
    Par malbaladejo dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 14/01/2005, 11h08
  2. [SQL] Requête à jointure qui ne fonctionne pas
    Par Bensor dans le forum Langage SQL
    Réponses: 2
    Dernier message: 09/12/2004, 16h10
  3. Jointure externe qui ne fonctionne pas
    Par Guizz dans le forum Langage SQL
    Réponses: 3
    Dernier message: 05/02/2004, 12h26
  4. CREATEFILEMAPPING qui ne fonctionne pas???
    Par Jasmine dans le forum MFC
    Réponses: 2
    Dernier message: 06/01/2004, 19h33
  5. UNION qui ne fonctionne pas
    Par r-zo dans le forum Langage SQL
    Réponses: 7
    Dernier message: 21/07/2003, 10h04

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