ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)

This guide shows how to use the BME280 sensor module with the ESP8266 to read pressure, temperature, humidity and estimate altitude using Arduino IDE. The BME280 sensor uses I2C or SPI communication protocol to exchange data with a microcontroller.

ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)

We’ll show you how to wire the sensor to the ESP8266, install the required libraries, and write a simple sketch that displays the sensor readings. We’ll also build a web server example to display the latest pressure, temperature and humidity readings.

Before proceeding with this tutorial you should have the ESP8266 add-on installed in your Arduino IDE.

You might also like reading other BME280 guides:

Introducing BME280 Sensor Module

The BME280 sensor 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’re using the module illustrated in the figure below.

BME280 Sensor I2C Module reads pressure, temperature, and humidity

This sensor communicates using I2C communication protocol, so the wiring is very simple. You can use the default ESP8266 I2C pins as shown in the following table:

BME280ESP8266
Vin3.3V
GNDGND
SCLGPIO 5
SDAGPIO 4

There are other versions of this sensor that can use either SPI or I2C communication protocols, like the module shown in the next figure:

BME280 Sensor Module SPI or I2C communication protocols

If you’re using one of these sensors, to use I2C communication protocol, use the following pins:

BME280ESP8266
SCK (SCL Pin) GPIO 5
SDI (SDA pin) GPIO 4

If you use SPI communication protocol, you need to use the following pins:

BME280ESP8266
SCK (SPI Clock)GPIO 14
SDO (MISO)GPIO 12
SDI (MOSI)GPIO 13
CS (Chip Select) GPIO 15

Parts Required

To complete this tutorial you need the following parts:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Schematic – ESP8266 with BME280 using I2C

We’re going to use I2C communication with the BME280 sensor module. For that, wire the sensor to the ESP8266 SDA and SCL pins, as shown in the following schematic diagram.

Schematic Wiring diagram ESP8266 with BME280 using I2C

Recommended reading: ESP8266 Pinout Reference Guide

Installing the BME280 library

To get readings from the BME280 sensor module you need to use the Adafruit_BME280 library. Follow the next steps to install the library in your Arduino IDE:

Open your Arduino IDE and go to Sketch Include Library > Manage Libraries. The Library Manager should open.

Search for “adafruit bme280 ” on the Search box and install the library.

Installing BME280 library in Arduino IDE

Installing the Adafruit_Sensor library

To use the BME280 library, you also need to install the Adafruit_Sensor library. Follow the next steps to install the library in your Arduino IDE:

Go to Sketch Include Library > Manage Libraries and type “Adafruit Unified Sensor” in the search box. Scroll all the way down to find the library and install it.

Installing Adafruit Unified Sensor Driver library

After installing the libraries, restart your Arduino IDE.


Reading Pressure, Temperature, and Humidity

To read pressure, temperature, and humidity we’ll use a sketch example from the library.

ESP8266 with BME280 I2C sensor module on Breadboard

After installing the BME280 library, and the Adafruit_Sensor library, open the Arduino IDE and, go to File > Examples > Adafruit BME280 library > bme280 test.

/*********
  Complete project details at https://randomnerdtutorials.com  
*********/

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

/*#include <SPI.h>
#define BME_SCK 14
#define BME_MISO 12
#define BME_MOSI 13
#define BME_CS 15*/

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime;

void setup() {
  Serial.begin(9600);
  Serial.println(F("BME280 test"));

  bool status;

  // default settings
  // (you can also pass in a Wire library object like &Wire2)
  status = bme.begin(0x76);  
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  Serial.println("-- Default Test --");
  delayTime = 1000;

  Serial.println();
}

void loop() { 
  printValues();
  delay(delayTime);
}

void printValues() {
  Serial.print("Temperature = ");
  Serial.print(bme.readTemperature());
  Serial.println(" *C");
  
  // Convert temperature to Fahrenheit
  /*Serial.print("Temperature = ");
  Serial.print(1.8 * bme.readTemperature() + 32);
  Serial.println(" *F");*/
  
  Serial.print("Pressure = ");
  Serial.print(bme.readPressure() / 100.0F);
  Serial.println(" hPa");

  Serial.print("Approx. Altitude = ");
  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");

  Serial.print("Humidity = ");
  Serial.print(bme.readHumidity());
  Serial.println(" %");

  Serial.println();
}

