| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
wiki:tutoriels:arduino:module-bleutooth [2022/05/16 16:28] damien.muti [Module HC-05 Grove BLE v1] |
wiki:tutoriels:arduino:module-bleutooth [2022/05/16 17:39] (Version actuelle) damien.muti [Dialogue entre le smartphone et la carte Arduino] |
||
|---|---|---|---|
| Ligne 94: | Ligne 94: | ||
| * [[https:// | * [[https:// | ||
| - | == Programme == | + | == Programme |
| + | |||
| + | Ce Programme permet d' | ||
| - | Il faut ensuite téléverser le code suivant sur la carte Arduino : | ||
| < | < | ||
| + | |||
| #include < | #include < | ||
| SoftwareSerial hc06(2, 3); | SoftwareSerial hc06(2, 3); | ||
| Ligne 104: | Ligne 106: | ||
| float sensor_val = 0; | float sensor_val = 0; | ||
| // faire clignoter clignoter la led | // faire clignoter clignoter la led | ||
| - | byte led = 13; | + | byte led = 8; |
| int Tblink = 100; | int Tblink = 100; | ||
| float isBlink = false; // drapeau pour lancer le clignotement... ou non | float isBlink = false; // drapeau pour lancer le clignotement... ou non | ||
| Ligne 115: | Ligne 117: | ||
| Serial.begin(9600); | Serial.begin(9600); | ||
| // | // | ||
| - | hc06.begin(9600); | + | hc06.begin(115200); /// Tester aussi avec 9600 si vous rencontrez des difficultés de communication avec le moule BT |
| } | } | ||
| void loop() { | void loop() { | ||
| Ligne 129: | Ligne 131: | ||
| if (cmd == " | if (cmd == " | ||
| Serial.println(" | Serial.println(" | ||
| - | digitalWrite(13, HIGH); // alumer la led | + | digitalWrite(led, HIGH); // alumer la led |
| isBlink = false; // arrêter le clignotement | isBlink = false; // arrêter le clignotement | ||
| } else if (cmd == " | } else if (cmd == " | ||
| Serial.println(" | Serial.println(" | ||
| - | digitalWrite(13, LOW); // éteindre la led | + | digitalWrite(led, LOW); // éteindre la led |
| isBlink = false; // arrêter le clignotement | isBlink = false; // arrêter le clignotement | ||
| } else { | } else { | ||
| Ligne 170: | Ligne 172: | ||
| </ | </ | ||
| + | |||
| + | |||
| + | |||
| Le code Arduino est téléchargeable ici : | Le code Arduino est téléchargeable ici : | ||
| Ligne 406: | Ligne 411: | ||
| ]] | ]] | ||
| - | ===== Etalonage du module ===== | ||
| - | <code> | + | Le code permettant de connaître les caractéristiques du modules BT Grove-BLE est accessible ici : [[https:// |
| + | ===== Etalonage du module ===== | ||
| - | Skip to content | + | Le code permettant de connaître les caractéristiques du module BT Grove-BLE est le suivant : [[https:// |
| - | Product | ||
| - | Team | + | < |
| - | Enterprise | + | |
| - | Explore | + | |
| - | Marketplace | + | |
| - | Pricing | + | |
| - | + | ||
| - | Sign in | + | |
| - | Sign up | + | |
| - | Seeed-Studio / | + | |
| - | HM_13_SW | + | |
| - | Public | + | |
| - | + | ||
| - | Code | + | |
| - | Issues 1 | + | |
| - | Pull requests | + | |
| - | Actions | + | |
| - | Projects | + | |
| - | Wiki | + | |
| - | Security | + | |
| - | Insights | ||
| - | HM_13_SW/ | ||
| - | @JackyZhangFromSeeed | ||
| - | JackyZhangFromSeeed changed folder and file name from " | ||
| - | Latest commit a967764 on 26 Jan 2015 | ||
| - | History | ||
| - | 1 contributor | ||
| - | 210 lines (184 sloc) 6.1 KB | ||
| /* | /* | ||
| Bluetooth HM13 Demo Code | Bluetooth HM13 Demo Code | ||
| Ligne 648: | Ligne 626: | ||
| return 0; | return 0; | ||
| } | } | ||
| + | </ | ||
| + | ===== Programme de test du module ===== | ||
| + | |||
| + | Ce Programme permet d' | ||
| + | |||
| + | |||
| + | < | ||
| + | |||
| + | #include < | ||
| + | SoftwareSerial hc06(2, 3); | ||
| + | String cmd = ""; | ||
| + | float sensor_val = 0; | ||
| + | // faire clignoter clignoter la led | ||
| + | byte led = 8; | ||
| + | int Tblink = 100; | ||
| + | float isBlink = false; // drapeau pour lancer le clignotement... ou non | ||
| + | |||
| + | void setup() { | ||
| + | // pin 13 OUTPUT | ||
| + | pinMode(led, | ||
| + | |||
| + | // | ||
| + | Serial.begin(9600); | ||
| + | // | ||
| + | hc06.begin(115200); | ||
| + | } | ||
| + | void loop() { | ||
| + | //Read data from HC06 | ||
| + | while (hc06.available() > 0) { | ||
| + | cmd += (char)hc06.read(); | ||
| + | } | ||
| + | //Select function with cmd | ||
| + | if (cmd != "" | ||
| + | Serial.print(" | ||
| + | Serial.println(cmd); | ||
| + | // We expect ON or OFF from bluetooth | ||
| + | if (cmd == " | ||
| + | Serial.println(" | ||
| + | digitalWrite(led, | ||
| + | isBlink = false; // arrêter le clignotement | ||
| + | } else if (cmd == " | ||
| + | Serial.println(" | ||
| + | digitalWrite(led, | ||
| + | isBlink = false; // arrêter le clignotement | ||
| + | } else { | ||
| + | // convertir la comande en un entier | ||
| + | int x = cmd.toInt(); | ||
| + | if (x >= 0 && x <= 10000) { // si la commande est un nombre entre 0 et 10000 (soit 10s) | ||
| + | Tblink = x; | ||
| + | clignoterLed(13, | ||
| + | isBlink=true; | ||
| + | } | ||
| + | else { | ||
| + | Serial.println(" | ||
| + | } | ||
| + | } | ||
| + | cmd = ""; | ||
| + | } | ||
| + | // gestion du clignotement | ||
| + | if (isBlink) { | ||
| + | clignoterLed(led, | ||
| + | } | ||
| + | |||
| + | // Simulate sensor measurement | ||
| + | sensor_val = (float)random(256); | ||
| + | |||
| + | //Write sensor data to HC06 | ||
| + | hc06.print(sensor_val); | ||
| + | delay(100); | ||
| + | } | ||
| + | |||
| + | void clignoterLed(int led, int Ta, int Te) { // led : patte connécéet à la led, Ta: temps d' | ||
| + | digitalWrite(led, | ||
| + | delay(Ta); | ||
| + | digitalWrite(led, | ||
| + | delay(Te); | ||
| + | } | ||
| </ | </ | ||
| + | |||
| + | |||
| + | |||
| ====== Carte Arduino Nano BLE ====== | ====== Carte Arduino Nano BLE ====== | ||