{"id":21909,"date":"2021-07-10T09:14:57","date_gmt":"2021-07-10T00:14:57","guid":{"rendered":"https:\/\/www.souichi.club\/?p=21909"},"modified":"2022-03-19T17:24:12","modified_gmt":"2022-03-19T08:24:12","slug":"bme280","status":"publish","type":"post","link":"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/","title":{"rendered":"Program to display temperature and humidity on the Raspberry Pi"},"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\/21909\/\" 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\/21909\/\" title=\"Japanese\">\u65e5\u672c\u8a9e<\/a><\/span><\/li>\n<\/ul>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 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-6a2cbd0162610\" 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-6a2cbd0162610\"  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\/raspberrypi\/bme280\/#BME280\" >BME280<\/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\/raspberrypi\/bme280\/#Connectors\" >Connectors<\/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\/raspberrypi\/bme280\/#Specifications\" >Specifications<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Sets_purchased\" >Sets purchased<\/a><\/li><\/ul><\/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\/raspberrypi\/bme280\/#Circuit_Diagram\" >Circuit Diagram<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#advance_preparation\" >advance preparation<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Enabling_I2C\" >Enabling I2C<\/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\/raspberrypi\/bme280\/#Module_installation\" >Module installation<\/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\/raspberrypi\/bme280\/#Checking_the_connection_address\" >Checking the connection address<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Sample_Program\" >Sample Program<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Obtaining_the_program\" >Obtaining the program<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Checking_and_fixing\" >Checking and fixing<\/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\/raspberrypi\/bme280\/#Supplementary_explanation\" >Supplementary explanation<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Adjustment_parameters\" >Adjustment parameters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Acquisition_of_data\" >Acquisition of data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Calculation_of_temperature_humidity_and_barometric_pressure\" >Calculation of temperature, humidity, and barometric pressure<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Initial_processing\" >Initial processing<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Main_processing\" >Main processing<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/bme280\/#Execution_result\" >Execution result<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"BME280\"><\/span>BME280<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>An article on connecting a temperature, humidity, and barometric pressure sensor (BME280) to a Raspberry Pi 3 B+ to measure temperature, humidity, and barometric pressure.<\/p>\n\n\n\n<p>When I bought the sensor, the connector and module were separate and needed to be soldered together.<\/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\/BME280-01.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-01.jpg?resize=512%2C320&#038;ssl=1\" alt=\"BME280 module\" class=\"wp-image-16040\" width=\"512\" height=\"320\" title=\"BME280\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-01.jpg?resize=1024%2C639&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-01.jpg?resize=300%2C187&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-01.jpg?resize=768%2C479&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-01.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=\"Connectors\"><\/span>Connectors<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Connectors are from the top of the picture.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Vcc: 3.3 to 5.0 V<\/li><li>GND\uff1aGND<\/li><li>SCL: I2C SCL<\/li><li>SDA: I2C SDA<\/li><\/ul>\n\n\n\n<p>Connectors<br>Connectors are from the top of the picture.<\/p>\n\n\n\n<p>Vcc: 3.3 to 5.0 V<br>GND\uff1aGND<br>SCL: I2C SCL<br>SDA: I2C SDA<\/p>\n\n\n\n<p>Connect to the pins on the Raspberry Pi.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Specifications\"><\/span>Specifications<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The specifications 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>Interface<\/p>\n<\/td>\n<td>\n<p>I2C(max 3.4MHz)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Supply voltage<\/p>\n<\/td>\n<td>\n<p>3.3 &#8211; 5V(DC)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Measurement range<\/p>\n<\/td>\n<td>\n<ul>\n<li>Temperature: -40 to +85 \u00b0C<\/li>\n<li>humidity: 0 to 100 \uff05<\/li>\n<li>barometric pressure: 300 to 1100 hPa (elevation 9000m to -500m)<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Minimum Unit<\/p>\n<\/td>\n<td>\n<ul>\n<li>Temperature: 0.01 \u2103<\/li>\n<li>humidity: 0.008 \uff05<\/li>\n<li>barometric pressure: 0.18 Pa<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Measurement error<\/p>\n<\/td>\n<td>\n<ul>\n<li>Temperature: \u00b11 \u2103<\/li>\n<li>humidity: \u00b13 \uff05<\/li>\n<li>barometric pressure: \u00b11 Pa<\/li>\n<\/ul>\n<p>The BME280 can measure not only temperature and humidity, but also barometric pressure, compared to the DHT11 and DHT22 that we tested earlier.<\/p>\n<p>In terms of measurement error, the BME280 is more accurate than the DHT22 in humidity, but less accurate in temperature.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>I2C address<\/p>\n<\/td>\n<td>\n<ul>\n<li>SDO LOW: 0x76<\/li>\n<li>SDO HIGH: 0x77<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sets_purchased\"><\/span>Sets purchased<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I bought the BME280 not as a standalone unit, but as a set that includes a 0.96&#8243; display module and a Wi-Fi 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-en-02.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-02.jpg?resize=501%2C512&#038;ssl=1\" alt=\"BME280,display module,Wi-Fi Modelu \" class=\"wp-image-21942\" width=\"501\" height=\"512\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-02.jpg?resize=1001%2C1024&amp;ssl=1 1001w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-02.jpg?resize=293%2C300&amp;ssl=1 293w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-02.jpg?resize=768%2C786&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-02.jpg?resize=1502%2C1536&amp;ssl=1 1502w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-02.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/a><\/figure>\n\n\n\n<p>I didn&#8217;t need the Wi-Fi module because it&#8217;s a Raspberry Pi, but I bought it because it was a cheap set.<\/p>\n\n\n\n<p>I&#8217;d like to try out the display module and Wi-Fi module at some point.<br>This time, however, I&#8217;m only going to try the temperature, humidity, and pressure sensors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Circuit_Diagram\"><\/span>Circuit Diagram<span class=\"ez-toc-section-end\"><\/span><\/h2>\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-03.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-03.png?resize=768%2C497&#038;ssl=1\" alt=\"Circuit Diagram\" class=\"wp-image-21944\" width=\"768\" height=\"497\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-03.png?resize=1024%2C662&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-03.png?resize=300%2C194&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-03.png?resize=768%2C497&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-03.png?resize=1536%2C993&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-03.png?w=1670&amp;ssl=1 1670w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"advance_preparation\"><\/span>advance preparation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Enabling_I2C\"><\/span>Enabling I2C<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Enable I2C in the Raspberry Pi menu.<\/p>\n\n\n\n<p>Preferences, Raspberry Pi Configuration, Interfaces tab.<\/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-05.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-05.png?resize=512%2C424&#038;ssl=1\" alt=\"Enable I2C\" class=\"wp-image-21947\" width=\"512\" height=\"424\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-05.png?resize=1024%2C847&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-05.png?resize=300%2C248&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-05.png?resize=768%2C635&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-05.png?w=1130&amp;ssl=1 1130w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<p>I2C (Inter-Integrated Circuit) is a form of serial communication that allows multiple slaves (in this case, the BME280) to be connected to a master (in this case, the Raspberry Pi).<\/p>\n\n\n\n<p>Two signal lines are used for data communication: SCL, which sends clock signals from the master to the slaves, and SDA, which is used for data input and output.<\/p>\n\n\n\n<p>A small display module is also connected as a slave to display the temperature, humidity, and barometric pressure results on the display.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Module_installation\"><\/span>Module installation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Install the modules required to control I2C from Python using the following command.<\/p>\n\n\n<pre><code class=\"lang-shell\">sudo apt-get update\nsudo apt install -y python-smbus\nsudo pip install smbus2<\/code><\/pre>\n\n\n<p>Most of the modules for controlling I2C from the Raspberry Pi with Python seem to be python-smbus, but the BME280 used smbus2.<\/p>\n\n\n\n<p>smbus2 has the same syntax as the python-smbus package, but is designed from scratch to extend the functionality.<\/p>\n\n\n\n<p>For more details, please refer to <a href=\"https:\/\/pypi.org\/project\/smbus2\/\" target=\"_blank\" rel=\"noreferrer noopener\">this page<\/a>.<\/p>\n\n\n\n<p>If the above command successfully installs smbus2, you will see the following message<\/p>\n\n\n<pre><code class=\"lang-shell\">Successfully installed smbus2-0.3.0<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Checking_the_connection_address\"><\/span>Checking the connection address<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>From the LXTerminal of the Raspberry Pi, use the following command to check the connection address.<\/p>\n\n\n<pre><code class=\"lang-shell\">sudo i2cdetect -y 1<\/code><\/pre>\n\n\n<p>The display result shows that the address is 0x76.<\/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-06.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-06.png?resize=495%2C290&#038;ssl=1\" alt=\"Check the connection address.\" class=\"wp-image-21948\" width=\"495\" height=\"290\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-06.png?w=660&amp;ssl=1 660w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/m5stickc-ble-en-06.png?resize=300%2C176&amp;ssl=1 300w\" sizes=\"auto, (max-width: 495px) 100vw, 495px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Program\"><\/span>Sample Program<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Obtaining_the_program\"><\/span>Obtaining the program<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Copy the SWITCH SCIENCE sample program (bme280_sample.py), which is available <a href=\"https:\/\/github.com\/SWITCHSCIENCE\/samplecodes\/blob\/master\/BME280\/Python27\/bme280_sample.py\" target=\"_blank\" rel=\"noreferrer noopener\">on github<\/a>, onto your Raspberry Pi and run it.<\/p>\n\n\n\n<p>The program source is not posted here, so please refer to the link above.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Checking_and_fixing\"><\/span>Checking and fixing<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I copied bme280_sample.py to a suitable directory, opened it in the Thonny Python IDE, and ran it.<\/p>\n\n\n\n<p>There are a few things to check and fix before running.<\/p>\n\n\n\n<p>Make sure that the i2c_address = 0x76 in the 7th line of the program matches the connection address mentioned above.<\/p>\n\n\n\n<p>Next, since this sample program is based on Python 2.7, we need to correct the syntax of the print statements in lines 95, 103, and 117, which are syntax errors in Python 3.<\/p>\n\n\n<pre><code class=\"lang-shell\">before : print \"pressure : %7.2f hPa\" % (pressure\/100)\nafter : print (\"pressure : {:7.2f} hPa\".format(pressure\/100))<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Supplementary_explanation\"><\/span>Supplementary explanation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The following is a supplementary explanation of the sample program.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Adjustment_parameters\"><\/span>Adjustment parameters<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>The get_calib_param function in lines 21-59 obtains the adjustment parameters.<\/p>\n\n\n\n<p>The adjustment parameters are values written to the non-volatile memory of the device during manufacturing, and contain parameter values to correct the acquired values of temperature, humidity, and barometric pressure.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Acquisition_of_data\"><\/span>Acquisition of data<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>The temperature, pressure, and humidity data are acquired together from the addresses F7h to FEh by the readData function in lines 61 to 71.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Calculation_of_temperature_humidity_and_barometric_pressure\"><\/span>Calculation of temperature, humidity, and barometric pressure<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>The compensate_P function on lines 73 to 95 calculates the atmospheric pressure, the compensate_T function on lines 97 to 103 calculates the temperature, and the compensate_H function on lines 105 to 117 calculates the humidity.<\/p>\n\n\n\n<p>The corrections are made from the correction values obtained by the get_calib_param function and the values obtained by the readData function.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Initial_processing\"><\/span>Initial processing<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>The setup function in lines 120 to 135 is the initial processing.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Main_processing\"><\/span>Main processing<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Lines 142-144 are the main processing.<\/p>\n\n\n\n<p>It calls the readData function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Execution_result\"><\/span>Execution result<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Run Thonny Python IDE (application) on RaspberryPi and press F5. When executed with F5, temp (temperature), pressure (air pressure), and hum (humidity) are output.<\/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\/BME280-06.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-06.png?resize=768%2C455&#038;ssl=1\" alt=\"Sample program execution results\" class=\"wp-image-16056\" width=\"768\" height=\"455\" title=\"Sample program execution results\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-06.png?resize=1024%2C606&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-06.png?resize=300%2C178&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-06.png?resize=768%2C455&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-06.png?w=1277&amp;ssl=1 1277w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\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>An article on connecting a temperature, humidity, and barometric pressure sensor to a Raspberry Pi to measure temperature, humidity, and barometric pressure.<\/p>\n","protected":false},"author":5,"featured_media":16040,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/www.souichi.club\/?p=16039","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[136],"tags":[228,250,248,247,249],"class_list":["post-21909","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberrypi","tag-bme280","tag-humidity","tag-pressure","tag-rasppi","tag-temperature","en-US"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/BME280-01.jpg?fit=1280%2C799&ssl=1","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21909","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=21909"}],"version-history":[{"count":2,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21909\/revisions"}],"predecessor-version":[{"id":24945,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21909\/revisions\/24945"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/media\/16040"}],"wp:attachment":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/media?parent=21909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/categories?post=21909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/tags?post=21909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}