Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente Prochaine révision Les deux révisions suivantes | ||
wiki:tutoriels:arduino:module-bleutooth [2022/05/16 16:33] damien.muti [Module HC-05 Grove BLE v1] |
wiki:tutoriels:arduino:module-bleutooth [2022/05/16 17:35] damien.muti [Etalonage du module] |
||
---|---|---|---|
Ligne 410: | Ligne 410: | ||
===== Etalonage du module ===== | ===== Etalonage du module ===== | ||
+ | |||
+ | Le code permettant de connaître les caractéristiques du module BT Grove-BLE est le suivant : [[https:// | ||
+ | |||
< | < | ||
Ligne 618: | Ligne 621: | ||
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 ====== | ||