{"id":221,"date":"2022-03-14T15:22:22","date_gmt":"2022-03-14T15:22:22","guid":{"rendered":"https:\/\/www.bleuio.com\/blog\/?p=221"},"modified":"2022-07-01T10:25:34","modified_gmt":"2022-07-01T10:25:34","slug":"show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32","status":"publish","type":"post","link":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/","title":{"rendered":"Show Bluetooth LE Sensor readings on LCD screen connected to STM32"},"content":{"rendered":"\n<p>The aim of this&nbsp;<a href=\"https:\/\/www.bleuio.com\/\">Bluetooth LE project<\/a>&nbsp;is to read air quality sensor data and show it on an LCD display which is connected to STM32 board. A web browser will read the sensor data and pass it to STM32 board using BleuIO.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n\n\n\n<p>The project is based on&nbsp;<strong>STM32 Nucleo-144<\/strong>&nbsp;which controls&nbsp;<strong>LCD display<\/strong>&nbsp;using BleuIO.<\/p>\n\n\n\n<p>For this project, we will need&nbsp;<a href=\"https:\/\/www.bleuio.com\/\">two BleuIO USB dongles<\/a>, one connected to the Nucleo board and the other to a computer running the web script and a&nbsp;<a href=\"https:\/\/smartsensordevices.com\/hibouair-air-quality-monitoring-solution-indoor-co2-ble\/\">HibouAir \u2013 Air quality monitoring device<\/a>&nbsp;.<br>When the BleuIO Dongle is connected to the Nucleo boards USB port the STM32 will recognize it and directly start advertising. This allows the Dongle on the computer port connect with the web script.<\/p>\n\n\n\n<p>With the web script on the computer, we can scan and get air quality sensor data from HibouAir. Then we send these data to LCD screen connected to STM32 using Bluetooth.<\/p>\n\n\n\n<p>We have used a STM32 Nucleo-144 development board with STM32H743ZI MCU (STM32H743ZI micro mbed-Enabled Development Nucleo-144 series ARM\u00ae Cortex\u00ae-M7 MCU 32-Bit Embedded Evaluation Board) for this example. This development board has a USB host where we connect the BleuIO dongle.<\/p>\n\n\n\n<p>If you want to use another setup you will have to make sure it support USB Host and beware that the GPIO setup might be different and may need to be reconfigured in the .ioc file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">About the Code<\/h2>\n\n\n\n<p>The project source code is available at Github.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/smart-sensor-devices-ab\/stm32_ble_sensor_lcd.git\">https:\/\/github.com\/smart-sensor-devices-ab\/stm32_ble_sensor_lcd.git<\/a><\/p>\n\n\n\n<p>Either clone the project, or download it as a zip file and unzip it, into your STM32CubeIDE workspace.<\/p>\n\n\n\n<p>If you download the project as a zip file you will need to rename the project folder from \u2018stm32_bleuio_lcd-master\u2019 to \u2018stm32_bleuio_lcd\u2019<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"476\" height=\"259\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/pin-configuration.jpg\" alt=\"\" class=\"wp-image-197\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/pin-configuration.jpg 476w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/pin-configuration-300x163.jpg 300w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/figure>\n\n\n\n<p>Connect the SDA to PF0 on the Nucleo board and SCL to PF1.<\/p>\n\n\n\n<p>Then setup I2C2 in the STM32Cube ioc file as follows. (Make sure to change the I2C speed frequency to 50 KHz as per LCD display requirements.)<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"344\" height=\"69\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/stm32cubeide_pins-1.png\" alt=\"\" class=\"wp-image-198\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/stm32cubeide_pins-1.png 344w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/stm32cubeide_pins-1-300x60.png 300w\" sizes=\"auto, (max-width: 344px) 100vw, 344px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"548\" height=\"106\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/stm32cubeide_NVIC.png\" alt=\"\" class=\"wp-image-199\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/stm32cubeide_NVIC.png 548w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/stm32cubeide_NVIC-300x58.png 300w\" sizes=\"auto, (max-width: 548px) 100vw, 548px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"648\" height=\"698\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/LCD-I2C-configuration.jpg\" alt=\"\" class=\"wp-image-200\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/LCD-I2C-configuration.jpg 648w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/LCD-I2C-configuration-279x300.jpg 279w\" sizes=\"auto, (max-width: 648px) 100vw, 648px\" \/><\/figure>\n\n\n\n<p>In the USBH_CDC_ReceiveCallback function in USB_HOST\\usb_host.c we copy the CDC_RX_Buffer into a external variable called dongle_response that is accessable from the main.c file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost)\n{\n  \tif(phost == &amp;hUsbHostFS)\n  \t{\n  \t\t\/\/ Handles the data recived from the USB CDC host, here just printing it out to UART\n  \t\trx_size = USBH_CDC_GetLastReceivedDataSize(phost);\n\t\tHAL_UART_Transmit(&amp;huart3, CDC_RX_Buffer, rx_size, HAL_MAX_DELAY);\n\n\t\t\/\/ Copy buffer to external dongle_response buffer\n\t\tstrcpy((char *)dongle_response, (char *)CDC_RX_Buffer);\n\n\t\t\/\/ Reset buffer and restart the callback function to receive more data\n\t\tmemset(CDC_RX_Buffer,0,RX_BUFF_SIZE);\n\t\tUSBH_CDC_Receive(phost, CDC_RX_Buffer, RX_BUFF_SIZE);\n  \t}\n\n  \treturn;\n}\n<\/code><\/pre>\n\n\n\n<p>In main.c we create a simple intepreter so we can react to the data we are recieving from the dongle.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void dongle_interpreter(uint8_t * input)\n{\n\n\tif(strlen((char *)input) != 0)\n\t{\n\t\tif(strstr((char *)input, \"\\r\\nADVERTISING...\") != NULL)\n\t\t{\n\t\t\tisAdvertising = true;\n\t\t}\n\t\tif(strstr((char *)input, \"\\r\\nADVERTISING STOPPED\") != NULL)\n\t\t{\n\t\t\tisAdvertising = false;\n\t\t}\n\t\tif(strstr((char *)input, \"\\r\\nCONNECTED\") != NULL)\n\t\t{\n\t\t\tisConnected = true;\n\t\t\tHAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET);\n\t\t}\n\t\tif(strstr((char *)input, \"\\r\\nDISCONNECTED\") != NULL)\n\t\t{\n\t\t\tisConnected = false;\n\t\t\tHAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);\n\t\t}\n\n\n\t\tif(strstr((char *)input, \"L=0\") != NULL)\n\t\t{\n\n\t\t\tisLightBulbOn = false;\n\t\t\t\/\/HAL_GPIO_WritePin(Lightbulb_GPIO_Port, Lightbulb_Pin, GPIO_PIN_RESET);\n\t\t\tlcd_clear();\n\n\t\t\twriteToDongle((uint8_t*)DONGLE_SEND_LIGHT_OFF);\n\n\t\t\tuart_buf_len = sprintf(uart_tx_buf, \"\\r\\nClear screen\\r\\n\");\n\t\t\tHAL_UART_Transmit(&amp;huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);\n\t\t}\n\n\t\tif(strstr((char *)input, \"L=1\") != NULL)\n\t\t{\n\t\t\t\tisLightBulbOn = true;\n\t\t\t\twriteToDongle((uint8_t*)DONGLE_SEND_LIGHT_ON);\n\n\n\t\t\t\tlcd_clear();\n\n\t\t\t\tlcd_write(input);\n\n\t\t}\n\n\t}\n\tmemset(&amp;dongle_response, 0, RSP_SIZE);\n}<\/code><\/pre>\n\n\n\n<p>We put the intepreter function inside the main loop.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* Infinite loop *\/\n  \/* USER CODE BEGIN WHILE *\/\n  while (1)\n  {\n    \/* USER CODE END WHILE *\/\n    MX_USB_HOST_Process();\n\n    \/* USER CODE BEGIN 3 *\/\n    \/\/ Simple handler for uart input\n    handleUartInput(uartStatus);\n\n    \/\/ Inteprets the dongle data\n    dongle_interpreter(dongle_response);\n\n\t\/\/ Starts advertising as soon as the Dongle is ready.\n\tif(!isAdvertising &amp;&amp; !isConnected &amp;&amp; isBleuIOReady)\n\t{\n\t\tHAL_Delay(200);\n\t\twriteToDongle((uint8_t*)DONGLE_CMD_AT_ADVSTART);\n\t\tisAdvertising = true;\n\t}\n  }\n  \/* USER CODE END 3 *\/<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Using the example project<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What we will need<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Two BleuIO dongles (<a href=\"https:\/\/www.bleuio.com\/\">https:\/\/www.bleuio.com\/<\/a>)<\/li><li>A board with a STM32 Microcontroller with a USB port. (A Nucleo-144 development board: NUCLEO-H743ZI2, was used developing this example. (<a href=\"https:\/\/www.st.com\/en\/evaluation-tools\/nucleo-h743zi.html\">https:\/\/www.st.com\/en\/evaluation-tools\/nucleo-h743zi.html<\/a>)<br>To connect the dongle to the Nucleo board a \u201cUSB A to Micro USB B\u201d-cable with a USB A female-to-female adapter can be used.)<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"467\" height=\"350\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/adapter.jpg\" alt=\"\" class=\"wp-image-201\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/adapter.jpg 467w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/adapter-300x225.jpg 300w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>STM32CubeIDE (<a href=\"https:\/\/www.st.com\/en\/development-tools\/stm32cubeide.html\">https:\/\/www.st.com\/en\/development-tools\/stm32cubeide.html<\/a>)<\/li><li>Liquid Crystal Display Module \u2013 NHD-0420D3Z-NSW-BBW-V3 (<a href=\"https:\/\/www.digikey.com\/en\/products\/detail\/newhaven-display-intl\/NHD-0420D3Z-NSW-BBW-V3\/2626390?s=N4IgTCBcDaIHIAkAiBaADAFjGpBmAWinAMoDqKAQheQGq4gC6AvkA\">https:\/\/www.digikey.com\/en\/products\/detail\/newhaven-display-intl\/NHD-0420D3Z-NSW-BBW-V3\/2626390?s=N4IgTCBcDaIHIAkAiBaADAFjGpBmAWinAMoDqKAQheQGq4gC6AvkA<\/a>)<\/li><li>HibouAir \u2013 Air quality monitoring device (https:\/\/www.hibouair.com\/)<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Importing as an Existing Project<\/h3>\n\n\n\n<p>From STM32CubeIDE choose File&gt;Import\u2026<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"334\" height=\"536\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/import.png\" alt=\"\" class=\"wp-image-202\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/import.png 334w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/import-187x300.png 187w\" sizes=\"auto, (max-width: 334px) 100vw, 334px\" \/><\/figure>\n\n\n\n<p>Then choose General&gt;Existing Projects into Workspace then click \u2018Next &gt;\u2019<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"511\" height=\"543\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/existing_projects.png\" alt=\"\" class=\"wp-image-203\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/existing_projects.png 511w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/existing_projects-282x300.png 282w\" sizes=\"auto, (max-width: 511px) 100vw, 511px\" \/><\/figure>\n\n\n\n<p>Make sure you\u2019ve choosen your workspace in \u2018Select root directory:\u2019<\/p>\n\n\n\n<p>You should see the project \u201cstm32_bleuio_SHT85_example\u201d, check it and click \u2018Finish\u2019.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"703\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/import_projects.png\" alt=\"\" class=\"wp-image-204\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/import_projects.png 463w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/import_projects-198x300.png 198w\" sizes=\"auto, (max-width: 463px) 100vw, 463px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Running the example<\/h3>\n\n\n\n<p>Upload the the code to STM32 and run the example. The USB dongle connect to STM32 will start advertising automatically.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"access-sensor-data-from-a-web-browser\">Send Sensor data to LCD screen from a web browser<\/h2>\n\n\n\n<p>Connect the BleuIO dongle to the computer. Run the web script to connect to the other BleuIO dongle on the STM32. Now you can send sensor data to the LCD screen.<\/p>\n\n\n\n<p>For this script to work, we need<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.bleuio.com\/\">BleuIO USB dongle<\/a>&nbsp;connected to the computer.<\/li><li><a href=\"https:\/\/www.npmjs.com\/package\/bleuio\">BleuIO javascript library<\/a><\/li><li>Chrome 78 or later, and you need to enable the&nbsp;<strong>#enable-experimental-web-platform-features<\/strong>&nbsp;flag in&nbsp;<a href=\"chrome:\/\/flags\/\">chrome:\/\/flags<\/a><\/li><li>A web bundler \u2013 (<a href=\"https:\/\/parceljs.org\/\">parcel js<\/a>)<\/li><\/ul>\n\n\n\n<p>Create a simple Html file called index.html which will serve as the frontend of the script. This Html file contains some buttons that help connect, read advertised data from the HibouAir to get air quality sensor data, and send this data to the LCD screen which is connected to stm32.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n  &lt;head&gt;\n    &lt;meta charset=\"UTF-8\" \/&gt;\n    &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" \/&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" \/&gt;\n    &lt;link\n      href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.1.3\/dist\/css\/bootstrap.min.css\"\n      rel=\"stylesheet\"\n      integrity=\"sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3\"\n      crossorigin=\"anonymous\"\n    \/&gt;\n    &lt;title&gt;Bluetooth LE Air quality sensor data to LCD screen&lt;\/title&gt;\n  &lt;\/head&gt;\n  &lt;body class=\"mt-5\"&gt;\n    &lt;div class=\"container mt-5\"&gt;\n      &lt;img\n        src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/themes\/bleuio\/images\/logo.png\"\n      \/&gt;\n      &lt;h1 class=\"mb-5\"&gt;Bluetooth LE Air quality sensor data to LCD screen&lt;\/h1&gt;\n\n      &lt;div class=\"row\"&gt;\n        &lt;div class=\"col-md-4 pt-5\"&gt;\n          &lt;button class=\"btn btn-success mb-2\" id=\"connect\"&gt;Connect&lt;\/button&gt;\n          &lt;form method=\"post\" id=\"sendDataForm\" name=\"sendMsgForm\" hidden&gt;\n            &lt;div class=\"mb-3\"&gt;\n              &lt;label for=\"sensorID\" class=\"form-label\"&gt;Sensor ID&lt;\/label&gt;\n              &lt;input\n                type=\"text\"\n                class=\"form-control\"\n                name=\"sensorID\"\n                id=\"sensorID\"\n                required\n                maxlength=\"60\"\n                value=\"0578E0\"\n              \/&gt;\n            &lt;\/div&gt;\n\n            &lt;button type=\"submit\" class=\"btn btn-primary\"&gt;Get Data&lt;\/button&gt;\n          &lt;\/form&gt;\n          &lt;br \/&gt;\n          &lt;button class=\"btn btn-danger\" id=\"clearScreen\" disabled&gt;\n            Clear screen\n          &lt;\/button&gt;\n        &lt;\/div&gt;\n        &lt;div class=\"col-md-8\"&gt;\n          &lt;img src=\"air_quality_lcd.jpg\" class=\"img-fluid\" \/&gt;\n        &lt;\/div&gt;\n      &lt;\/div&gt;\n    &lt;\/div&gt;\n\n    &lt;script src=\"script.js\"&gt;&lt;\/script&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<p>Create a js file called script.js and include it at the bottom of the Html file. This js file uses the BleuIO js library to write AT commands and communicate with the other dongle.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import * as my_dongle from 'bleuio'\nimport 'regenerator-runtime\/runtime'\n\nconst dongleToConnect='&#91;0]40:48:FD:E5:2F:17'\n\/\/const sensorID = '0578E0'\ndocument.getElementById('connect').addEventListener('click', function(){\n  my_dongle.at_connect()\n  document.getElementById(\"clearScreen\").disabled=false;\n  document.getElementById(\"connect\").disabled=true;\n  document.getElementById(\"sendDataForm\").hidden=false;\n})\n\ndocument.getElementById(\"sendDataForm\").addEventListener(\"submit\", function(event){\n    event.preventDefault()\n    const sensorID = document.getElementById('sensorID').value\n    getSensorData(sensorID)\n    setInterval(function () {getSensorData(sensorID)}, 10000);\n\n   \n  });\n\n  const getSensorData =((sensorID)=&gt;{\n    my_dongle.ati().then((data)=&gt;{\n        \/\/make central if not\n        if(JSON.stringify(data).includes(\"Peripheral\")){\n            console.log('peripheral')\n            my_dongle.at_dual().then((x)=&gt;{\n                console.log('central now')\n            })\n        }        \n    })\n    .then(()=&gt;{\n        \/\/ connect to dongle\n        my_dongle.at_getconn().then((y)=&gt;{\n            if(JSON.stringify(y).includes(dongleToConnect)){\n                console.log('already connected')\n            }else{\n                my_dongle.at_gapconnect(dongleToConnect).then(()=&gt;{\n                    console.log('connected successfully')\n                })\n            }\n        })\n        .then(async()=&gt;{\n           return my_dongle.at_findscandata(sensorID,6).then((sd)=&gt;{\n                console.log('scandata',sd)\n                let advData = sd&#91;sd.length - 1].split(\" \").pop()\n                let positionOfID= advData.indexOf(sensorID);\n                let tempHex = advData.substring(positionOfID+14, positionOfID+18)\n                let temp = parseInt('0x'+tempHex.match(\/..\/g).reverse().join(''))\/10;\n\n                let co2Hex = advData.substring(positionOfID+38, positionOfID+42)\n                let co2 = parseInt('0x'+co2Hex);\n                \/\/console.log(temp,co2)\n                return {\n                    'CO2' :co2,\n                    'Temp' :temp,                       \n                  }\n            })\n        })\n        .then((x)=&gt;{\n            console.log(x.CO2)\n            console.log(x.Temp)\n            var theVal = \"L=1 SENSOR ID \"+sensorID+\"    TEMPERATURE \" + x.Temp + ' \u00b0c    CO2 '+ x.CO2+' ppm';\n            console.log('Message Send 1 ')\n            \/\/ send command to show data\n            my_dongle.at_spssend(theVal).then(()=&gt;{\n                console.log('Message Send '+theVal)\n            })\n        })\n        \n    })\n})\n\ndocument.getElementById('clearScreen').addEventListener('click', function(){\n    my_dongle.ati().then((data)=&gt;{\n        \/\/make central if not\n        if(JSON.stringify(data).includes(\"Peripheral\")){\n            console.log('peripheral')\n            my_dongle.at_central().then((x)=&gt;{\n                console.log('central now')\n            })\n        }\n    })\n    .then(()=&gt;{\n        \/\/ connect to dongle\n        my_dongle.at_getconn().then((y)=&gt;{\n            if(JSON.stringify(y).includes(dongleToConnect)){\n                console.log('already connected')\n            }else{\n                my_dongle.at_gapconnect(dongleToConnect).then(()=&gt;{\n                    console.log('connected successfully')\n                })\n            }\n        })\n        .then(()=&gt;{\n            \/\/ send command to clear the screen\n            my_dongle.at_spssend('L=0').then(()=&gt;{\n                console.log('Screen Cleared')\n            })\n        })\n        \n    })\n})<\/code><\/pre>\n\n\n\n<p>The script has a button to connect to COM port on the computer. There is a text field where you can write sensor ID of the air quality monitor device. Once connected, the script will try to get advertised data from the sensor and convert it to a meaningful data. After that it will send this data to the STM32 board which then display on the LCD screen.<\/p>\n\n\n\n<p>To connect to the BleuIO dongle on the STM32, make sure the STM32 is powered up and a BleuIO dongle is connected to it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Get the MAC address<\/h3>\n\n\n\n<p>Follow the steps to get the MAC address of the dongle that is connected to STM32<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- Open this site https:\/\/bleuio.com\/web_terminal.html and click connect to dongle.\n- Select the appropriate port to connect.\n- Once it says connected, type ATI. This will show dongle information and current status.\n- If the dongle is on peripheral role, set it to central by typing AT+CENTRAL\n- Now do a gap scan by typing AT+GAPSCAN\n- Once you see your dongle on the list ,stop the scan by pressing control+c\n- Copy the ID and paste it into the script (script.js) line #4<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/scan_deviceid.gif\" alt=\"\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Run the web script<\/h3>\n\n\n\n<p>You will need a web bundler. You can use&nbsp;<a href=\"https:\/\/parceljs.org\/\">parcel.js<\/a><\/p>\n\n\n\n<p>Once parcel js installed, go to the root directory of web script and type&nbsp;<strong>\u201cparcel index.html\u201d<\/strong>. This will start your development environment.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/parcel_on.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Open the script on a browser. For this example we opened http:\/\/localhost:1234<\/p>\n\n\n\n<p>You can easily connect to the dongle and see air quality data on the LCD screen. The response will show on browser console screen.<\/p>\n\n\n\n<p>The web script looks like this<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"540\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/image-13-1024x540-1.png\" alt=\"\" class=\"wp-image-222\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/image-13-1024x540-1.png 1024w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/image-13-1024x540-1-300x158.png 300w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/image-13-1024x540-1-768x405.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<p>The message will show on the LCD screen.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"542\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/image-14.png\" alt=\"\" class=\"wp-image-223\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/image-14.png 800w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/image-14-300x203.png 300w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/image-14-768x520.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The aim of this&nbsp;Bluetooth LE project&nbsp;is to read air quality sensor data and show it on an LCD display which is connected to STM32 board. A web browser will read the sensor data and pass it to STM32 board using BleuIO. 1. Introduction The project is based on&nbsp;STM32 Nucleo-144&nbsp;which controls&nbsp;LCD display&nbsp;using BleuIO. For this project, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":224,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-221","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bleuio-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Show Bluetooth LE Sensor readings on LCD screen connected to STM32 - BleuIO - Create Bluetooth Low Energy application<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Show Bluetooth LE Sensor readings on LCD screen connected to STM32 - BleuIO - Create Bluetooth Low Energy application\" \/>\n<meta property=\"og:description\" content=\"The aim of this&nbsp;Bluetooth LE project&nbsp;is to read air quality sensor data and show it on an LCD display which is connected to STM32 board. A web browser will read the sensor data and pass it to STM32 board using BleuIO. 1. Introduction The project is based on&nbsp;STM32 Nucleo-144&nbsp;which controls&nbsp;LCD display&nbsp;using BleuIO. For this project, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/\" \/>\n<meta property=\"og:site_name\" content=\"BleuIO - Create Bluetooth Low Energy application\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-14T15:22:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-01T10:25:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/air-quality-lcd-data.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1768\" \/>\n\t<meta property=\"og:image:height\" content=\"939\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"BleuIO\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/\"},\"author\":{\"name\":\"BleuIO\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\"},\"headline\":\"Show Bluetooth LE Sensor readings on LCD screen connected to STM32\",\"datePublished\":\"2022-03-14T15:22:22+00:00\",\"dateModified\":\"2022-07-01T10:25:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/\"},\"wordCount\":980,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/air-quality-lcd-data.jpg\",\"articleSection\":[\"BleuIO tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/\",\"name\":\"Show Bluetooth LE Sensor readings on LCD screen connected to STM32 - BleuIO - Create Bluetooth Low Energy application\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/air-quality-lcd-data.jpg\",\"datePublished\":\"2022-03-14T15:22:22+00:00\",\"dateModified\":\"2022-07-01T10:25:34+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/air-quality-lcd-data.jpg\",\"contentUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/air-quality-lcd-data.jpg\",\"width\":1768,\"height\":939,\"caption\":\"BLE air quality lcd data\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Show Bluetooth LE Sensor readings on LCD screen connected to STM32\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/\",\"name\":\"BleuIO - Create Bluetooth Low Energy application\",\"description\":\"Learn Bluetooth Low Energy programming and build Bluetooth Low Energy Application\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\",\"name\":\"BleuIO\",\"sameAs\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\"],\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/author\\\/biadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Show Bluetooth LE Sensor readings on LCD screen connected to STM32 - BleuIO - Create Bluetooth Low Energy application","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/","og_locale":"en_US","og_type":"article","og_title":"Show Bluetooth LE Sensor readings on LCD screen connected to STM32 - BleuIO - Create Bluetooth Low Energy application","og_description":"The aim of this&nbsp;Bluetooth LE project&nbsp;is to read air quality sensor data and show it on an LCD display which is connected to STM32 board. A web browser will read the sensor data and pass it to STM32 board using BleuIO. 1. Introduction The project is based on&nbsp;STM32 Nucleo-144&nbsp;which controls&nbsp;LCD display&nbsp;using BleuIO. For this project, [&hellip;]","og_url":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/","og_site_name":"BleuIO - Create Bluetooth Low Energy application","article_published_time":"2022-03-14T15:22:22+00:00","article_modified_time":"2022-07-01T10:25:34+00:00","og_image":[{"width":1768,"height":939,"url":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/air-quality-lcd-data.jpg","type":"image\/jpeg"}],"author":"BleuIO","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/#article","isPartOf":{"@id":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/"},"author":{"name":"BleuIO","@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80"},"headline":"Show Bluetooth LE Sensor readings on LCD screen connected to STM32","datePublished":"2022-03-14T15:22:22+00:00","dateModified":"2022-07-01T10:25:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/"},"wordCount":980,"commentCount":0,"image":{"@id":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/air-quality-lcd-data.jpg","articleSection":["BleuIO tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/","url":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/","name":"Show Bluetooth LE Sensor readings on LCD screen connected to STM32 - BleuIO - Create Bluetooth Low Energy application","isPartOf":{"@id":"https:\/\/www.bleuio.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/#primaryimage"},"image":{"@id":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/air-quality-lcd-data.jpg","datePublished":"2022-03-14T15:22:22+00:00","dateModified":"2022-07-01T10:25:34+00:00","author":{"@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80"},"breadcrumb":{"@id":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/#primaryimage","url":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/air-quality-lcd-data.jpg","contentUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/air-quality-lcd-data.jpg","width":1768,"height":939,"caption":"BLE air quality lcd data"},{"@type":"BreadcrumbList","@id":"https:\/\/www.bleuio.com\/blog\/show-bluetooth-le-sensor-readings-on-lcd-screen-connected-to-stm32\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.bleuio.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Show Bluetooth LE Sensor readings on LCD screen connected to STM32"}]},{"@type":"WebSite","@id":"https:\/\/www.bleuio.com\/blog\/#website","url":"https:\/\/www.bleuio.com\/blog\/","name":"BleuIO - Create Bluetooth Low Energy application","description":"Learn Bluetooth Low Energy programming and build Bluetooth Low Energy Application","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bleuio.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80","name":"BleuIO","sameAs":["https:\/\/www.bleuio.com\/blog"],"url":"https:\/\/www.bleuio.com\/blog\/author\/biadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":3,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":376,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/221\/revisions\/376"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/media\/224"}],"wp:attachment":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}