{"id":329,"date":"2021-06-19T17:18:16","date_gmt":"2021-06-19T16:18:16","guid":{"rendered":"https:\/\/rfhyper.wordpress.com\/?p=329"},"modified":"2021-06-19T17:18:16","modified_gmt":"2021-06-19T16:18:16","slug":"le-ble-simplement-avec-la-carte-adafruit-feather-nrf52840-sense","status":"publish","type":"post","link":"https:\/\/leblogrf.fr\/index.php\/2021\/06\/19\/le-ble-simplement-avec-la-carte-adafruit-feather-nrf52840-sense\/","title":{"rendered":"Le BLE simplement avec la carte Adafruit Feather nRF52840 Sense"},"content":{"rendered":"\n<p>Dans cet article, je vais d\u00e9crire comment faire un montage utilisant le protocole Bluetooth Low Energy (BLE) tr\u00e8s simplement.<br>Je me suis inspir\u00e9 du livre <strong>\u00ab&nbsp;Bluetooth Low Energy Projets pour Arduino, Raspberry Pi et smartphones&nbsp;\u00bb<\/strong> (traduit en Fran\u00e7ais) et disponible chez Dunod&nbsp;:<br><a rel=\"noreferrer noopener\" href=\"https:\/\/www.dunod.com\/sciences-techniques\/bluetooth-low-energy-projets-pour-arduino-raspberry-pi-et-smartphones\" target=\"_blank\">https:\/\/www.dunod.com\/sciences-techniques\/bluetooth-low-energy-projets-pour-arduino-raspberry-pi-et-smartphones<\/a><br>Copyright 2016 Alasdair Allan et Don Coleman, Dunod 978-2-10-076085-5<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/9782100760855-001-x.jpeg?w=360\" alt=\"\" class=\"wp-image-333\" width=\"150\" height=\"212\" srcset=\"https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/9782100760855-001-x.jpeg 360w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/9782100760855-001-x-213x300.jpeg 213w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/figure><\/div>\n\n\n\n<p>Ce livre propose de r\u00e9aliser plusieurs montages pour se familiariser avec le protocole BLE. Le premier montage est un \u00ab&nbsp;commutateur d\u2019\u00e9clairage intelligent&nbsp;\u00bb mais le module BLE utilis\u00e9 dans le livre n\u2019est plus commercialis\u00e9. <a href=\"https:\/\/www.adafruit.com\/product\/1697\">https:\/\/www.adafruit.com\/product\/1697<\/a> <br>C\u2019est le grand probl\u00e8me de ce livre dont la publication date de 2017. Une \u00e9ternit\u00e9 dans le domaine de l\u2019\u00e9lectronique, l\u2019IoT, les objets connect\u00e9s, etc..<br>Donc je propose ici d\u2019utiliser la carte <strong>Adafruit Feather nrf52840 Sense<\/strong>. Elle embarque le nRF52840 de chez Nordic Semiconductors. Un chip tr\u00e8s populaire actuellement. <br><a rel=\"noreferrer noopener\" href=\"https:\/\/www.adafruit.com\/product\/4516\" target=\"_blank\">https:\/\/www.adafruit.com\/product\/4516<\/a> <br>Vous pouvez aussi prendre l&rsquo;Adafruit Feather nRF5240 Express : <br><a rel=\"noreferrer noopener\" href=\"https:\/\/www.adafruit.com\/product\/4062\" target=\"_blank\">https:\/\/www.adafruit.com\/product\/4062<\/a> C\u2019est presque la m\u00eame chose, la seule diff\u00e9rence est que la \u00ab\u00a0Sense\u00a0\u00bb int\u00e8gre des capteurs qui permettrons de faire d\u2019autres montages rapidement sans rajouter d\u2019autre module.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Installer l&rsquo;IDE Arduino <\/h2>\n\n\n\n<p>La proc\u00e9dure se trouve sur le site Adafruit en Anglais&nbsp;: <a rel=\"noreferrer noopener\" href=\"https:\/\/learn.adafruit.com\/adafruit-feather-sense\" target=\"_blank\">https:\/\/learn.adafruit.com\/adafruit-feather-sense<\/a> <br>Installer Arduino IDE (Au minimum la version 1.8.6) <br>Ensuite il faut rajouter la prise en charge de la carte Feather. <br>Aller dans \u00ab&nbsp;Pr\u00e9f\u00e9rences&nbsp;\u00bb et ajouter&nbsp;dans \u00ab&nbsp;URL de gestionnaire de cartes suppl\u00e9mentaires&nbsp;\u00bb <a rel=\"noreferrer noopener\" href=\"https:\/\/www.adafruit.com\/package_adafruit_index.json\" target=\"_blank\">https:\/\/www.adafruit.com\/package_adafruit_index.json<\/a> <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/feathersense2.png?w=839\" alt=\"\" class=\"wp-image-349\" width=\"539\" height=\"345\" srcset=\"https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feathersense2.png 839w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feathersense2-300x192.png 300w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feathersense2-768x492.png 768w\" sizes=\"auto, (max-width: 539px) 100vw, 539px\" \/><\/figure><\/div>\n\n\n\n<p>Red\u00e9marrer Arduino IDE.<br>Dans \u00ab Boards Manager \u00bb rechercher Adafruit nRF52.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/feathersense3.png?w=984\" alt=\"\" class=\"wp-image-351\" width=\"557\" height=\"314\" srcset=\"https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feathersense3.png 984w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feathersense3-300x169.png 300w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feathersense3-768x432.png 768w\" sizes=\"auto, (max-width: 557px) 100vw, 557px\" \/><\/figure><\/div>\n\n\n\n<p>Le packet Adafruit nRF52 va s\u2019afficher, cliquer sur \u00ab Installer \u00bb. Quand le package est install\u00e9, aller dans le menu \u00ab Outils \u00bb  \u00ab Type de carte \u00bb et s\u00e9lectionner la carte \u00ab Adafruit Bluefruit nRF52840 Feather Bluefruit Sense \u00bb<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/feathersense4.png?w=1024\" alt=\"\" class=\"wp-image-345\" width=\"597\" height=\"293\" srcset=\"https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feathersense4.png 1045w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feathersense4-300x148.png 300w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feathersense4-1024x505.png 1024w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feathersense4-768x378.png 768w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/figure>\n\n\n\n<p>Installer le driver Adafruit pour Windows (uniquement si la carte n\u2019est pas d\u00e9tect\u00e9e au branchement sur le port USB) <a rel=\"noreferrer noopener\" href=\"https:\/\/learn.adafruit.com\/adafruit-arduino-ide-setup\/windows-driver-installation%C2%A0\" target=\"_blank\">https:\/\/learn.adafruit.com\/adafruit-arduino-ide-setup\/windows-driver-installation%C2%A0<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Ex\u00e9cuter son premier sketch<\/h2>\n\n\n\n<p>Depuis l&rsquo;IDE Arduino, aller dans \u00ab&nbsp;File&nbsp;\u00bb puis \u00ab&nbsp;Examples&nbsp;\u00bb \u00ab&nbsp;01.Basics&nbsp;\u00bb puis \u00ab&nbsp;Blink&nbsp;\u00bb <br>C\u2019est le sketch (programme) de base en Arduino. <br>Il fait juste clignoter une LED pr\u00e9sente sur la carte. <br>Dans le menu \u00ab&nbsp;sketch&nbsp;\u00bb cliquer sur \u00ab&nbsp; Upload&nbsp;\u00bb Le sketch va \u00eatre compil\u00e9 et transf\u00e9r\u00e9 sur la carte.<br>Puis la LED rouge sur la carte va clignoter.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/feather_blink_crop.jpg?w=1024\" alt=\"\" class=\"wp-image-353\" width=\"457\" height=\"252\" srcset=\"https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feather_blink_crop.jpg 1687w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feather_blink_crop-300x166.jpg 300w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feather_blink_crop-1024x565.jpg 1024w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feather_blink_crop-768x424.jpg 768w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/feather_blink_crop-1536x848.jpg 1536w\" sizes=\"auto, (max-width: 457px) 100vw, 457px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">3. Faire clignoter une LED externe<\/h2>\n\n\n\n<p>Nous allons maintenant faire un montage avec une LED comme si c\u2019\u00e9tait une ampoule. <br>Prendre une LED et une r\u00e9sistance d\u2019environ 100 \u03a9. <br>Attention&nbsp;: dans le livre, la r\u00e9sistance est de 220 \u03a9 car la carte est sur 5V, alors que la Feather est sur 3,3V. Relier la patte 3V de la carte \u00e0 la barre d\u2019alimentation positive de la plaque. Idem pour la patte GND \u00e0 la barre n\u00e9gative commune. Relier la r\u00e9sistance 100\u03a9 \u00e0 la patte 5 de la carte, puis \u00e0 la patte la plus longue de la LED. Relier l\u2019autre patte de la LED \u00e0 la masse (GND).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/2021-05-24_17-07-57_398.jpg?w=1024\" alt=\"\" class=\"wp-image-356\" width=\"524\" height=\"393\" \/><figcaption>Montage carte Feather avec LED<\/figcaption><\/figure><\/div>\n\n\n\n<p>Modifier le sketch \u00ab\u00a0Blink\u00a0\u00bb pour utiliser la sortie 5 :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background-color has-foreground-background-color has-text-color has-background has-small-font-size\">#define LED_PIN 5\nvoid setup() {\n  pinMode(LED_PIN, OUTPUT);\n}\nvoid loop() {\n  digitalWrite(LED_PIN, HIGH);\n  delay(1000);\n  digitalWrite(LED_PIN, LOW);\n  delay(1000);\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. Ajouter un bouton-poussoir<\/h2>\n\n\n\n<p>Rajouter un bouton sur la carte d&rsquo;exp\u00e9rimentation. Brancher l&rsquo;une des pattes \u00e0 la broche 6 de la carte, puis l&rsquo;autre au +3V. Rajouter une r\u00e9sistance de rappel de 10k \u03a9  depuis la broche 6 pour \u00e9viter des faux appuis. Voir la page 30 figure 3.7 du livre pour le sch\u00e9ma du montage.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/2021-05-24_17-37-34_645.jpg?w=1024\" alt=\"\" class=\"wp-image-359\" \/><figcaption> Montage carte Feather avec LED et bouton poussoir<\/figcaption><\/figure>\n\n\n\n<p>Le sketch Arduino est le suivant :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background-color has-foreground-background-color has-text-color has-background has-small-font-size\">#define LED_PIN 5\n#define BUTTON_PIN 6\nint val;\nvoid setup() {\n  pinMode(LED_PIN, OUTPUT);\n  pinMode(BUTTON_PIN, INPUT);\n\n}\nvoid loop() {\n  val = digitalRead(BUTTON_PIN);\n  if (val == HIGH) {\n    digitalWrite(LED_PIN, HIGH);\n  }\n   if (val == LOW) {\n    digitalWrite(LED_PIN, LOW);\n  }\n}<\/pre>\n\n\n\n<p>Am\u00e9lioration avec un Anti-Rebond logiciel.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background-color has-foreground-background-color has-text-color has-background has-small-font-size\">#define LED_PIN 5\n#define BUTTON_PIN 6\nint currentState;\nint debounceState;\n\nvoid setup() {\n  pinMode(LED_PIN, OUTPUT);\n  pinMode(BUTTON_PIN, INPUT);\n\n}\n\nvoid loop() {\n  currentState = digitalRead(BUTTON_PIN);\n  delay(10) ;\n  debounceState = digitalRead(BUTTON_PIN);\n\n  if (currentState == debounceState) {\n   if (currentState == HIGH) {\n     digitalWrite(LED_PIN, HIGH);\n   }\n   if (currentState == LOW) {\n     digitalWrite(LED_PIN, LOW);\n   }\n  }\n}<\/pre>\n\n\n\n<p>Pour finir, nous allons rajouter la prise en charge du BLE. Le but est de pouvoir lire le status de la LED depuis un smartphone connect\u00e9 en BLE \u00e0 la carte, mais aussi de pouvoir allumer la LED \u00e0 distance. La carte Adafruit Feather nRF52840 Sense int\u00e8gre d\u00e9j\u00e0 un module BLE, il n&rsquo;y a donc pas de modification du montage \u00e0 faire.<br>Le sketch ci-dessous est bas\u00e9 sur celui du livre Exemple 3.1 page 39. Il reprend exactement le m\u00eame fonctionnement mais a \u00e9t\u00e9 adapt\u00e9 pour la carte Feather :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background-color has-foreground-background-color has-text-color has-background has-small-font-size\">#include &lt;bluefruit.h&gt; \u2776\n\n#define LED_PIN 5\n#define BUTTON_PIN 6\n\nint currentState;\nint debounceState;\nint switchState = 0;   \nint ledState = 0;\n\nBLEService    lightswitch = BLEService(0xFF10); \u2777\n\nBLECharacteristic switchCharacteristic = BLECharacteristic(0xFF11);  \u2778\nBLECharacteristic stateCharacteristic = BLECharacteristic(0xFF12);\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(LED_PIN, OUTPUT);\n  pinMode(BUTTON_PIN, INPUT);\n  Bluefruit.begin();\n  Bluefruit.setName(\"Light Switch\"); \u2779\n  lightswitch.begin();\n  \n  switchCharacteristic.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE); \u277a\n  switchCharacteristic.setPermission(SECMODE_OPEN, SECMODE_OPEN);\n  switchCharacteristic.setFixedLen(1);\n  switchCharacteristic.setUserDescriptor(\"Switch\");\n  switchCharacteristic.begin();\n \n  stateCharacteristic.setProperties(CHR_PROPS_NOTIFY);\n  stateCharacteristic.setFixedLen(1);\n  stateCharacteristic.setUserDescriptor(\"State\");\n  stateCharacteristic.begin(); \n  \n  startAdv(); \n  Serial.println(\"Smart Light Switch\");\n}\n\nvoid startAdv(void) \u277b\n{\n  \/\/ Advertising packet\n  Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);\n  Bluefruit.Advertising.addTxPower();\n  Bluefruit.Advertising.addService(lightswitch);\n  Bluefruit.Advertising.addName();\n  \n  \/* Start Advertising\n   * - Enable auto advertising if disconnected\n   * - Interval:  fast mode = 20 ms, slow mode = 152.5 ms\n   * - Timeout for fast mode is 30 seconds\n   * - Start(timeout) with timeout = 0 will advertise forever (until connected)\n   * \n   * For recommended advertising interval\n   * https:\/\/developer.apple.com\/library\/content\/qa\/qa1931\/_index.html   \n   *\/\n  Bluefruit.Advertising.restartOnDisconnect(true);\n  Bluefruit.Advertising.setInterval(32, 244);    \/\/ in unit of 0.625 ms\n  Bluefruit.Advertising.setFastTimeout(30);      \/\/ number of seconds in fast mode\n  Bluefruit.Advertising.start(0);                \/\/ 0 = Don't stop advertising after n seconds  \n}\n\nvoid loop() {\n  \n  currentState = digitalRead(BUTTON_PIN);\n  delay(10);\n  debounceState = digitalRead(BUTTON_PIN);\n  \n\n  if( currentState == debounceState  ) { \n    if ( currentState != switchState ) { \n\n      if ( currentState == LOW ) { \n        \/\/ Button just released\n        \n      } else { \n        Serial.print(F(\"Button event: \"));\n        if ( ledState == 0 ) {\n          stateCharacteristic.notify8(1); \u277c\n          switchCharacteristic.write8(1);\n          digitalWrite(LED_PIN, HIGH);\n          ledState = 1;\n           Serial.println(F(\"light on\"));\n       } else {\n          stateCharacteristic.notify8(0); \u277d\n          switchCharacteristic.write8(0);\n          digitalWrite(LED_PIN, LOW);\n          ledState = 0;\n           Serial.println(F(\"light off\"));\n       }\n      }\n      switchState = currentState;\n    }\n  \n  }\n}<\/pre>\n\n\n\n<p>\u2776 Inclusion de la librairie Arduino Bluefruit<br>\u2777 Cr\u00e9ation du service avec l&rsquo;UUID 0xFF10<br>\u2778 Cr\u00e9ation des caract\u00e9ristiques<br>\u2779 D\u00e9finition du nom du p\u00e9riph\u00e9rique BLE qui sera affich\u00e9 sur le smartphone<br>\u277a D\u00e9finition des propri\u00e9t\u00e9s des caract\u00e9ristiques <br>\u277b D\u00e9finition de la configuration pour  l&rsquo; \u00ab\u00a0Advertising\u00a0\u00bb. C&rsquo;est un \u00e9l\u00e9ment essentiel du BLE. Le code a \u00e9t\u00e9 repris de la documentation de la librairie Bluefruit. <a rel=\"noreferrer noopener\" href=\"https:\/\/learn.adafruit.com\/adafruit-feather-sense\/bleadvertising\" target=\"_blank\">https:\/\/learn.adafruit.com\/adafruit-feather-sense\/bleadvertising<\/a><br>\u277c Bascule les valeurs de switch et state \u00e0 1 lors d&rsquo;un appui sur le bouton-poussoir<br>\u277d Bascule les valeurs de switch et state \u00e0 0  lors d&rsquo;un autre appui<\/p>\n\n\n\n<p>Une fois le code t\u00e9l\u00e9vers\u00e9, vous devriez pouvoir allumer et \u00e9teindre la LED comme avant avec le bouton-poussoir mais en plus vous pouvez afficher le status sur un smartphone.<br>Sur Iphone vous pouvez utilisez l&rsquo;application LightBlue. Au lancement, l&rsquo;application scanne les p\u00e9riph\u00e9riques BLE \u00e0 proximit\u00e9. Le p\u00e9riph\u00e9rique \u00ab\u00a0Light Switch\u00a0\u00bb devrait apparaitre dans la liste. En cliquant dessus, la connexion est \u00e9tablie et les deux caract\u00e9ristiques \u00ab\u00a0Switch\u00a0\u00bb et \u00ab\u00a0State\u00a0\u00bb vont appara\u00eetre.<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-4 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"1334\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/2021-06-19_09-41-50_000.png?w=576\" alt=\"\" data-id=\"365\" data-link=\"https:\/\/rfhyper.wordpress.com\/2021-06-19_09-41-50_000\/\" class=\"wp-image-365\" srcset=\"https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-41-50_000.png 750w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-41-50_000-169x300.png 169w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-41-50_000-576x1024.png 576w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"1334\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-08_000.png?w=576\" alt=\"\" data-id=\"367\" data-link=\"https:\/\/rfhyper.wordpress.com\/2021-06-19_09-42-08_000\/\" class=\"wp-image-367\" srcset=\"https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-08_000.png 750w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-08_000-169x300.png 169w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-08_000-576x1024.png 576w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"1334\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-25_000.png?w=576\" alt=\"\" data-id=\"368\" data-link=\"https:\/\/rfhyper.wordpress.com\/2021-06-19_09-42-25_000\/\" class=\"wp-image-368\" srcset=\"https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-25_000.png 750w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-25_000-169x300.png 169w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-25_000-576x1024.png 576w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"1334\" src=\"http:\/\/leblogs.cluster029.hosting.ovh.net\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-37_000.png?w=576\" alt=\"\" data-id=\"369\" data-link=\"https:\/\/rfhyper.wordpress.com\/2021-06-19_09-42-37_000\/\" class=\"wp-image-369\" srcset=\"https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-37_000.png 750w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-37_000-169x300.png 169w, https:\/\/leblogrf.fr\/wp-content\/uploads\/2021\/06\/2021-06-19_09-42-37_000-576x1024.png 576w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure><\/li><\/ul><figcaption class=\"blocks-gallery-caption\">Application LightBlue pour utilisation de p\u00e9riph\u00e9rique BLE<\/figcaption><\/figure>\n\n\n\n<p>Pour le moment, il est possible de lire le status de la LED mais pas de changer l&rsquo;\u00e9tat depuis le smartphone. Pour faire cela, il faut rajouter un gestionnaire d&rsquo;\u00e9v\u00e9nements (ou handler).<br>Rajouter la ligne suivante juste apr\u00e8s switchCharacteristic.begin();<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background-color has-foreground-background-color has-text-color has-background has-small-font-size\">switchCharacteristic.setWriteCallback(switchCharacteristicWritten);<\/pre>\n\n\n\n<p>Puis \u00e0 la fin du sketch rajouter :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background-color has-foreground-background-color has-text-color has-background has-small-font-size\">void switchCharacteristicWritten(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len) {\n  (void) conn_hdl;\n  (void) chr;\n  (void) len; \/\/ len should be 1\n  \n  Serial.print(F(\"Characteristic event: \"));\n  if (data[0]) {\n    Serial.println(F(\"light on\"));\n    digitalWrite(LED_PIN, HIGH);\n    ledState = 1;\n    stateCharacteristic.notify8(1); \n    \n  } else {\n    Serial.println(F(\"light off\"));\n    digitalWrite(LED_PIN, LOW);\n    ledState = 0;\n    stateCharacteristic.notify8(0);   \n    \n  }\n}<\/pre>\n\n\n\n<p>Voil\u00e0 maintenant, dans l&rsquo;application LightBlue, cliquez sur la caract\u00e9ristique Switch, puis sur \u00ab\u00a0Write new value\u00a0\u00bb, entrez la valeur \u00ab\u00a001\u00a0\u00bb, puis cliquez sur Done, la LED va s&rsquo;allumer, ou entrez la valeur \u00ab\u00a000\u00a0\u00bb, la LED va s&rsquo;\u00e9teindre.<br>Le programme complet est disponible en t\u00e9l\u00e9chargement ici :<br><a rel=\"noreferrer noopener\" href=\"https:\/\/1drv.ms\/u\/s!AnDlERvozWJSiH0mic39i0BAGQDF?e=QXrVsk\" target=\"_blank\">https:\/\/1drv.ms\/u\/s!AnDlERvozWJSiH0mic39i0BAGQDF?e=QXrVsk<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dans cet article, je vais d\u00e9crire comment faire un montage utilisant le protocole Bluetooth Low Energy (BLE) tr\u00e8s simplement.Je me suis inspir\u00e9 du livre \u00ab&nbsp;Bluetooth Low Energy Projets pour Arduino, Raspberry Pi et smartphones&nbsp;\u00bb (traduit en Fran\u00e7ais) et disponible chez Dunod&nbsp;:https:\/\/www.dunod.com\/sciences-techniques\/bluetooth-low-energy-projets-pour-arduino-raspberry-pi-et-smartphonesCopyright 2016 Alasdair Allan et Don Coleman, Dunod 978-2-10-076085-5 Ce livre propose de r\u00e9aliser plusieurs &hellip; <a href=\"https:\/\/leblogrf.fr\/index.php\/2021\/06\/19\/le-ble-simplement-avec-la-carte-adafruit-feather-nrf52840-sense\/\" class=\"more-link\">Continuer la lecture de <span class=\"screen-reader-text\">Le BLE simplement avec la carte Adafruit Feather nRF52840 Sense<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":330,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-329","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-ble"],"_links":{"self":[{"href":"https:\/\/leblogrf.fr\/index.php\/wp-json\/wp\/v2\/posts\/329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leblogrf.fr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leblogrf.fr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leblogrf.fr\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/leblogrf.fr\/index.php\/wp-json\/wp\/v2\/comments?post=329"}],"version-history":[{"count":0,"href":"https:\/\/leblogrf.fr\/index.php\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/leblogrf.fr\/index.php\/wp-json\/wp\/v2\/media\/330"}],"wp:attachment":[{"href":"https:\/\/leblogrf.fr\/index.php\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leblogrf.fr\/index.php\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leblogrf.fr\/index.php\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}