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 :

Projet de Terminale : Contrôle bluetooth d'un moteur


Sujet :

Arduino

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Février 2020
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Février 2020
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Projet de Terminale : Contrôle bluetooth d'un moteur
    Bonjour,

    Je suis en terminale et pour notre projet de fin d'année, nous avons choisis de créer une serrure biométrique avec Arduino. Maintenant, je voudrais ajouter un contrôle bluetooth, c'est à dire que, lorsque le moteur ne tourne pas, il soit possible d'ouvrir la porte avec le mot "Ouvrir" envoyé depuis le téléphone. J'utilise le module Serial Bluetooth de Grove.
    Maintenant, après de nombreuses heures d'essais, je n'ai toujours pas trouvé pourquoi le programme ne fonctionne pas. A ce stade, j'essaie juste de faire apparaître les mots entrés dans le téléphone dans la console.
    Quelqu'un pour m'aider ?
    Merci d'avance

    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
     
    int PWMA = 11;
    int DIRA = 13;
    #include <Adafruit_Fingerprint.h>
    #include <SoftwareSerial.h>
    #include<MsTimer2.h>
    #define RxD 6
    #define TxD 7
    #define DEBUG_ENABLED  1
    SoftwareSerial mySerial(2, 3);
    SoftwareSerial BLE(RxD, TxD);
    Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
     
     
    void setupBleConnection()
    {
      BLE.begin(9600); //Set BLE BaudRate to default baud rate 9600
      delay(1000);
      BLE.print("AT+CLEAR"); //clear all previous setting
      delay(3000);
      BLE.print("AT+ROLE0"); //set the bluetooth name as a slaver
      delay(2000);
      BLE.print("AT+SAVE1");  //don't save the connect information
      delay(2000);
    }
    void setup()  {
     
      pinMode (DIRA, OUTPUT); 
      Serial.begin(9600);
      delay(100);
      pinMode(RxD, INPUT);
      pinMode(TxD, OUTPUT);
      setupBleConnection();
      Serial.println("\n\nAdafruit finger detect test");
      finger.begin(57600);
      delay(5);
      finger.getTemplateCount();
      Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
      Serial.println("Waiting for valid finger...");
    }
     
    void bluetooth()
    {
     char recvChar;
      while (1) {
        if (BLE.available()) { //check if there's any data sent from the remote BLE
          recvChar = BLE.read();
          Serial.print(recvChar);
        }
        if (Serial.available()) { //check if there's any data sent from the local serial terminal, you can add the other applications here
          recvChar  = Serial.read();
          BLE.print(recvChar);
        }
      }
    }
    char recvChar;
    void loop() {
        delay(50);
        if (BLE.available()) { //check if there's any data sent from the remote BLE
          recvChar = BLE.read();
          Serial.print(recvChar);
        }
        if (Serial.available()) { //check if there's any data sent from the local serial terminal, you can add the other applications here
          recvChar  = Serial.read();
          BLE.print(recvChar);
      }
      getFingerprintIDez();
    }
     
      uint8_t getFingerprintID() {
        uint8_t p = finger.getImage();
        switch (p) {
          case FINGERPRINT_OK:
            Serial.println("Image taken");
            break;
          case FINGERPRINT_NOFINGER:
            Serial.println("No finger detected");
            return p;
          case FINGERPRINT_PACKETRECIEVEERR:
            Serial.println("Communication error");
            return p;
          case FINGERPRINT_IMAGEFAIL:
            Serial.println("Imaging error");
            return p;
          default:
            Serial.println("Unknown error");
            return p;
        }
        p = finger.image2Tz();
        switch (p) {
          case FINGERPRINT_OK:
            Serial.println("Image converted");
            break;
          case FINGERPRINT_IMAGEMESS:
            Serial.println("Image too messy");
            return p;
          case FINGERPRINT_PACKETRECIEVEERR:
            Serial.println("Communication error");
            return p;
          case FINGERPRINT_FEATUREFAIL:
            Serial.println("Could not find fingerprint features");
            return p;
          case FINGERPRINT_INVALIDIMAGE:
            Serial.println("Could not find fingerprint features");
            return p;
          default:
            Serial.println("Unknown error");
            return p;
        }
     
        // OK converted!
        p = finger.fingerFastSearch();
        if (p == FINGERPRINT_OK) {
          Serial.println("Found a print match!");
        } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
          Serial.println("Communication error");
          return p;
        } else if (p == FINGERPRINT_NOTFOUND) {
          Serial.println("Did not find a match");
          return p;
        } else {
          Serial.println("Unknown error");
          return p;
        }
     
        Serial.print("Found ID #"); Serial.print(finger.fingerID);
        Serial.print(" with confidence of "); Serial.println(finger.confidence);
     
        return finger.fingerID;
      }
     
      int getFingerprintIDez() {
        uint8_t p = finger.getImage();
        if (p != FINGERPRINT_OK)  return -1;
     
        p = finger.image2Tz();
        if (p != FINGERPRINT_OK)  return -1;
     
        p = finger.fingerFastSearch();
        if (p != FINGERPRINT_OK)  return -1;
     
        Serial.print("Found ID #"); Serial.print(finger.fingerID);
        Serial.print(" with confidence of "); Serial.println(finger.confidence);
        digitalWrite(DIRA, 1);
        analogWrite(PWMA, 255);
        delay(200);
        int(a) = 0;
        while (a < 25) {
          analogWrite(0, 0);
          delay(0.02);
          a = analogRead(1);
          char recvChar;
          recvChar = BLE.read();
          Serial.println(recvChar);
            if (BLE.available()) { //check if there's any data sent from the remote BLE
            recvChar = BLE.read();
            if (recvChar="stop"){
              break;}
          }
        }
        digitalWrite(PWMA, 0);
        delay(6000);
        digitalWrite(DIRA, 0);
        analogWrite(PWMA, 255);
        delay(400);
        a = 0;
        while (a < 25) {
          a = analogRead(1);
          Serial.println(a);
        }
        digitalWrite(PWMA, 0);
        return finger.fingerID;
      }

  2. #2
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 685
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 685
    Points : 5 328
    Points
    5 328
    Par défaut
    vous allez au devant d'ennuis car vous essayez d'utiliser 2 ports séries virtuels avec la bibliothèque SoftwareSerial.

    c'est possible (cf la doc et l'exemple TwoPortReceive) mais il faut basculer manuellement entre les 2 ports à écouter et c'est pas super stable s'il y a bcp de données qui arrivent

    soit vous basculez sur un Arduino qui a plus de ports série matériels, comme une MEGA par exemple et vous utilisez Serial1 pour l'empreinte digitale et Serial2 pour le bluetooth, ce sera bien robuste et simple.

    Soit vous restez sur l'architecture actuelle (un UNO j'imagine ?) et vous ne pouvez plus utiliser l'interface série pour débug et vous connectez un des deux modules sur les pins 0 et 1 qui correspondent à Serial. (il faudra les débrancher pendant que vous téléchargez du code). Vous aurez donc un port Série physique en matériel (Serial) et vous pourrez en créer un virtuel (prenez le module qui aura le plus bas débit en bauds pour le virtuel).

Discussions similaires

  1. Réponses: 2
    Dernier message: 07/11/2016, 04h26
  2. Besoin d'aide pour notre projet de Terminale
    Par Martalex dans le forum Débuter
    Réponses: 2
    Dernier message: 25/03/2016, 17h48
  3. Projet Mastermind Terminale S ISN
    Par jojodu30 dans le forum Général Python
    Réponses: 9
    Dernier message: 27/05/2015, 13h28
  4. [Python 3.X] IMPORTANT - Aide Scrabble Projet ISN Terminale S
    Par Batmai dans le forum Général Python
    Réponses: 5
    Dernier message: 25/05/2015, 15h24
  5. [Python 3.X] Aide Scrabble - Projet ISN Terminale S
    Par Batmai dans le forum Général Python
    Réponses: 10
    Dernier message: 18/05/2015, 11h51

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