View raw code

We’ve made a few modifications to the sketch to make it fully compatible with the ESP8266.

How the Code Works

Continue reading this section to learn how the code works, or skip to the “Demonstration” section.

Libraries

The code starts by including the needed libraries: the wire library to use I2C, and the Adafruit_Sensor and Adafruit_BME280 libraries to interface with the BME280 sensor.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

SPI communication

As we’re going to use I2C communication, the following lines that define the SPI pins are commented:

/*#include <SPI.h>
#define BME_SCK 14
#define BME_MISO 12
#define BME_MOSI 13
#define BME_CS 15*/

Note: if you’re using SPI communication, use the ESP8266 default SPI pins:

MOSIMISOCLKCS
GPIO 13GPIO 12GPIO 14GPIO 15

Sea level pressure

A variable called SEALEVELPRESSURE_HPA is created.

#define SEALEVELPRESSURE_HPA (1013.25)

This variable saves the pressure at the sea level in hectopascal (is equivalent to milibar). This variable is used to estimate the altitude for a given pressure by comparing it with the sea level pressure. This example uses the default value, but for more accurate results, replace the value with the current sea level pressure at your location.

I2C

This example uses I2C communication protocol by default. As you can see, you just need to create an Adafruit_BME280 object called bme.

Adafruit_BME280 bme; // I2C

To use SPI, you need to comment this previous line and uncomment one of the following lines.

//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

setup()

In the setup(), start a serial communication:

Serial.begin(9600);

And initialize the sensor:

status = bme.begin(0x76); 
if (!status) {
  Serial.println("Could not find a valid BME280 sensor, check wiring!");
  while (1);
}

We initialize the sensor with the 0x76 address. In case you’re not getting sensor readings, check the I2C address of your sensor. With the BME280 sensor wired to your ESP8266, run this I2C scanner sketch to check the address of your sensor. Then, change the address if needed.

Printing values

In the loop(), the printValues() function reads the values from the BME280 and prints the results in the Serial Monitor.

void loop() { 
  printValues();
  delay(delayTime);
}

Reading temperature, humidity, pressure, and estimate altitude is as simple as using the following methods on the bme object:

  • bme.readTemperature() – reads temperature in Celsius;
  • bme.readHumidity() – reads absolute humidity;
  • bme.readPressure() – reads pressure in hPa (hectoPascal = millibar);
  • bme.readAltitude(SEALEVELPRESSURE_HPA) – estimates altitude in meters based on the pressure at the sea level.

Demonstration

Upload the code to your ESP8266, and open the Serial Monitor at a baud rate of 9600. Press the on-board RST button to run the code. You should see the readings displayed on the Serial Monitor.

Printing BME280 pressure, temperature and humidity readings with ESP32 in Arduino IDE Serial Monitor

ESP8266 Web Server with BME280 Sensor

The BME280 sensor measures temperature, humidity, and pressure. So, you can easily build a compact weather station and monitor the measurements using a web server built with the ESP8266 – that’s what we’re going to do in this section

ESP8266 Web Server with BME280 Sensor in Arduino IDE

Copy the following code to your Arduino IDE. Don’t upload it yet. First, you need to include your SSID and password.

/*********
  Rui Santos
  Complete project details at https://randomnerdtutorials.com  
*********/

// Load Wi-Fi library
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>

//uncomment the following lines if you're using SPI
/*#include <SPI.h>
#define BME_SCK 14
#define BME_MISO 12
#define BME_MOSI 13
#define BME_CS 15*/

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

// Replace with your network credentials
const char* ssid     = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

// Set web server port number to 80
WiFiServer server(80);

// Variable to store the HTTP request
String header;

