{"id":134513,"date":"2023-09-30T09:38:46","date_gmt":"2023-09-30T09:38:46","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=134513"},"modified":"2023-09-30T11:19:20","modified_gmt":"2023-09-30T11:19:20","slug":"raspberry-pi-bme280-data-logger","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-bme280-data-logger\/","title":{"rendered":"Raspberry Pi with BME280: Temperature, Humidity, and Pressure Data Logger (Python)"},"content":{"rendered":"\n<p>In this project, you&#8217;re going to build a data logger with the Raspberry Pi and the BME280 sensor that automatically stores data on temperature, humidity, pressure, and the corresponding timestamp on a <em>.txt<\/em> file. This project gives you the basics of data collection, which is useful in many different applications that use sensors. You can apply the concepts from this project to any sensor.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Raspberry-Pi-BME280-Data-Logger.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi with BME280 Temperature Humidity and Pressure Data Logger Python\" class=\"wp-image-134527\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Raspberry-Pi-BME280-Data-Logger.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Raspberry-Pi-BME280-Data-Logger.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Raspberry-Pi-BME280-Data-Logger.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Raspberry-Pi-BME280-Data-Logger.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgreen\"><strong>New to the <\/strong>BME280 environmental<strong> sensor?<\/strong> Read our getting started guide: <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-bme280-python\/\">Raspberry Pi: BME280 Temperature, Humidity, and Pressure Sensor (Python)<\/a>.<\/p>\n\n\n\n<p><strong>Table of Contents<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#prerequisites\" title=\"\">Prerequisites<\/a><\/li>\n\n\n\n<li><a href=\"#BME280-sensor\" title=\"\">BME280 Sensor Introduction<\/a><\/li>\n\n\n\n<li><a href=\"#parts-required\" title=\"\">Parts Required<\/a><\/li>\n\n\n\n<li><a href=\"#bme280-rpi-wiring\" title=\"\">Wiring the BME280 to the Raspberry Pi<\/a><\/li>\n\n\n\n<li><a href=\"#bme280-library\" title=\"\">Installing Libraries<\/a><\/li>\n\n\n\n<li><a href=\"#rpi-datalogger-python-code\" title=\"\">Raspberry Pi BME280 Data Logger Python Script<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h2>\n\n\n\n<p>Before continuing with this tutorial, check the following prerequisites.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Get familiar with the Raspberry Pi board\u2014if you&#8217;re not familiar with the Raspberry Pi, you can read our <a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-raspberry-pi\/\" title=\"\"><strong>Raspberry Pi Getting Started Guide here<\/strong>.<\/a><\/li>\n\n\n\n<li>You must know how to run and create Python files on your Raspberry Pi. We like to program our Raspberry Pi via SSH using an extension on VS Code. We have a detailed tutorial about that subject: <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-remote-ssh-vs-code\/\" title=\"\"><strong>Programming Raspberry Pi Remotely using VS Code (Remote-SSH)<\/strong><\/a>.<\/li>\n\n\n\n<li>Know how to use the Raspberry Pi GPIOs so that you know how to wire the circuit properly. Read the following tutorial: <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pinout-gpios\/\"><strong>Raspberry Pi Pinout Guide: How to use the Raspberry Pi GPIOs?<\/strong><\/a><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"BME280-sensor\">Introducing BME280 Sensor Module<\/h2>\n\n\n\n<p>The <a rel=\"noreferrer noopener\" aria-label=\"BME280 sensor (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\">BME280 sensor<\/a> module reads barometric pressure, temperature, and humidity. Because pressure changes with altitude, you can also estimate altitude. There are several versions of this sensor module. We\u2019re using the module illustrated in the figure below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"1200\" height=\"722\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-sensor.jpg?resize=1200%2C722&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BME280 Sensor I2C Module reads pressure, temperature, and humidity\" class=\"wp-image-86437\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-sensor.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-sensor.jpg?resize=300%2C180&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-sensor.jpg?resize=768%2C462&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-sensor.jpg?resize=1024%2C616&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p>This sensor communicates using I2C communication protocol, so the wiring is very simple. You can use the default Raspberry Pi I2C pins as shown in the following table:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>Raspberry <\/strong>Pi<\/td><\/tr><tr><td>Vin<\/td><td><span class=\"rnthl rntcred\">3.3V<\/span><\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><tr><td>SCL<\/td><td><span class=\"rnthl rntcyellow\">GPIO 3<\/span><\/td><\/tr><tr><td>SDA<\/td><td><span class=\"rnthl rntclgray\">GPIO 2<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"rntbox rntclgreen\"><strong>Learn more about the Raspberry Pi GPIOs<\/strong>: <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pinout-gpios\/\">Raspberry Pi Pinout Guide: How to use the Raspberry Pi GPIOs?<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"parts-required\">Parts Required<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-with-Raspberry-Pi.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi with BME280 Sensor\" class=\"wp-image-134486\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-with-Raspberry-Pi.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-with-Raspberry-Pi.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Here&#8217;s a list of parts you need to build the circuit:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-board\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Raspberry Pi board<\/a> &#8211; read <a href=\"https:\/\/makeradvisor.com\/best-raspberry-pi-starter-kits\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Best Raspberry Pi Starter Kits<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\" rel=\"noopener\" title=\"\">BME280 temperature and humidity sensor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Jumper wires<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"enable-i2c\">Enable I2C on the Raspberry Pi<\/h2>\n\n\n\n<p>I2C communication is not enabled by default. You need to enable it manually. Open a terminal window on your Raspberry Pi and type the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo raspi-config<\/pre>\n\n\n\n<p>The following menu will open. Select <strong>Interface Options<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"292\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/raspi-config.png?resize=722%2C292&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Enable I2C communication\" class=\"wp-image-134472\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/raspi-config.png?w=722&amp;quality=100&amp;strip=all&amp;ssl=1 722w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/raspi-config.png?resize=300%2C121&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 722px) 100vw, 722px\" \/><\/figure><\/div>\n\n\n<p>Then, select the I2C option.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"736\" height=\"288\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/raspi-config-i2c.png?resize=736%2C288&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Enable I2C communication\" class=\"wp-image-134473\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/raspi-config-i2c.png?w=736&amp;quality=100&amp;strip=all&amp;ssl=1 736w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/raspi-config-i2c.png?resize=300%2C117&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/figure><\/div>\n\n\n<p>Finally, enable I2C by selecting <strong>Yes<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"483\" height=\"321\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/enabled-i2c.png?resize=483%2C321&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Enable I2C communication\" class=\"wp-image-134474\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/enabled-i2c.png?w=483&amp;quality=100&amp;strip=all&amp;ssl=1 483w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/enabled-i2c.png?resize=300%2C199&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 483px) 100vw, 483px\" \/><\/figure><\/div>\n\n\n<p>I2C should be successfully enabled.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"485\" height=\"324\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/i2c-is-enabled.png?resize=485%2C324&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi I2C communication enabled\" class=\"wp-image-134475\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/i2c-is-enabled.png?w=485&amp;quality=100&amp;strip=all&amp;ssl=1 485w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/i2c-is-enabled.png?resize=300%2C200&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 485px) 100vw, 485px\" \/><\/figure><\/div>\n\n\n<p>After enabling I2C, reboot your Raspberry Pi by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo reboot<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bme280-rpi-wiring\">Wiring the BME280 to the Raspberry Pi<\/h2>\n\n\n\n<p>Wire the BME280 to the Raspberry Pi default I2C pins.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"831\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-Raspberry-Pi_bb.png?resize=900%2C831&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Wiring BME280 Diagram\" class=\"wp-image-134476\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-Raspberry-Pi_bb.png?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-Raspberry-Pi_bb.png?resize=300%2C277&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-Raspberry-Pi_bb.png?resize=768%2C709&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>Raspberry Pi<\/strong><\/td><\/tr><tr><td>Vin<\/td><td><span class=\"rnthl rntcred\">3.3V<\/span><\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><tr><td>SCL<\/td><td><span class=\"rnthl rntclblue\">GPIO 3<\/span><\/td><\/tr><tr><td>SDA<\/td><td><span class=\"rnthl rntclgreen\">GPIO 2<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"get-i2c-address\">Getting the Sensor I2C Address<\/h2>\n\n\n\n<p>With the sensor connected to the Raspberry Pi, let&#8217;s check if the sensor is connected properly by searching for its I2C address.<\/p>\n\n\n\n<p>Open a Terminal window on your Raspberry Pi and run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo i2cdetect -y 1<\/pre>\n\n\n\n<p>It should show your sensor I2C address:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"210\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/detect-i2c-address-bme280.png?resize=533%2C210&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BME280 Getting BME280 I2C Address\" class=\"wp-image-134477\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/detect-i2c-address-bme280.png?w=533&amp;quality=100&amp;strip=all&amp;ssl=1 533w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/detect-i2c-address-bme280.png?resize=300%2C118&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"bme280-library\">Install BME280 Library<\/h2>\n\n\n\n<p>There are several libraries compatible with the Raspberry Pi to read from the BME280 sensor. We&#8217;ll be using the <strong>RPi.BME280<\/strong> library. Besides having functions to read from the BME280 sensor, it also has the option to get a timestamp associated with each reading. This makes it extremely simple to use for data logging applications.<\/p>\n\n\n\n<p>This library is available to install through PIP (a package manager for Python packages).<\/p>\n\n\n\n<p>First, install or upgrade pip by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo pip install --upgrade pip<\/pre>\n\n\n\n<p>Then, run the following command to install the library using pip:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo pip install RPI.BME280<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Installing the pytz library<\/h3>\n\n\n\n<p>The <strong>RPi.280<\/strong> library has an option to get the timestamp associated with each reading. However, that timestamp will be in UTC. If you want to convert it to a specific timezone, you can use the <strong>pytz <\/strong>library. Open a terminal window on your Raspberry Pi and run the following command to install the <strong>pytz <\/strong>library.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pip install pytz<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"rpi-datalogger-python-code\">Raspberry Pi BME280 Data Logger Python Script<\/h2>\n\n\n\n<p>Create a new Python file on your Raspberry Pi called <em>bme280_data_logger.py<\/em> and copy the following code.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-python\"># Complete Project Details: https:\/\/RandomNerdTutorials.com\/raspberry-pi-bme280-data-logger\/\n\nimport smbus2\nimport bme280\nimport os\nimport time\nimport pytz\n\n# BME280 sensor address (default address)\naddress = 0x76\n\n# Initialize I2C bus\nbus = smbus2.SMBus(1)\n\n# Load calibration parameters\ncalibration_params = bme280.load_calibration_params(bus, address)\n\n# create a variable to control the while loop\nrunning = True\n\n# Check if the file exists before opening it in 'a' mode (append mode)\nfile_exists = os.path.isfile('sensor_readings_bme280.txt')\nfile = open('sensor_readings_bme280.txt', 'a')\n\n# Write the header to the file if the file does not exist\nif not file_exists:\n    file.write('Time and Date, temperature (\u00baC), temperature (\u00baF), humidity (%), pressure (hPa)\\n')\n\n# loop forever\nwhile running:\n    try:\n        # Read sensor data\n        data = bme280.sample(bus, address, calibration_params)\n\n        # Extract temperature, pressure, humidity, and corresponding timestamp\n        temperature_celsius = data.temperature\n        humidity = data.humidity\n        pressure = data.pressure\n        timestamp = data.timestamp\n\n        # Adjust timezone\n        # Define the timezone you want to use (list of timezones: https:\/\/gist.github.com\/mjrulesamrat\/0c1f7de951d3c508fb3a20b4b0b33a98)\n        desired_timezone = pytz.timezone('Europe\/Lisbon')  # Replace with your desired timezone\n\n        # Convert the datetime to the desired timezone\n        timestamp_tz = timestamp.replace(tzinfo=pytz.utc).astimezone(desired_timezone)\n\n        # Convert temperature to Fahrenheit\n        temperature_fahrenheit = (temperature_celsius * 9\/5) + 32\n\n        # Print the readings\n        print(timestamp_tz.strftime('%H:%M:%S %d\/%m\/%Y') + &quot; Temp={0:0.1f}\u00baC, Temp={1:0.1f}\u00baF, Humidity={2:0.1f}%, Pressure={3:0.2f}hPa&quot;.format(temperature_celsius, temperature_fahrenheit, humidity, pressure))\n\n        # Save time, date, temperature, humidity, and pressure in .txt file\n        file.write(timestamp_tz.strftime('%H:%M:%S %d\/%m\/%Y') + ', {:.2f}, {:.2f}, {:.2f}, {:.2f}\\n'.format(temperature_celsius, temperature_fahrenheit, humidity, pressure))\n\n        time.sleep(10)\n\n    except KeyboardInterrupt:\n        print('Program stopped')\n        running = False\n        file.close()\n    except Exception as e:\n        print('An unexpected error occurred:', str(e))\n        running = False\n        file.close()\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi\/bme280_data_logger.py\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Code Works<\/h2>\n\n\n\n<p>Here&#8217;s a quick description of what the code does:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>it saves sensor readings and the corresponding timestamp to a file called <em>sensor_readings_bme280.txt<\/em>.<\/li>\n\n\n\n<li>but first, it checks if a file called <em>sensor_readings_bme280.txt<\/em> already exists (this is to prevent writing the file header multiple times when the program resets or stops\/starts).<\/li>\n\n\n\n<li>if the file doesn&#8217;t exist, it will create a new file.<\/li>\n\n\n\n<li>there&#8217;s an infinite loop, in which you get temperature, humidity, and pressure readings and the corresponding timestamp in UTC.<\/li>\n\n\n\n<li>it converts the timestamp to your desired timezone, and then it writes all the data to the file, including the timestamp.<\/li>\n\n\n\n<li>the program keeps running and writing to the file until you tell the program to stop with a keyboard interrupt or until the program stops for any other reason. In that case, we close the file.<\/li>\n<\/ul>\n\n\n\n<p>Continue reading for a more detailed explanation of the code, or skip to the <a href=\"#demonstration\" title=\"\">demonstration section<\/a>,<\/p>\n\n\n\n<p>The code is very similar to the one in <strong><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-bme280-python\/\" title=\"\">THIS PROJECT<\/a><\/strong> (but it adds some lines for data logging).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Import the Required Libraries<\/h3>\n\n\n\n<p>First, you need to import the required libraries. The <span class=\"rnthl rntliteral\">smbus2<\/span> is necessary to use I2C communication, the <span class=\"rnthl rntliteral\">RPi.BME280<\/span> to get readings from the BME280 sensor, the <span class=\"rnthl rntliteral\">time<\/span> module to add delays to your code, the <span class=\"rnthl rntliteral\">os<\/span> module that will allow us to interact with the operating system (in our case, we need to check if a file already exists on the filesystem), and finally, the <span class=\"rnthl rntliteral\">pytz<\/span> module to adjust the timezone.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>import smbus2\nimport bme280\nimport os\nimport time\nimport pytz<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Initialize the BME280 Sensor<\/h4>\n\n\n\n<p>We set the default address of the BME280 sensor to 0x<strong>76<\/strong>. This is the address that the sensor communicates with over the I2C bus (<a href=\"#get-i2c-address\" title=\"\">check this previous section<\/a>). <\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># BME280 sensor address (default address)\naddress = 0x76<\/code><\/pre>\n\n\n\n<p>We then initialize the I2C bus using the <span class=\"rnthl rntliteral\">smbus2.SMBus(1)<\/span> command.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Initialize I2C bus\nbus = smbus2.SMBus(1)<\/code><\/pre>\n\n\n\n<p>Then, we initialize the sensor by setting the I2C bus and its I2C address.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Load calibration parameters\ncalibration_params = bme280.load_calibration_params(bus, address)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">File Handling<\/h4>\n\n\n\n<p>The following line, checks if a file called <em>sensor_readings_bme280.txt<\/em> already exists (it will look for it in the project folder path). If the file already exists, the <span class=\"rnthl rntliteral\">file_exists<\/span> variable will be <span class=\"rnthl rntliteral\">True<\/span>. Otherwise, it will be <span class=\"rnthl rntliteral\">False<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>file_exists = os.path.isfile('sensor_readings_bme280.txt')<\/code><\/pre>\n\n\n\n<p>Then, it opens the file in <span class=\"rnthl rntliteral\">&#8216;a&#8217;<\/span> (append) mode. If the file doesn&#8217;t exist yet, it will automatically create the file before opening it.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>file = open('sensor_readings_bme280.txt', 'a')<\/code><\/pre>\n\n\n\n<p>When using the <span class=\"rnthl rntliteral\">open()<\/span> function, you can specify different modes to control how the file is accessed and used. When writing to the file, the most popular methods are <span class=\"rnthl rntliteral\">&#8216;w&#8217;<\/span> (write) and <span class=\"rnthl rntliteral\">&#8216;a&#8217;<\/span> (append).<\/p>\n\n\n\n<p class=\"rntbox rntclgreen\"><strong>Write vs Append mode<\/strong>: the write mode opens the file for writing and empties the file if it already exists. The append mode opens the file for writing and it appends new data to the end of the file. If you want to have a record of your readings over time, the best mode is append so that you can keep all your previous data.<\/p>\n\n\n\n<p>If the file doesn&#8217;t exist yet, the code writes a header line to the file, containing the column names. We&#8217;ll save date and time first, then, the temperature in Celsius and Fahrenheit, the humidity, and finally the pressure.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Write the header to the file if the file does not exist\nif not file_exists:\n    file.write('Time and Date, temperature (\u00baC), temperature (\u00baF), humidity (%), pressure (hPa)\\n')<\/code><\/pre>\n\n\n\n<p>Notice that we add a <span class=\"rnthl rntliteral\">\\n<\/span> at the end of the String. The <span class=\"rnthl rntliteral\">\\n<\/span> tells Python to start the next display text on the next line, known as a <em>newline<\/em>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Getting Sensor Readings<\/h4>\n\n\n\n<p>Then, we have a while loop that is always running as long as the <span class=\"rnthl rntliteral\">running<\/span> variable is <span class=\"rnthl rntliteral\">True<\/span>. We have set that variable to <span class=\"rnthl rntliteral\">True<\/span> at the beginning of the code. The <span class=\"rnthl rntliteral\">running<\/span> variable will change to <span class=\"rnthl rntliteral\">False<\/span>, when the execution of the program is stopped by a keyboard interrupt, or when an unexpected error occurs.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>while running:<\/code><\/pre>\n\n\n\n<p>Inside the loop, the try block attempts to read from the sensor: we use the <span class=\"rnthl rntliteral\">bme280.sample(bus, address, calibration_params)<\/span> function to read sensor data.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>data = bme280.sample(bus, address, calibration_params)<\/code><\/pre>\n\n\n\n<p>We extract the temperature, humidity, pressure, and the corresponding timestamp from the <span class=\"rnthl rntliteral\">data<\/span> returned by the sensor and save each reading on a variable: <span class=\"rnthl rntliteral\">temperature_celsius<\/span>, <span class=\"rnthl rntliteral\">humidity<\/span>, <span class=\"rnthl rntliteral\">pressure<\/span>, and <span class=\"rnthl rntliteral\">timestamp<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Extract temperature, pressure, humidity, and corresponding timestamp\ntemperature_celsius = data.temperature\nhumidity = data.humidity\npressure = data.pressure\ntimestamp = data.timestamp<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Adjust the timezone<\/h4>\n\n\n\n<p>As we mentioned previously, the timestamp returned by the <span class=\"rnthl rntliteral\">data<\/span> object of the BME280 library comes in UTC format, by default. We can use the <strong>pytz <\/strong>library functions to convert that time to our desired timezone.<\/p>\n\n\n\n<p>First, specify your desired timezone on the following line (<a href=\"https:\/\/gist.github.com\/mjrulesamrat\/0c1f7de951d3c508fb3a20b4b0b33a98\" target=\"_blank\" rel=\"noopener\" title=\"\">you can find a list of all supported timezones here<\/a>). We live in Portugal, so our timezone is <span class=\"rnthl rntliteral\">&#8216;Europe\/Lisbon&#8217;<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>desired_timezone = pytz.timezone('Europe\/Lisbon')  # Replace with your desired timezone<\/code><\/pre>\n\n\n\n<p>Then, convert the timestamp to your desired timezone as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Convert the datetime to the desired timezone\ntimestamp_tz = timestamp.replace(tzinfo=pytz.utc).astimezone(desired_timezone)<\/code><\/pre>\n\n\n\n<p>The new timestamp adjusted to your specific timezone is saved on the <span class=\"rnthl rntliteral\">timestamp_tz<\/span> variable.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Converting the Temperature to Fahrenheit<\/h4>\n\n\n\n<p>We convert the temperature from Celsius to Fahrenheit as follows (the temperature in Fahrenheit is saved on the <span class=\"rnthl rntliteral\">temperature_fahrenheit<\/span> variable.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Convert temperature to Fahrenheit\ntemperature_fahrenheit = celsius_to_fahrenheit(temperature_celsius)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Print the Readings<\/h4>\n\n\n\n<p>Finally, we print the readings formatted with two decimal places and the corresponding timestamp:<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Print the readings\n print(timestamp_tz.strftime('%H:%M:%S %d\/%m\/%Y') + \" Temp={0:0.1f}\u00baC, Temp={1:0.1f}\u00baF, Humidity={2:0.1f}%, Pressure={3:0.2f}hPa\".format(temperature_celsius, temperature_fahrenheit, humidity, pressure))<\/code><\/pre>\n\n\n\n<div class=\"wp-block-group rntbox rntclblue\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>The <span class=\"rnthl rntliteral\">strftime()<\/span> function converts a datetime, time, and date object into a string object according to the given format. In our case, we&#8217;re using the format hour:minutes:seconds for the time and day\/month\/year for the date.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">%H<\/span>: decimal number represents the Hour, 24-hour clock format(00 to 23)<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">%M<\/span>: decimal number that represents the <strong>Minute <\/strong>(01 to 59)<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">%S<\/span>: decimal number that represents the <strong>Second <\/strong>(01 to 59)<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">%d<\/span>: <strong>day <\/strong>of the month as a zero-padded decimal number. (01 to 31)<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">%m<\/span>: <strong>month <\/strong>as a zero-padded decimal number(01 to 12)<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">%Y<\/span>: decimal number represents the <strong>Year<\/strong> with the century.<\/li>\n<\/ul>\n\n\n\n<p>For different date and time formats, <a href=\"https:\/\/docs.python.org\/3\/library\/datetime.html#strftime-and-strptime-format-codes\" target=\"_blank\" rel=\"noopener\" title=\"\">check all the format codes here<\/a>.<\/p>\n<\/div><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Writing Data to the File<\/h4>\n\n\n\n<p>Then, we use the <span class=\"rnthl rntliteral\">write()<\/span> function on the <span class=\"rnthl rntliteral\">file<\/span> object to actually write data to the file. We print the timestamp, temperature in Celsius, temperature in Fahrenheit, humidity, and pressure.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>file.write(timestamp_tz.strftime('%H:%M:%S %d\/%m\/%Y') + ', {:.2f}, {:.2f}, {:.2f}, {:.2f}\\n'.format(temperature_celsius, temperature_fahrenheit, humidity, pressure))<\/code><\/pre>\n\n\n\n<p>New readings are printed and written to the file every 10 seconds. You can adjust the time between each sample by passing a different number to the <span class=\"rnthl rntliteral\">sleep()<\/span> method.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>time.sleep(10)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Interrupt and Exception Handling<\/h4>\n\n\n\n<p>If you interrupt the program by pressing <strong>Ctrl<\/strong>+<strong>C<\/strong>, the code catches the <span class=\"rnthl rntliteral\">KeyboardInterrupt<\/span> exception, prints a message indicating program termination, and then closes the file before setting <span class=\"rnthl rntliteral\">running<\/span> to <span class=\"rnthl rntliteral\">False<\/span> to exit the loop. <\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>except KeyboardInterrupt:\n    print('Program stopped')\n    running = False\n    file.close()<\/code><\/pre>\n\n\n\n<p><strong>Important<\/strong>: you need to call <span class=\"rnthl rntliteral\">file.close()<\/span> so that all data is written to the file.<\/p>\n\n\n\n<p>We proceed in a similar way if any other error or exception occurs.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>except Exception as e:\n    print('An unexpected error occurred:', str(e))\n    running = False\n    file.close()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration\">Demonstration<\/h2>\n\n\n\n<p>Save your Python file. Then run it on your Raspberry Pi. Run the following command on the directory of your file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>python bme280_data_logger.py<\/em><\/pre>\n\n\n\n<p>You&#8217;ll start getting new temperature and humidity readings on the terminal window, and a new file called <em>sensors_readings_bme280.txt<\/em> will be created in your project folder. If you&#8217;re using VS Code, you&#8217;ll see the newly created file on the file explorer (don&#8217;t open it yet). <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"877\" height=\"805\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-datalogger-VS-Code-Raspberry-Pi.png?resize=877%2C805&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Datalogger VS Code BME280\" class=\"wp-image-134517\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-datalogger-VS-Code-Raspberry-Pi.png?w=877&amp;quality=100&amp;strip=all&amp;ssl=1 877w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-datalogger-VS-Code-Raspberry-Pi.png?resize=300%2C275&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/BME280-datalogger-VS-Code-Raspberry-Pi.png?resize=768%2C705&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 877px) 100vw, 877px\" \/><\/figure><\/div>\n\n\n<p>Let the code run for a while so it gathers a considerable amount of data. Then, stop the execution of the code by pressing<strong> CTRL+C<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"289\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Rpi-Datalogger-Stop-program.png?resize=686%2C289&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi VS Code Stop Python program\" class=\"wp-image-134518\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Rpi-Datalogger-Stop-program.png?w=686&amp;quality=100&amp;strip=all&amp;ssl=1 686w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Rpi-Datalogger-Stop-program.png?resize=300%2C126&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 686px) 100vw, 686px\" \/><\/figure><\/div>\n\n\n<p>Now, you can open the <em>sensors_readings_bme280.txt<\/em> file and see all the data it collected. You can run the program again to gather more data and it won&#8217;t overwrite the previous data.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"704\" height=\"795\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/sensor-readings-bme280-txt-file.png?resize=704%2C795&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Sensor Readings Data Logger Raspberry Pi VS Code\" class=\"wp-image-134520\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/sensor-readings-bme280-txt-file.png?w=704&amp;quality=100&amp;strip=all&amp;ssl=1 704w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/sensor-readings-bme280-txt-file.png?resize=266%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 266w\" sizes=\"(max-width: 704px) 100vw, 704px\" \/><\/figure><\/div>\n\n\n<p>If you&#8217;re using PuTTY, navigate to your project folder. List all files inside the project folder using the <span class=\"rnthl rntliteral\"><strong>ls<\/strong><\/span> command and note that a file called <em>sensor_readings_bme280.txt<\/em> is listed.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"661\" height=\"333\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Raspberry-Pi-Putty-list-files.png?resize=661%2C333&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi List Files Putty\" class=\"wp-image-134521\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Raspberry-Pi-Putty-list-files.png?w=661&amp;quality=100&amp;strip=all&amp;ssl=1 661w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Raspberry-Pi-Putty-list-files.png?resize=300%2C151&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/figure><\/div>\n\n\n<p>To open that file, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cat sensor_readings_bme280.txt<\/pre>\n\n\n\n<p>Then, you&#8217;ll see all data gathered by your sensor with the corresponding timestamps.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"677\" height=\"754\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/raspberry-pi-sensor-readings-bme280-putty.png?resize=677%2C754&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Datalogger File txt Putty\" class=\"wp-image-134522\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/raspberry-pi-sensor-readings-bme280-putty.png?w=677&amp;quality=100&amp;strip=all&amp;ssl=1 677w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/raspberry-pi-sensor-readings-bme280-putty.png?resize=269%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 269w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this project, you\u2019ve learned a very useful concept: data logging. Now you can use data logging in other monitoring projects or use other sensors. We have guides for other sensors that you may find useful:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-detect-motion-pir-python\/\">Raspberry Pi: Detect Motion using a PIR Sensor with Python<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-bme280-python\/\">Raspberry Pi: BME280 Temperature, Humidity and Pressure Sensor (Python)<\/a><\/li>\n<\/ul>\n\n\n\n<p>We hope you found this tutorial useful. If you&#8217;re quite new to the Raspberry Pi, check the following tutorials:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-raspberry-pi\/\">Getting Started with Raspberry Pi<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pinout-gpios\/\" title=\"\">Raspberry Pi Pinout Guide<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-remote-ssh-vs-code\/\">Programming Raspberry Pi Remotely using VS Code (Remote-SSH)<\/a><\/li>\n<\/ul>\n\n\n\n<p>You can check all our Raspberry Pi projects on the following link:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-raspberry-pi\/\" title=\"\">Free Raspberry Pi Projects and Tutorials<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this project, you&#8217;re going to build a data logger with the Raspberry Pi and the BME280 sensor that automatically stores data on temperature, humidity, pressure, and the corresponding timestamp &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Raspberry Pi with BME280: Temperature, Humidity, and Pressure Data Logger (Python)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-bme280-data-logger\/#more-134513\" aria-label=\"Read more about Raspberry Pi with BME280: Temperature, Humidity, and Pressure Data Logger (Python)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":134527,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301,264,268,190],"tags":[],"class_list":["post-134513","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-raspberrypi","category-project","category-raspberry-pi-project","category-raspberry-pi"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/08\/Raspberry-Pi-BME280-Data-Logger.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/134513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=134513"}],"version-history":[{"count":14,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/134513\/revisions"}],"predecessor-version":[{"id":137121,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/134513\/revisions\/137121"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/134527"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=134513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=134513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=134513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}