{"id":2491,"date":"2024-04-27T04:15:17","date_gmt":"2024-04-27T04:15:17","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=2491"},"modified":"2024-04-27T04:15:21","modified_gmt":"2024-04-27T04:15:21","slug":"getting-started-with-stm32wb55-led-control-using-ble","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=2491","title":{"rendered":"Getting Started with STM32WB55: LED Control using BLE"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1015\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-2-1-1024x1015.png\" alt=\"\" class=\"wp-image-2492\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-2-1-1024x1015.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-2-1-300x297.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-2-1-150x150.png 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-2-1-768x761.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-2-1-750x743.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-2-1-400x396.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-2-1-250x248.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-2-1.png 1130w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>It this guide, we shall control the LED wirelessly using BLE feature of STM32WB55.<\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Enable the LEDs.<\/li><li>Services and Characteristics modification.<\/li><li>LED Control.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Enable the LEDs:<\/h2>\n\n\n\n<p>From the schematic of the STM32WB55 Nucleo, we can find the following:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"772\" height=\"648\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-6.39.49\u202fAM.png\" alt=\"\" class=\"wp-image-2412\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-6.39.49\u202fAM.png 772w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-6.39.49\u202fAM-300x252.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-6.39.49\u202fAM-768x645.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-6.39.49\u202fAM-750x630.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-6.39.49\u202fAM-400x336.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-6.39.49\u202fAM-250x210.png 250w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/figure>\n\n\n\n<p>It has three on board LEDs connected to PB0, PB1 and PB5:<\/p>\n\n\n\n<p>Set the pins as GPIO output as following:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-22_07-23-52-1024x572.jpg\" alt=\"\" class=\"wp-image-2413\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-22_07-23-52-1024x572.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-22_07-23-52-300x167.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-22_07-23-52-768x429.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-22_07-23-52-1536x857.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-22_07-23-52-2048x1143.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-22_07-23-52-1150x642.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-22_07-23-52-750x419.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-22_07-23-52-400x223.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-22_07-23-52-250x141.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Also, give them a name as LD1, LD2 and LD3 for easy write later.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for the LED section.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Services and Characteristics Modification:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>In order to make the BLE accept data from another device, we need to set the characteristics and services with write permission.<\/p>\n\n\n\n<p>From STM32_WPAN, Select LEDControl (or what ever name you gave for the service in BLE GATT):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_06-57-33-1024x572.jpg\" alt=\"\" class=\"wp-image-2493\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_06-57-33-1024x572.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_06-57-33-300x167.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_06-57-33-768x429.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_06-57-33-1536x857.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_06-57-33-2048x1143.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_06-57-33-1150x642.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_06-57-33-750x419.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_06-57-33-400x223.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_06-57-33-250x141.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>First, set CHAR_PROP_WRITE to yes. This will set the properties of the characteristics to be writable.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Second, Set the GATT_NOTIFY_ATTRIBUTE_WRITE to yes also. This will notify the GATT in case there is new data to be written.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Save the project and this will generate the code.<\/p>\n\n\n\n<p>Thats all for the services and Characteristics section.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. LED Control:<\/h2>\n\n\n\n<p>Now, open custom_stm.c source file as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"268\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_07-06-24-268x1024.jpg\" alt=\"\" class=\"wp-image-2494\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_07-06-24-268x1024.jpg 268w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_07-06-24-250x954.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/04\/2024-04-27_07-06-24.jpg 542w\" sizes=\"(max-width: 268px) 100vw, 268px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In user begin include, include the main.h header file as following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/* USER CODE BEGIN Includes *\/\n#include &quot;main.h&quot;\n\/* USER CODE END Includes *\/<\/pre><\/div>\n\n\n\n<p>In the following function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">static SVCCTL_EvtAckStatus_t Custom_STM_Event_Handler(void *Event)<\/pre><\/div>\n\n\n\n<p>Within the function:<\/p>\n\n\n\n<p>There is this line:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/* USER CODE BEGIN CUSTOM_STM_Service_1_Char_1_ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE *\/<\/pre><\/div>\n\n\n\n<p>Here, we shall implement the LED control as following:<\/p>\n\n\n\n<p>When the data is transmitted from phone to Nucleo, the attribute changes. Since the LED control has one 1 variable to hold the data which is the first byte of the attribute data, we can read it as following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint8_t data=attribute_modified-&gt;Attr_Data[0];<\/pre><\/div>\n\n\n\n<p>Check the state of the variable:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>1-&gt; Turn on the LED.<\/li><li>2-&gt; Turn off the LED.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">            if(data==0)\n            {\n            \tHAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET);\n            }\n            if(data==1)\n            {\n            \tHAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);\n            }<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all.<\/p>\n\n\n\n<p>Save the project, build it and run it on your board.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Results:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"LED Control using BLE of STM32WB55\" width=\"1170\" height=\"658\" src=\"https:\/\/www.youtube.com\/embed\/VwhVHmfW57c?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, we shall control multiple LEDs.<\/p>\n\n\n\n<p>Stay tuned.<\/p>\n\n\n\n<p>Happy coding \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It this guide, we shall control the LED wirelessly using BLE feature of STM32WB55. In this guide, we shall cover the following: Enable the LEDs. Services and Characteristics modification. LED Control. Results. 1. Enable the LEDs: From the schematic of the STM32WB55 Nucleo, we can find the following: It has three on board LEDs connected [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-2491","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2491"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2491"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2491\/revisions"}],"predecessor-version":[{"id":2495,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2491\/revisions\/2495"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}