void setup() {
  Serial.begin(115200);
  bool status;

  // default settings
  // (you can also pass in a Wire library object like &Wire2)
  //status = bme.begin();  
  if (!bme.begin(0x76)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.begin();
}

void loop(){
  WiFiClient client = server.available();   // Listen for incoming clients

  if (client) {                             // If a new client connects,
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {                    // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();
            
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the table 
            client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial;}");
            client.println("table { border-collapse: collapse; width:35%; margin-left:auto; margin-right:auto; }");
            client.println("th { padding: 12px; background-color: #0043af; color: white; }");
            client.println("tr { border: 1px solid #ddd; padding: 12px; }");
            client.println("tr:hover { background-color: #bcbcbc; }");
            client.println("td { border: none; padding: 12px; }");
            client.println(".sensor { color:white; font-weight: bold; background-color: #bcbcbc; padding: 1px; }");
            
            // Web Page Heading
            client.println("</style></head><body><h1>ESP8266 with BME280</h1>");
            client.println("<table><tr><th>MEASUREMENT</th><th>VALUE</th></tr>");
            client.println("<tr><td>Temp. Celsius</td><td><span class=\"sensor\">");
            client.println(bme.readTemperature());
            client.println(" *C</span></td></tr>");  
            client.println("<tr><td>Temp. Fahrenheit</td><td><span class=\"sensor\">");
            client.println(1.8 * bme.readTemperature() + 32);
            client.println(" *F</span></td></tr>");       
            client.println("<tr><td>Pressure</td><td><span class=\"sensor\">");
            client.println(bme.readPressure() / 100.0F);
            client.println(" hPa</span></td></tr>");
            client.println("<tr><td>Approx. Altitude</td><td><span class=\"sensor\">");
            client.println(bme.readAltitude(SEALEVELPRESSURE_HPA));
            client.println(" m</span></td></tr>"); 
            client.println("<tr><td>Humidity</td><td><span class=\"sensor\">");
            client.println(bme.readHumidity());
            client.println(" %</span></td></tr>"); 
            client.println("</body></html>");
            
            // The HTTP response ends with another blank line
            client.println();
            // Break out of the while loop
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
  }
}

View raw code

How the Code Works

Continue reading this section to learn how the code works or skip to the “Demonstration” section.

This sketch is very similar with the sketch used in the ESP8266 Web Server Tutorial. First, you include the ESP8266WiFi library and the needed libraries to read from the BME280 sensor.

// Load Wi-Fi library
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>

The next line defines a variable to save the pressure at the sea level. For more accurate altitude estimation, replace the value with the current sea level pressure at your location.

#define SEALEVELPRESSURE_HPA (1013.25)

In the following line you create an Adafruit_BME280 object called bme that by default establishes a communication with the sensor using I2C.

Adafruit_BME280 bme; // I2C

As mentioned previously, you need to insert your ssid and password in the following lines inside the double quotes.

const char* ssid     = "";
const char* password = "";

Then, you set your web server to port 80.

// Set web server port number to 80
WiFiServer server(80);

The following line creates a variable to store the header of the HTTP request:

String header;

setup()

In the setup(), we start a serial communication at a baud rate of 115200 for debugging purposes.

Serial.begin(115200);

You check that the BME280 sensor was successfully initialized.

if (!bme.begin(0x76)) {
  Serial.println("Could not find a valid BME280 sensor, check wiring!");
  while (1);

The following lines begin the Wi-Fi connection with WiFi.begin(ssid, password), wait for a successful connection and print the ESP IP address in the Serial Monitor.

// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();

loop()

In the loop(), we program what happens when a new client establishes a connection with the web server. The ESP is always listening for incoming clients with this line:

WiFiClient client = server.available(); // Listen for incoming clients

When a request is received from a client, we’ll save the incoming data. The while loop that follows will be running as long as the client stays connected.

if (client) { // If a new client connects,
  Serial.println("New Client."); // print a message out in the serial port
  String currentLine = ""; // make a String to hold incoming data from the client
  while (client.connected()) { // loop while the client's connected
    if (client.available()) { // if there's bytes to read from the client,
      char c = client.read(); // read a byte, then
      Serial.write(c); // print it out the serial monitor
      header += c;
      if (c == '\n') { // if the byte is a newline character
        // if the current line is blank, you got two newline characters in a row.
        // that's the end of the client HTTP request, so send a response:
        if (currentLine.length() == 0) {
          // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
          // and a content-type so the client knows what's coming, then a blank line:
          client.println("HTTP/1.1 200 OK");
          client.println("Content-type:text/html");
          client.println("Connection: close");
          client.println();

Displaying the HTML web page

The next thing you need to do is sending a response to the client with the HTML text to build the web page.

The web page is sent to the client using this expression client.println(). You should enter what you want to send to the client as an argument.

The following code snippet sends the web page to display the sensor readings in a table.

client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons 
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial;}");
client.println("table { border-collapse: collapse; width:35%; margin-left:auto; margin-right:auto; }");
client.println("th { padding: 12px; background-color: #0043af; color: white; }");
client.println("tr { border: 1px solid #ddd; padding: 12px; }");
client.println("tr:hover { background-color: #bcbcbc; }");
client.println("td { border: none; padding: 12px; }");
client.println(".sensor { color:white; font-weight: bold; background-color: #bcbcbc; padding: 1px; }");
 
// Web Page Heading
client.println("</style></head><body><h1>ESP32 with BME280</h1>");
client.println("<table><tr><th>MEASUREMENT</th><th>VALUE</th></tr>");
client.println("<tr><td>Temp. Celsius</td><td><span class=\"sensor\">");
client.println(bme.readTemperature());
client.println(" *C</span></td></tr>"); 
client.println("<tr><td>Temp. Fahrenheit</td><td><span class=\"sensor\">");
client.println(1.8 * bme.readTemperature() + 32);
client.println(" *F</span></td></tr>"); 
client.println("<tr><td>Pressure</td><td><span class=\"sensor\">");
client.println(bme.readPressure() / 100.0F);
client.println(" hPa</span></td></tr>");
client.println("<tr><td>Approx. Altitude</td><td><span class=\"sensor\">");
client.println(bme.readAltitude(SEALEVELPRESSURE_HPA));
client.println(" m</span></td></tr>"); 
client.println("<tr><td>Humidity</td><td><span class=\"sensor\">");
client.println(bme.readHumidity());
client.println(" %</span></td></tr>"); 
client.println("</body></html>");

Note: you can click here to view the full HTML web page.

Displaying the Sensor Readings

To display the sensor readings on the table, we just need to send them between the corresponding <td> and </td> tags. For example, to display the temperature:

client.println("<tr><td>Temp. Celsius</td><td><span class=\"sensor\">");
client.println(bme.readTemperature());
client.println(" *C</span></td></tr>");

Note: the <span> tag is useful to style a particular part of a text. In this case, we’re using the <span> tag to include the sensor reading in a class called “sensor”. This is useful to style that particular part of text using CSS.

By default the table is displaying the temperature readings in both Celsius degrees and Fahrenheit. You can comment the following three lines, if you want to display the temperature only in Fahrenheit degrees.

/*client.println("<tr><td>Temp. Celsius</td><td><span class=\"sensor\">");
client.println(bme.readTemperature());
client.println(" *C</span></td></tr>");*/

Closing the Connection

Finally, when the response ends, we clear the header variable, and stop the connection with the client with client.stop().

// Clear the header variable
header = "";
// Close the connection
client.stop();

Web Server Demonstration

After inserting your network credentials you can upload the code to your board.

Check that you have the right board and COM port selected, and upload the code to your ESP8266. After uploading, open the Serial Monitor at a baud rate of 115200, and copy the ESP8266 IP address.

ESP8266 IP address Serial Monitor

Open your browser, paste the IP address, and you should see the latest sensor readings.

BME280 Web Server with ESP8266 demonstration

To update the readings, you just need to refresh the web page.

You may also like: ESP8266 with DHT11 Sensor – Asynchronous Web Server with Auto Updates

Wrapping Up

This article was an in-depth guide on how to get pressure, temperature and humidity readings from a BME280 sensor with the ESP8266 using Arduino IDE and display the readings on a web server.

Now, you can take this project further and display your sensor readings in an OLED display; create a datalogger; save the readings in your own database or send the readings to your Home Automation platform using MQTT. Here’s some projects and tutorials that might help you implement these ideas:

Learn more about the ESP8266 with our course: Home Automation using ESP8266

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…


Enjoyed this project? Stay updated by subscribing our newsletter!

46 thoughts on “ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)”

  1. When trying to connect with my W10 Firefox, I get these messages on the serial monitor:

    WiFi connected.
    IP address:
    172.20.10.2
    New Client.
    GET / HTTP/1.1
    Accept: text/html, application/xhtml+xml, image/jxr, */*
    Accept-Language: en-US,en-GB;q=0.8,en-DE;q=0.5,en;q=0.3
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
    Accept-Encoding: gzip, deflate
    Host: 172.20.10.2
    Connection: Keep-Alive

    Exception (28):
    epc1=0x40202b6c epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

    >>>stack>>>

    ctx: cont
    sp: 3ffffd80 end: 3fffffc0 offset: 01a0
    3fffff20: 3ffe88bd 3ffe8a63 3fffff50 40203714
    3fffff30: 0000000a 3ffe8a63 3ffee768 40202c50
    3fffff40: 3ffe85d9 3ffe8a63 3ffee908 402012e7
    3fffff50: 402063a8 00000000 00001388 4020fa2f
    3fffff60: 00000000 3ffefcfc 3fff000c 0000005f
    3fffff70: ff2f5054 3ffee7b0 3ffee908 4020267f
    3fffff80: 0000000a 3ffee7b0 3ffee908 402010d1
    3fffff90: 00000000 00000000 00000001 3ffee970
    3fffffa0: 3fffdad0 00000000 3ffee940 40203fc8
    3fffffb0: feefeffe feefeffe 3ffe8510 40100529
    <<<stack<<<

    ets Jan 8 2013,rst cause:2, boot mode:(3,7)

    load 0x4010f000, len 1384, room 16
    tail 8
    chksum 0x2d
    csum 0x2d
    v8b899c12
    ~ld

    Same using Internet Explorer.
    What could be the problem?

    Reply
    • You Need to install the ArduinoIDE plugin EspExceptionDecoder to decipher the stack.
      Try to hard reset your ESP before anything else….

      Reply
  2. BUT it should be in same network the wifi module and the client
    i want to check wifi module from different network

    Reply
  3. Hello Rui.
    Works perfectly here at home.
    But how can I get the values with 1 digit after the comma?
    For example 20.29 gr / c to 20.2 Gr / c
    I have not yet succeeded in doing it myself.
    Thanks in advance.
    Bert Heideveld (the Netherlands).

    Reply
  4. Hi Rui,
    First things first: my compliments for your tutorials! But I have a problem with the webserver part of the tutorial. When uploading the sketch I get this “info” in the serial monitor:

    ⸮!⸮⸮Ԍ⸮

    Exception (3):
    epc1=0x40207fb5 epc2=0x00000000 epc3=0x00000000 excvaddr=0x40030729 depc=0x00000000

    >>>stack>>>

    ctx: cont
    sp: 3ffffbc0 end: 3fffffc0 offset: 01a0
    3ffffd60: 00000001 4010429b 3ffed010 3ffffef0
    3ffffd70: 40100e68 0000049c 000003fd 402080df
    3ffffd80: 0000049c 00001000 000003fd 40100e68
    3ffffd90: 4010655c 00000000 0000001f 40233cd9
    3ffffda0: 40100119 40233dc3 3ffefe44 0000049c
    3ffffdb0: 000003fd 3ffffef0 3ffefe44 40233da6
    3ffffdc0: ffffff00 55aa55aa 00000021 00000020
    3ffffdd0: 00000020 00000004 00000004 aa55aa55
    3ffffde0: 000003ff 40234290 3ffefe44 3ffefe44
    3ffffdf0: 000000ff 3ffefe44 0000049c 00000000
    3ffffe00: 40100119 00000001 3ffefe54 402344aa
    3ffffe10: 00000008 3ffefe44 000000ff 3ffffef0
    3ffffe20: 3fffff10 3ffefe7b 00000021 00000020
    3ffffe30: 3ffeff04 3fffff51 00000001 4023455a
    3ffffe40: 3ffffef0 40241870 00000000 00000009
    3ffffe50: 3fff0244 3fffff10 3fff617c 40234529
    3ffffe60: 3ffefe44 40234590 3ffe8512 3ffe84e6
    3ffffe70: 402023aa 3ffe84e6 3ffe84dc 40202307
    3ffffe80: 5f504b53 36393062 00006530 00000000
    3ffffe90: 3ffee858 00000001 3ffefe44 40233e9e
    3ffffea0: 35373832 39313636 00000037 40207e58
    3ffffeb0: 00000001 3ffefe44 00000000 40208280
    3ffffec0: 000003fd 4023397b 00000000 40100e34
    3ffffed0: 00000001 00000064 3ffee780 40233996
    3ffffee0: 01051000 009dc39b 3ffee851 3ffee84f
    3ffffef0: 5f504b53 36393062 00006530 00000000
    3fffff00: 3ffee858 00000001 3ffefe44 40233eae
    3fffff10: 35373832 39313636 00000037 40207e68
    3fffff20: 00000001 3ffefe44 00000000 40208290
    3fffff30: 000003fd 4023398b 00000000 40100e34
    3fffff40: 00000001 00000064 3ffee780 402339a6
    3fffff50: 40233900 3ffee818 00000081 00000002
    3fffff60: 00000004 00000000

    This happened after I by mistake uploaded an incomplete code, because I did not copy everything. After searching the internet I think that in one or another way the flash memory of the ESP8266 is corrupted or some code is left, so maybe I need a way to clear everything in the flash memory, I think.

    I did upload another sketch (with webserver access), which worked fine before, but now also this program gives similarly messages in the serial monitor. BTW the example code for the BM280 still works OK.

    The problem is therefore probably the code for connection to my network. Any ideas? Thanks for any advice!

    Kind regards,
    Sjoerd W. Bijleveld

    Reply
  5. Hi Rui,
    Problem solved! The Arduino IDE on my Mac shows under the tab “tools” all kind of information about the connected board, in my case Wemos D1 mini and it shows also the option “Erase Flash:” with 3 options: Only Sketch, Sketch + Wifi settings and All Flash Memory. I did choose All Flash Memory and now your sketch works like a charm! I hope this information will help you (and other people with similar problems)!

    Reply
  6. Hi,
    I’ve met trouble with addressing of BMP280 and solve it (thanks to David Stein davidstein.cz/2017/09/30/arduino-bme280-could-not-find-a-valid-bme280-sensor-solved/#comment-141)
    Adafruit lib include an alternate adress but it doesn’t work. Don’t know why.
    So, I’ve modified Adafruit_BMP280.h lib as it :
    #define BMP280_ADDRESS (0x76) /< The default I2C address for the sensor. */
    #define BMP280_ADDRESS_ALT (0x77) /
    < Alternative I2C address for the sensor. */
    instead of original which was :
    #define BMP280_ADDRESS (0x77) /< The default I2C address for the sensor. */
    #define BMP280_ADDRESS_ALT (0x76) /
    < Alternative I2C address for the sensor. */
    (I know, here is BME that we are talking about, but there are the same lines in both libraries so people could have same issue)
    You could also meet same trouble with CHIPID, so you can modified address too :
    #define BMP280_CHIPID (0x58) /**< Default chip ID. */ It could be 0x60, which is not my case.
    Finally, I thank you for your tuto. You are the basement of all my sketches.

    Reply
  7. I ran this and it works great. I am wondering if there is a simple way to add a way to touch the screen (on a smartphone) anywhere to make it refresh the readings webpage?
    Thank you.

    Reply
      • Thank you for your suggestion. I do have a question about this method. Does this cause the whole webpage to be refreshed every 30 seconds or does it just update the temp, pressure and humidity numbers?
        If it reloads the whole page, then how is this better than just using a refresh directive in the section of the html page?

        Reply
        • With Server-Sent Events, you only update the values.
          With the refresh button for the root URL, you upload the whole page.
          You can also add a button that makes a request on a specify URL that only updates the values. There are endless possibilites. I was referring one of the easiest processes.
          Regards,
          Sara

          Reply
  8. Manu has helpfully drawn attention to the confusion with the I2C addresses when using the BMP280 sensor, but have I spent a couple of weeks scratching my head, unaware that I was working with BMP280 sensors.
    I ordered BME280 sensors and they didn’t work. I now notice they are all labelled “GY-BM ME/PM 280” and they behave like BMP280 sensors. One therefore needs to include the Adafruit_BMP.h file rather than Adafruit_BME.h, and work with a bmp object rather than a bme object in the sketch. Also they don’t do humidity.
    Just thought my experience might help others!

    Reply
  9. Why i get :

    ⸮BME280 test
    ?)⸮⸮⸮⸮⸮D⸮j?BME280 test
    H!⸮⸮)
    ⸮DHB?BME280 test
    ?⸮FJ
    ⸮DHB?BME280 test

    while on serial monitor bme280test?

    Reply
  10. Apparently this sketch does not work when using the Adafruit BME280 board made by Stemma QT. (Combo temp, pres, humidity, either I2c or SPI, with level shifter so doesn’t get fried by 5v)

    Something about the power supply? When I successfully compile the script, either using I2c, SPI, or SPIsw, the Arduino IDE cannot connect to the ESP8266mod. If I pull the power to the BME, the IDE can upload the sketch but then when the power to the BME is connected, the ESP reboots, cannot find the BME and then reboots again. This sketch, however, works fine using an Arduino Uno, after making the appropriate pin assignments. Any idea what is wrong?

    Reply
    • Hi John.
      The problem is probably with your USB power supply. It seems it is not providing enough current for ESP8266+sensor.
      Regards,
      Sara

      Reply
  11. Hi !
    First of all, thank you for all your wonderful guides. They’re very helping for learning.

    In this code line, I don’t understand what’s the final F for:
    client.println(bme.readPressure() / 100.0F);

    could you help me?

    Reply
  12. Hi Rui & Sara, I bought 2 BME280 sensors (at least that’s what I thought I bought. I’ve run the
    I2c scanner that nick Gammon and Krodal provided and the sensors report an address of 0x76. Yet I keep getting the message that no I2c devices were found. Any Ideas?

    Reply
  13. Something got lost, new try:


    in other words, I added a metatag in the head section, like “meta http-equiv=”refresh” content=”30″”
    Klaus

    Reply
  14. Hi Rui and Sara
    I got the program for the ESP8266 Web Server on your book using Arduino IDE. I used my MAcBook Pro with the IP Address to control the LED’s This is REALLY COOL!!!!!!
    Switch Off- LED goes “ON”
    Switch ON-LED goes “OFF”

    HEY- Could you explain why the address will not work on my IPhone? I am using Safari. My MAC is using Safari and the address works fine. I would like to use my iPhone to control the devices. Is there something in the code I need to add?

    Can you explain why my IPHONE will not work with the address for the ON/Off switch?

    I am excited I finally got the ESP8266 to work with Arduino. I still need to get Python to work. This is another day!

    BTW: DO YOU HAVE AN APP FOR YOUR PROGRAMS???

    MICHAEL

    Reply
    • Hi.
      If you are one of our customers, please post your issues on the forum: https://rntlab.com/forum/
      It is exclusive for members and we prioritize the forum questions.

      It is supposed to work on iphone. I tested all the examples on iphone and they worked just fine.
      What do you see on the safari web browser when you’re trying to access the web server? What exactly is not working?
      Can you provide more details?

      You can post your answer on the forum.
      Regards,
      Sara

      You can answer on

      Reply
  15. ESP8266 with BMP280
    MEASUREMENT VALUE
    Temp. Celsius 35.12 *C
    Temp. Fahrenheit 95.22 *F
    Pressure 991.12 hPa 29.27 inHg
    Approx. Altitude 185.86 m 609.77 ft

    I used a BMP280, modified the web page, no humidity with this sensor.

    Reply
  16. Hi,
    thanks for the coding examples – nice tutorial.
    Setting the table width in html code to 90% will show the values and units in one row. Maybe 75% or something between will also work.

    Reply
  17. hello,
    how did you modify the lib
    i wanna measure temperature, humidity and pressure so i used <adafruit_BME280.h> lib ….but i got this message in serial monitor : Could not find a valid BME280 sensor
    i tried to scann i2c address ….it’s 0x76
    when i use <adafruit_BMP280.h> lib , it works (but i can just measure temperature and pressure.
    i need t measure the 3 meteo parameters

    Reply
  18. Hi Sara..I get this error.. ESP8266, ESP01, Arduino Nano sketch works fine. Any ideas…
    ————— CUT HERE FOR EXCEPTION DECODER —————

    Soft WDT reset

    Exception (4):
    epc1=0x4020108d epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

    stack>>>

    ctx: cont
    sp: 3ffffe40 end: 3fffffd0 offset: 0160
    3fffffa0: feefeffe feefeffe feefeffe feefeffe
    3fffffb0: 3fffdad0 00000000 3ffeec54 40205314
    3fffffc0: feefeffe feefeffe 3fffdab0 40100f21
    <<<stack<<<

    ————— CUT HERE FOR EXCEPTION DECODER —————

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.