{"id":21394,"date":"2021-07-11T09:28:40","date_gmt":"2021-07-11T00:28:40","guid":{"rendered":"https:\/\/www.souichi.club\/?p=21394"},"modified":"2022-03-19T17:23:57","modified_gmt":"2022-03-19T08:23:57","slug":"m5stickc-ble","status":"publish","type":"post","link":"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/","title":{"rendered":"I tried BLE (Bluetooth Low Energy) communication between M5StickC and Raspberry Pi4"},"content":{"rendered":"<ul class=\"bogo-language-switcher list-view\"><li class=\"en-US en current first\"><span class=\"bogoflags bogoflags-us\"><\/span> <span class=\"bogo-language-name\"><a rel=\"alternate\" hreflang=\"en-US\" href=\"https:\/\/www.souichi.club\/en\/wp-json\/wp\/v2\/posts\/21394\/\" title=\"English\" class=\"current\" aria-current=\"page\">English<\/a><\/span><\/li>\n<li class=\"ja last\"><span class=\"bogoflags bogoflags-jp\"><\/span> <span class=\"bogo-language-name\"><a rel=\"alternate\" hreflang=\"ja\" href=\"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21394\/\" title=\"Japanese\">\u65e5\u672c\u8a9e<\/a><\/span><\/li>\n<\/ul>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f2acb75b04b\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #454e5c;color:#454e5c\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #454e5c;color:#454e5c\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f2acb75b04b\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Advertising_with_BLE\" >Advertising with BLE<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#What_is_BLE\" >What is BLE?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Supported_Versions\" >Supported Versions<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Overall_configuration_diagram\" >Overall configuration diagram<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Required_equipment\" >Required equipment<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#M5StickC\" >M5StickC<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Temperature_humidity_and_air_pressure_sensors\" >Temperature, humidity, and air pressure sensors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Grove_general-purpose_cable\" >Grove general-purpose cable<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Jumper_wire_set\" >Jumper wire set<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Raspberry_Pi_4B\" >Raspberry Pi 4B<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Tools_used\" >Tools used<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Soldering_iron\" >Soldering iron<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Solder\" >Solder<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Stand_loupe\" >Stand loupe<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Electricians_pliers\" >Electrician&#8217;s pliers<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Assembly\" >Assembly<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Soldering_the_BME280\" >Soldering the BME280<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Making_the_connector\" >Making the connector<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Wiring_Diagram\" >Wiring Diagram<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Building_the_Environment\" >Building the Environment<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Arduino_IDE\" >Arduino IDE<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Raspberry_Pi\" >Raspberry Pi<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Sketch_Program\" >Sketch (Program)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#M5StickC-2\" >M5StickC<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#source-code\" >source-code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Supplemental_Information\" >Supplemental Information<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Transmission_and_Deep_Sleep\" >Transmission and Deep Sleep<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#setAdvData\" >setAdvData<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Little_Endian\" >Little Endian<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#M5Lcdprintf\" >M5.Lcd.printf<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Raspberry_Pi_4\" >Raspberry Pi 4<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#directory_structure\" >directory structure<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#source-code-2\" >source-code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#supplementary_explanation\" >supplementary explanation<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Execution_result\" >Execution result<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#bluetoothctl\" >bluetoothctl<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Program_the_Raspberry_Pi_4\" >Program the Raspberry Pi 4<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-38\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#About_the_reach_distance\" >About the reach distance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-39\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc-ble\/#Finally\" >Finally.<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Advertising_with_BLE\"><\/span>Advertising with BLE<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>I used the M5StickC and BME280 sensor module to measure temperature, humidity, and air pressure, and advertise (broadcast) the measurement results via BLE (Bluetooth Low Energy).<\/p>\n\n\n\n<p>I made a program to scan BLE with a Raspy (RaspberryPi 4B) and receive the data asynchronously.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_BLE\"><\/span>What is BLE?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>BLE (Bluetooth Low Energy) is one of the extended specifications of Bluetooth that enables energy-saving wireless communication.<\/p>\n\n\n\n<p>The first standard, Bluetooth 1.0, had a transmission range of several meters and was mainly used for communication with mice and PC peripherals.<\/p>\n\n\n\n<p>Bluetooth 4.0 has a range of about 100 meters, and Bluetooth 5.0 is said to have a range of about 400 meters when the data rate is set to a low speed of 125 kbps.<\/p>\n\n\n\n<p>The latest version, Bluetooth 5.1, has a new function to detect direction.<\/p>\n\n\n<figure class=\"wp-block-table is-style-regular\">\n<table class=\"r_table01\">\n<tbody>\n<tr>\n<td class=\"r_td30\">\n<p>Bluetooth4.2<\/p>\n<\/td>\n<td>\n<p>Data rate: 1Mbps<\/p>\n<p>Reaching distance: several tens of meters to 100 meters<\/p>\n<p>Message capacity: 31Byte<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Bluetooth5.0<\/p>\n<\/td>\n<td>\n<p>Data rate: 2Mbps\u30011Mbps\u3001500kbps\u3001125kbps<\/p>\n<p>Reaching distance: 2-1Mbps 100m, 125kbps 400m<\/p>\n<p>Message capacity: 255Byte<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Bluetooth5.1<\/p>\n<\/td>\n<td>\n<p>This version has a function to detect the direction of the pairing partner.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Supported_Versions\"><\/span>Supported Versions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The Bluetooth versions supported by each device are as follows.<\/p>\n\n\n<figure class=\"wp-block-table is-style-regular\">\n<table class=\"r_table01\">\n<tbody>\n<tr>\n<td class=\"r_td30\">\n<p>Raspberry Pi Zero<\/p>\n<\/td>\n<td>\n<p>Bluetooth 4.1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Raspberry Pi 3 Model B+&nbsp;<\/p>\n<\/td>\n<td>\n<p>Bluetooth4.2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Raspberry Pi 4 Model B<\/p>\n<\/td>\n<td>\n<p>Bluetooth 5.0<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>M5StickC\uff08ESP32-PICO-D4\uff09<\/p>\n<\/td>\n<td>\n<p>Bluetooth 4.2<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>This time, the communication between the M5StickC and the Raspberry Pi 4 B is supposed to be Bluetooth 4.2 standard.<\/p>\n<p>The speed is slower than Wi-Fi, but it&#8217;s energy efficient, so I think it will be very useful for measuring temperature and humidity in places where power is not available.<\/p>\n<p>The BLE is so energy efficient that it is said to be able to run for a year on a button battery.<\/p>\n<p>Therefore, I think the lithium battery in the M5StickC can last for quite a long time depending on the programming.<\/p>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Overall_configuration_diagram\"><\/span>Overall configuration diagram<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The overall configuration diagram is as follows.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-01.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-01.png?resize=768%2C369&#038;ssl=1\" alt=\"Advertizing with BLE\" class=\"wp-image-21898\" width=\"768\" height=\"369\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-01.png?resize=1024%2C492&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-01.png?resize=300%2C144&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-01.png?resize=768%2C369&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-01.png?resize=1536%2C738&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-01.png?w=1756&amp;ssl=1 1756w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Attach a temperature, humidity, and air pressure measurement sensor (BME280) to the HY2.0-4P terminal of the M5StickC<\/li><li>Advertise (broadcast) the values acquired by the sensor via BLE for 10 seconds<\/li><li>Scan the signal with BLE on Raspberry Pi 4 and display it on the console<\/li><li>Data communication is asynchronous, not pairing.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Required_equipment\"><\/span>Required equipment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The equipment we prepared is as follows.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"M5StickC\"><\/span>M5StickC<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>M5StickC is used to connect temperature, humidity, and barometric pressure sensors and advertise them via BLE.<\/p>\n\n\n\n<p>The chip (ESP32-PICO-D4) in the M5StickC can communicate via Wi-Fi as well as Bluetooth.<\/p>\n\n\n\n<p>However, I tried to communicate via Bluetooth to save energy, assuming that we would be able to operate it in places where we could not secure a power supply.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-07.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-07.jpg?resize=512%2C277&#038;ssl=1\" alt=\"M5StickC set\" class=\"wp-image-21957\" width=\"512\" height=\"277\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-07.jpg?resize=1024%2C554&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-07.jpg?resize=300%2C162&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-07.jpg?resize=768%2C415&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-07.jpg?resize=1536%2C830&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-07.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Temperature_humidity_and_air_pressure_sensors\"><\/span>Temperature, humidity, and air pressure sensors<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Sensor module (BME280) for measuring temperature, humidity, and barometric pressure.<\/p>\n\n\n\n<p>The power supply from the M5StickC is 5.0V, so I chose a type that has a voltage regulator and can use both 3.3V and 5.0V.<\/p>\n\n\n\n<p>Connect it to the HY2.0-4P (Grove compatible terminal) of the M5StickC.<\/p>\n\n\n\n<p>For more information on the BME280&#8217;s measurement range and error, please refer to the previous article.<\/p>\n\n\n\n<p>The terminals are<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>VIN (both 3.3 and 5.0V can be used)<\/li><li>GND<\/li><li>SCL<\/li><li>SDA<\/li><\/ul>\n\n\n\n<p>It is connected to the M5StickC via I2C (Inter-Integrated Circuit) communication.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-08.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-08.jpg?resize=256%2C181&#038;ssl=1\" alt=\"BME280 module\" class=\"wp-image-21959\" width=\"256\" height=\"181\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-08.jpg?resize=1024%2C722&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-08.jpg?resize=300%2C212&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-08.jpg?resize=768%2C541&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-08.jpg?resize=1536%2C1083&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-08.jpg?w=1773&amp;ssl=1 1773w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Grove_general-purpose_cable\"><\/span>Grove general-purpose cable<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>This cable is used to connect the M5StickC&#8217;s HY2.0-4P (Grove compatible terminal) to the BME280.<\/p>\n\n\n\n<p>This cable has Grove terminals on both ends, so the BME280 side will need to be modified.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-09.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-09.jpg?resize=256%2C227&#038;ssl=1\" alt=\"Grove cable\" class=\"wp-image-21960\" width=\"256\" height=\"227\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-09.jpg?resize=1024%2C906&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-09.jpg?resize=300%2C265&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-09.jpg?resize=768%2C680&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-09.jpg?resize=1536%2C1359&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-09.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Jumper_wire_set\"><\/span>Jumper wire set<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The above Grove general-purpose cable has Grove terminals on both ends, so I changed the BME280 side to a 4-pin female jumper wire set.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-10.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-10.jpg?resize=512%2C266&#038;ssl=1\" alt=\"Jumper wire set\" class=\"wp-image-21961\" width=\"512\" height=\"266\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-10.jpg?resize=1024%2C531&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-10.jpg?resize=300%2C155&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-10.jpg?resize=768%2C398&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-10.jpg?resize=1536%2C796&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-10.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Raspberry_Pi_4B\"><\/span>Raspberry Pi 4B<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I used a Raspberry Pi 4B that I had on hand, but I think a Raspberry Pi Zero would work just as well.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-11.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-11.jpg?resize=512%2C296&#038;ssl=1\" alt=\"Raspberry Pi 4B\" class=\"wp-image-21962\" width=\"512\" height=\"296\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-11.jpg?resize=1024%2C592&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-11.jpg?resize=300%2C173&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-11.jpg?resize=768%2C444&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-11.jpg?resize=1536%2C888&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-11.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Tools_used\"><\/span>Tools used<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The tools used were as follows<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Soldering_iron\"><\/span>Soldering iron<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A soldering iron was used to fix the connector pins to the temperature, humidity, and barometric pressure sensor module (BME280).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-12.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-12.jpg?resize=512%2C279&#038;ssl=1\" alt=\"Soldering iron\" class=\"wp-image-21963\" width=\"512\" height=\"279\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-12.jpg?resize=1024%2C557&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-12.jpg?resize=300%2C163&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-12.jpg?resize=768%2C418&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-12.jpg?resize=1536%2C835&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-12.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Solder\"><\/span>Solder<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Any kind of leaded solder for electronic work is fine.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-13.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-13.jpg?resize=512%2C158&#038;ssl=1\" alt=\"Solder\" class=\"wp-image-21964\" width=\"512\" height=\"158\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-13.jpg?resize=1024%2C315&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-13.jpg?resize=300%2C92&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-13.jpg?resize=768%2C236&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-13.jpg?resize=1536%2C473&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-13.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Stand_loupe\"><\/span>Stand loupe<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The stand loupe makes it easier to work with.<\/p>\n\n\n\n<p>The LED lights up your hand and the loupe magnifies it, so you can see better, and since the base is fixed, it is easier to solder.<\/p>\n\n\n\n<p>I&#8217;m not good at soldering, so I need a stand loupe.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-15.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-15.jpg?resize=512%2C443&#038;ssl=1\" alt=\"Stand loupe\" class=\"wp-image-21966\" width=\"512\" height=\"443\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-15.jpg?resize=1024%2C885&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-15.jpg?resize=300%2C259&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-15.jpg?resize=768%2C664&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-15.jpg?resize=1536%2C1328&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-15.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Electricians_pliers\"><\/span>Electrician&#8217;s pliers<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Electrician&#8217;s pliers<br>I used these to cut off one of the Grove compatible terminals and replace it with a 4-pin jumper wire.<\/p>\n\n\n\n<p>Small electric pliers are easier to handle than large ones.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-14.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-14.jpg?resize=512%2C249&#038;ssl=1\" alt=\"Electrician's pliers\" class=\"wp-image-21965\" width=\"512\" height=\"249\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-14.jpg?resize=1024%2C498&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-14.jpg?resize=300%2C146&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-14.jpg?resize=768%2C373&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-14.jpg?resize=1536%2C746&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-14.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Assembly\"><\/span>Assembly<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Soldering_the_BME280\"><\/span>Soldering the BME280<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The BME280 module that I purchased had separate pins and modules as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-04.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-04.jpg?resize=256%2C153&#038;ssl=1\" alt=\"BME280\" class=\"wp-image-18255\" width=\"256\" height=\"153\" title=\"BME280\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-04.jpg?resize=1024%2C613&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-04.jpg?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-04.jpg?resize=768%2C460&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-04.jpg?w=1280&amp;ssl=1 1280w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><\/figure>\n\n\n\n<p>Solder the pins to the module.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-05.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-05.jpg?resize=512%2C327&#038;ssl=1\" alt=\"Soldering the BME280\" class=\"wp-image-18256\" width=\"512\" height=\"327\" title=\"Soldering the BME280\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-05.jpg?resize=1024%2C653&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-05.jpg?resize=300%2C191&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-05.jpg?resize=768%2C490&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-05.jpg?w=1280&amp;ssl=1 1280w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Making_the_connector\"><\/span>Making the connector<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The Grove general-purpose cable I bought had Grove terminals on both ends, so I cut off one end and replaced it with a 4-pin jumper wire.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-06.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-06.jpg?resize=512%2C273&#038;ssl=1\" alt=\"Creating a connector and connecting it to the M5StickC\" class=\"wp-image-18257\" width=\"512\" height=\"273\" title=\"Creating a connector and connecting it to the M5StickC\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-06.jpg?resize=1024%2C546&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-06.jpg?resize=300%2C160&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-06.jpg?resize=768%2C409&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-06.jpg?w=1280&amp;ssl=1 1280w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Wiring_Diagram\"><\/span>Wiring Diagram<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The wiring diagram for the M5StickC and BME280 is shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-16.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-16.png?resize=768%2C415&#038;ssl=1\" alt=\"Wiring between M5StickC and BME280\" class=\"wp-image-21969\" width=\"768\" height=\"415\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-16.png?resize=1024%2C553&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-16.png?resize=300%2C162&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-16.png?resize=768%2C414&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-16.png?w=1364&amp;ssl=1 1364w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Building_the_Environment\"><\/span>Building the Environment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Install the Arduino IDE, the development environment for the M5StickC, on your computer.<\/p>\n\n\n\n<p>Also, install the necessary libraries and modules on the Raspberry Pi 4B in advance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Arduino_IDE\"><\/span>Arduino IDE<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I installed the Arduino IDE (Integrated Development Environment) on my Windows 10 machine, which is my development environment.<\/p>\n\n\n\n<p>For details on the installation procedure, please <a href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc\/#arduinoidedownload\" target=\"_blank\" rel=\"noreferrer noopener\">refer to the previous article<\/a>.<\/p>\n\n\n\n<p>The next step is to install the Adafruit BME280 library in the Arduino IDE, the development environment for the M5StickC.<\/p>\n\n\n\n<p>Start the Arduino IDE and select Sketch, Include Library, Manage Libraries.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-17.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-17.png?resize=768%2C475&#038;ssl=1\" alt=\"Manage Libraries\" class=\"wp-image-21972\" width=\"768\" height=\"475\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-17.png?resize=1024%2C633&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-17.png?resize=300%2C185&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-17.png?resize=768%2C475&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-17.png?w=1346&amp;ssl=1 1346w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<p>Search for \u2033BME280\u2033 in the search field and install the &#8220;Adafruit BME280 Library&#8221; that appears.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-18.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-18.png?resize=738%2C416&#038;ssl=1\" alt=\"install the Adafruit BME280 Library \" class=\"wp-image-21973\" width=\"738\" height=\"416\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-18.png?w=984&amp;ssl=1 984w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-18.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-18.png?resize=768%2C432&amp;ssl=1 768w\" sizes=\"auto, (max-width: 738px) 100vw, 738px\" \/><\/a><\/figure>\n\n\n\n<p>I selected &#8220;install all&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-11.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-11.png?resize=515%2C185&#038;ssl=1\" alt=\"Select Install all\" class=\"wp-image-18296\" width=\"515\" height=\"185\" title=\"Select Install all\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-11.png?w=686&amp;ssl=1 686w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-11.png?resize=300%2C108&amp;ssl=1 300w\" sizes=\"auto, (max-width: 515px) 100vw, 515px\" \/><\/a><figcaption>R<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Raspberry_Pi\"><\/span>Raspberry Pi<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Install bluepy, a module for controlling Bluetooth devices from Python, on the Raspberry Pi with the following command.<\/p>\n\n\n<pre><code class=\"lang-shell\">sudo pip3 install bluepy<\/code><\/pre>\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-19.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-19.png?resize=768%2C479&#038;ssl=1\" alt=\"Install  bluepy\" class=\"wp-image-21983\" width=\"768\" height=\"479\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-19.png?resize=1024%2C638&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-19.png?resize=300%2C187&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-19.png?resize=768%2C478&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-19.png?w=1026&amp;ssl=1 1026w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sketch_Program\"><\/span>Sketch (Program)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"M5StickC-2\"><\/span>M5StickC<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The M5StickC program for the side that measures and advertises (broadcasts) temperature, humidity, and barometric pressure is as follows.<\/p>\n\n\n\n<p>It is coded in Arduino IDE (C++) with reference to <a href=\"http:\/\/pages.switch-science.com\/letsiot\/blegw_rpi\/\" target=\"_blank\" rel=\"noreferrer noopener\">Switch Science&#8217;s website<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"source-code\"><\/span>source-code<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>ble_pub_en.ino<\/p>\n\n\n<pre class=\"line-numbers\"><code class=\"language-cpp\">#include &lt;M5StickC.h&gt;\n#include &lt;BLEDevice.h&gt; \/\/ Bluetooth Low Energy \n#include &lt;BLEServer.h&gt; \/\/ Bluetooth Low Energy\n#include &lt;BLEUtils.h&gt; \/\/ Bluetooth Low Energy\n#include &lt;esp_sleep.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n#include &lt;Adafruit_BME280.h&gt;\n\n#define T_PERIOD 10 \/\/ Number of seconds to send advertizing packets\n#define S_PERIOD 20 \/\/ Number of seconds to Deep Sleep\n\nRTC_DATA_ATTR static uint8_t seq; \/\/ Send SEQ\nAdafruit_BME280 bme;\n\nuint16_t temp; \/\/ Temperature\nuint16_t humid; \/\/ Humidity\nuint16_t press; \/\/ barometric pressure\nuint16_t vbat; \/\/ Voltage\n\nvoid setAdvData(BLEAdvertising *pAdvertising) { \/\/ Formatting Advertising Packets\n    BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();\n\n    oAdvertisementData.setFlags(0x06); \/\/ BR_EDR_NOT_SUPPORTED | General Discoverable Mode\n    \/\/ oAdvertisementData.setFlags(0x05); \/\/ BR_EDR_NOT_SUPPORTED | Limited Discoverable Mode\n\n    std::string strServiceData = \"\";\n    strServiceData += (char)0x0c; \/\/ Length(12Byte)\n    strServiceData += (char)0xff; \/\/ AD Type 0xFF: Manufacturer specific data\n    strServiceData += (char)0xff; \/\/ Test manufacture ID low byte\n    strServiceData += (char)0xff; \/\/ Test manufacture ID high byte\n    strServiceData += (char)seq; \/\/ sequence number\n    strServiceData += (char)(temp &amp; 0xff); \/\/ Lower byte of temperature\n    strServiceData += (char)((temp &gt;&gt; 8) &amp; 0xff); \/\/ Upper byte of temperature\n    strServiceData += (char)(humid &amp; 0xff);  \/\/ Lower byte of Humidity\n    strServiceData += (char)((humid &gt;&gt; 8) &amp; 0xff); \/\/ Upper byte of Humidity\n    strServiceData += (char)(press &amp; 0xff); \/\/ Lower byte of Pressure\n    strServiceData += (char)((press &gt;&gt; 8) &amp; 0xff); \/\/ Upper byte of Pressure\n    strServiceData += (char)(vbat &amp; 0xff); \/\/ Lower byte of Voltage\n    strServiceData += (char)((vbat &gt;&gt; 8) &amp; 0xff); \/\/ Upper byte of Voltage\n\n    oAdvertisementData.addData(strServiceData);\n    pAdvertising-&gt;setAdvertisementData(oAdvertisementData);\n}\n\nvoid setup() {\n    M5.begin();\n    M5.Axp.ScreenBreath(10); \/\/ Reduce the brightness of the screen\n    M5.Lcd.setRotation(1); \/\/ Change the direction of the LCD\n    M5.Lcd.setTextSize(2); \/\/ Set font size to 2\n    M5.Lcd.setTextColor(WHITE, BLACK); \/\/ White for text, black for background\n\n    Wire.begin(); \/\/ I2C initialization\n    while (!bme.begin(0x76)) { \/\/ BMP280 initialization\n        M5.Lcd.println(\"BMP280 init failed\");\n    }\n \n    temp = (uint16_t)(bme.readTemperature() * 100); \/\/ Obtain temperature (multiply by 100 and change decimal point to integer part)\n    humid = (uint16_t)(bme.readHumidity() * 100); \/\/ Acquire humidity (multiply by 100 and change decimal point to integer part)\n    press = (uint16_t)(bme.readPressure()\/100); \/\/ Acquisition of air pressure (converted from pa to hPa)\n    vbat = (uint16_t)(M5.Axp.GetVbatData() * 1.1 \/ 1000 * 100); \/\/ Battery voltage's up 100 times.\n\n    M5.Lcd.setCursor(0, 0, 1); \/\/ cursor position\n    M5.Lcd.printf(\"temp: %4.1f'C\\r\\n\", (float)temp \/ 100);\n    M5.Lcd.printf(\"humid:%4.1f%%\\r\\n\", (float)humid \/ 100);\n    M5.Lcd.printf(\"press:%4.0fhPa\\r\\n\", (float)press);\n    M5.Lcd.printf(\"vbat: %4.2fV\\r\\n\", (float)vbat \/ 100);\n\n    BLEDevice::init(\"blepub-01\"); \/\/ Initialize the device\n    BLEServer *pServer = BLEDevice::createServer();  \/\/ Create a server\n\n    BLEAdvertising *pAdvertising = pServer-&gt;getAdvertising(); \/\/ Get the advertised object.\n    setAdvData(pAdvertising); \/\/ Set the advertizing data.\n\n    pAdvertising-&gt;start();\n    delay(T_PERIOD * 1000); \/\/ Advertise T_PERIOD seconds\n    pAdvertising-&gt;stop();\n\n    seq++; \/\/ Count up the sequence number\n    delay(10);\n    esp_deep_sleep(1000000LL * S_PERIOD); \/\/ S_PERIOD seconds to Deep Sleep\n}\n\nvoid loop() {\n}<\/code><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Supplemental_Information\"><\/span>Supplemental Information<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Transmission_and_Deep_Sleep\"><\/span>Transmission and Deep Sleep<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>T_PERIOD specifies the number of seconds to advertise (broadcast) (10 seconds).<\/p>\n\n\n\n<p>S_PERIOD specifies the number of seconds for DeepSleep (20 seconds).<\/p>\n\n\n\n<p>In this program, it transmits for 10 seconds and sleeps for 20 seconds, but if you want to measure temperature, humidity, and air pressure at 5-minute intervals, you can use 4 minutes and 50 seconds (250 seconds).<\/p>\n\n\n\n<p>ESP32 has the following 5 modes.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Active mode\uff1a100mA\uff5e240mA<\/li><li>Modem-sleep mode\uff1a20mA\uff5e25mA\uff08Single-core\uff09<\/li><li>Light-sleep mode\uff1a0.8mA\uff08800\u00b5A\uff09<\/li><li>Deep-sleep mode\uff1a10\u00b5A\uff5e150\u00b5A<\/li><li>Hibernation mode\uff1a5\u00b5A<\/li><\/ol>\n\n\n\n<p>In Deep Sleep mode, the power consumption is quite low.<\/p>\n\n\n\n<p>In this program, we use esp_deep_sleep() for Deep Sleep.<\/p>\n\n\n\n<p>There are many examples on the Internet where you can specify the time to wakeup with esp_sleep_enable_timer_wakeup() and start Deep Sleep with esp_deep_sleep_start().<\/p>\n\n\n\n<p>Since esp_deep_sleep() internally calls esp_sleep_enable_timer_wakeup() and esp_deep_sleep_start() in succession, the process is the same.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"setAdvData\"><\/span>setAdvData<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>Assemble the data to be advertised.<\/p>\n\n\n\n<p>Since the M5StickC is Bluetooth 4.2, the message size that can be sent is limited to 31Byte.<\/p>\n\n\n\n<p>The layout of the data to be advertised is as follows (<a href=\"https:\/\/www.bluetooth.com\/specifications\/specs\/\" target=\"_blank\" rel=\"noreferrer noopener\">from Bluetooth.com<\/a>)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-13.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"824\" height=\"442\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-13.png?resize=824%2C442&#038;ssl=1\" alt=\"Advertising\u30c7\u30fc\u30bf\u30ec\u30a4\u30a2\u30a6\u30c8\" class=\"wp-image-18299\" title=\"Advertising\u30c7\u30fc\u30bf\u30ec\u30a4\u30a2\u30a6\u30c8\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-13.png?w=824&amp;ssl=1 824w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-13.png?resize=300%2C161&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-13.png?resize=768%2C412&amp;ssl=1 768w\" sizes=\"auto, (max-width: 824px) 100vw, 824px\" \/><\/a><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Length: Data length (1 octet)<\/li><li>AD Type: AD Type + Company ID (3 octets)<\/li><li>AD Data: SEQ, temperature, humidity, barometric pressure, voltage (9 octets)<\/li><\/ul>\n\n\n\n<p>It consists of the above.<\/p>\n\n\n\n<p>0xff (AD Type) represents the manufacturer-specific data, and the following two octets (2Byte) represent the company ID.<\/p>\n\n\n\n<p>For the company ID, I used a dummy value of 0xff\u00d72, but if you want to use it in a production environment, you need to join the Bluetooth SIG (Special Interest Group) and apply for and obtain a company ID.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Little_Endian\"><\/span>Little Endian<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>Temperature, humidity, and other values (two octets) are stored in little-endian format, with the upper and lower levels reversed.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"M5Lcdprintf\"><\/span>M5.Lcd.printf<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>Lines 62-65 show the temperature, humidity, barometric pressure, and voltage on the M5StickC display so that you can check the values.<\/p>\n\n\n\n<p>If you want to make the lithium battery last longer, you don&#8217;t need this display, for example, you can change it to show only when a button is pressed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Raspberry_Pi_4\"><\/span>Raspberry Pi 4<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The program for the Raspberry Pi 4B on the receiving end of the data is as follows.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"directory_structure\"><\/span>directory structure<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Created a directory under &#8220;.local&#8221;<\/p>\n\n\n<pre><code class=\"lang-shell\">\u251c\u2500$HOME\n\u2502  \u2502      \n\u2502  \u251c\u2500.local\n\u2502  \u2502  \u2502\n\u2502  \u2502  \u251c\u2500\u2500ble_sub\n\u2502  \u2502  \u2502  \u2502\n\u2502  \u2502  \u2502  \u251c\u2500\u2500ble_sub_en.py ... python script\n\u2502  \u2502  \u2502  \u2502<\/code><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"source-code-2\"><\/span>source-code<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>ble_sub_en.py<\/p>\n\n\n<pre class=\"line-numbers\"><code class=\"lang-python\"># -*- coding: utf-8 -*-\n#\n# Scan the BLE and display the data.\n#\nfrom bluepy.btle import DefaultDelegate, Scanner, BTLEException\nimport sys\nimport struct\nfrom datetime import datetime\n\nclass ScanDelegate(DefaultDelegate):\n    def __init__(self): # constructor\n        DefaultDelegate.__init__(self)\n        self.lastseq = None\n        self.lasttime = datetime.fromtimestamp(0)\n\n    def handleDiscovery(self, dev, isNewDev, isNewData):\n        if isNewDev or isNewData: # New device or new data\n            for (adtype, desc, value) in dev.getScanData(): # Repeat as many times as there are data\n                if desc == 'Manufacturer' and value[0:4] == 'ffff': # Test companyID\n                    __delta = datetime.now() - self.lasttime\n                    # Only use the first one retrieved.\n                    if value[4:6] != self.lastseq and __delta.total_seconds() &gt; 11:\n                        self.lastseq = value[4:6] # Save Seq and time\n                        self.lasttime = datetime.now()\n                        (temp, humid, press, volt) = struct.unpack('&lt;hhhh', bytes.fromhex(value[6:])) # h is a 2Byte integer\n                        print('Temp= {0} \u00b0C, Humi= {1} %, Pres= {2} hPa, Volt= {3} V'.format( temp \/ 100, humid \/ 100, press, volt\/100))\n\nif __name__ == \"__main__\":\n    scanner = Scanner().withDelegate(ScanDelegate())\n    while True:\n        try:\n            scanner.scan(5.0) # Let ScanDelegate take care of the rest after finding the device.\n        except BTLEException:\n            ex, ms, tb = sys.exc_info()\n            print('BLE exception '+str(type(ms)) + ' at ' + sys._getframe().f_code.co_name)<\/code><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"supplementary_explanation\"><\/span>supplementary explanation<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Scan while looping with a while statement to extract the data advertised by M5StickC.<\/p>\n\n\n\n<p>When the data is received, the handleDiscovery method of the ScanDelegate class is called to extract only the data whose company ID is 0xffff.<\/p>\n\n\n\n<p>Extract the packed binary data with struct.unpack in line 25.<\/p>\n\n\n\n<p>&#8220;&lt;&#8221; represents little-endian, and &#8220;h&#8221; represents integer (2Byte).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Execution_result\"><\/span>Execution result<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>After writing the program and turning on the power of the M5StickC, the advertisement starts immediately.<\/p>\n\n\n\n<p>At the same time, temperature, humidity, barometric pressure, and voltage information are shown on the display.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-14.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-14.jpg?resize=512%2C340&#038;ssl=1\" alt=\"M5StickC\" class=\"wp-image-18311\" width=\"512\" height=\"340\" title=\"M5StickC\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-14.jpg?resize=1024%2C680&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-14.jpg?resize=300%2C199&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-14.jpg?resize=768%2C510&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-14.jpg?w=1280&amp;ssl=1 1280w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"bluetoothctl\"><\/span>bluetoothctl<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Before running the program on the Raspberry Pi 4, check if the data is being received using the interactive bluetoothctl command in LXTerminal.<\/p>\n\n\n<pre><code class=\"lang-shell\">bluetoothctl\nshow\nscan on<\/code><\/pre>\n\n\n<ul class=\"wp-block-list\"><li>show: Display Bluetooth information<\/li><li>scan on: Display information received via BLE<\/li><li>quit: Quit bluetoothctl<\/li><\/ul>\n\n\n\n<p>The data with the key of 0xffff (company ID) is the data from this program, so it is received normally.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-20.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-20.png?resize=768%2C479&#038;ssl=1\" alt=\"bluetoothctl command\" class=\"wp-image-21987\" width=\"768\" height=\"479\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-20.png?resize=1024%2C638&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-20.png?resize=300%2C187&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-20.png?resize=768%2C478&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-20.png?w=1026&amp;ssl=1 1026w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Program_the_Raspberry_Pi_4\"><\/span>Program the Raspberry Pi 4<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Run the program on the Raspberry Pi 4B.<\/p>\n\n\n\n<p>Note that root privileges are required to access the device via Bluetooth.<\/p>\n\n\n\n<p>Therefore, it is necessary to run the program with &#8220;sudo&#8221;.<\/p>\n\n\n<pre><code class=\"lang-shell\">sudo python ble_sub_en.py<\/code><\/pre>\n\n\n<p>Information such as temperature and humidity received about every 30 seconds is displayed on the console.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-21.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-21.png?resize=768%2C479&#038;ssl=1\" alt=\"Run the program on the Raspberry Pi 4B.\" class=\"wp-image-21992\" width=\"768\" height=\"479\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-21.png?resize=1024%2C638&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-21.png?resize=300%2C187&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-21.png?resize=768%2C478&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-21.png?w=1026&amp;ssl=1 1026w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"About_the_reach_distance\"><\/span>About the reach distance<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Next, I tried to see if Raspberry Pi 4 could receive data by placing the M5StickC at a distance.<\/p>\n\n\n\n<p>Raspberry Pi 4 can receive data from a distance of several dozen meters (less than 100 meters) without any problem as long as the visibility is good.<\/p>\n\n\n\n<p>However, the situation is different depending on the arrangement of doors, walls, and cabinets in the office.<\/p>\n\n\n\n<p>Even if there are some walls, the Raspberry Pi 4 was able to receive the signal without any problem if it was about 15 meters away, but if it was through a reinforced concrete wall, there were times when it could not be received.<\/p>\n\n\n\n<p>However, I was able to feel a much greater sense of &#8220;far reaching&#8221; than with Bluetooth in the early days.<\/p>\n\n\n\n<p>If it can reach this far, I think it will be very powerful for communication between IoT devices.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Finally\"><\/span>Finally.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This time, I tested a one-to-one combination of M5StickC and Raspberry Pi 4.<\/p>\n\n\n\n<p>However, I thought it would be interesting to place multiple M5StickC (sensors) and only one Raspberry Pi 4 in a place where power supply can be secured, and collect information from multiple sensors and upload it to the cloud.<\/p>\n\n\n\n<p>For example, it is difficult to secure a power supply in all outdoor locations such as fields and greenhouses, so I felt that it would be possible to use the M5StickC placed in multiple locations with a lithium battery plus an auxiliary battery to run the M5StickC and aggregate the data once on the Raspberry Pi 4.<\/p>\n\n\n\n<p>This concludes this article.<\/p>\n\n\n<div class=\"postscript_balloon\">Finally.<\/div>\n\n\n<p>I hope this article will be useful to someone somewhere.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I used the M5StickC and BME280 sensor module to measure temperature, humidity, and air pressure, and advertise the measurement results via BLE.<\/p>\n","protected":false},"author":5,"featured_media":18321,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/www.souichi.club\/?p=18241","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[238],"tags":[240,137,251,138],"class_list":["post-21394","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-m5stack","tag-arduino","tag-iot","tag-programing","tag-python","en-US"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-18.jpg?fit=1280%2C1103&ssl=1","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/comments?post=21394"}],"version-history":[{"count":2,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21394\/revisions"}],"predecessor-version":[{"id":24944,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21394\/revisions\/24944"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/media\/18321"}],"wp:attachment":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/media?parent=21394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/categories?post=21394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/tags?post=21394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}