esp32_bme280.md | Last modified: 1756638024 | Edit | Home

ESP32 + BME280 with Arduino IDE

https://randomnerdtutorials.com/esp32-bme280-arduino-ide-pressure-temperature-humidity/

Comment savoir si l'on a affaire un BMP280 ou un BME280 -> Lien vers le wiki des Fabriques du Ponant

5V vs 3.3V -> Autre lien vers les Fabriques du Ponant

J'ai un BME280 5V :

Connexion BME -> ESP

BME280 ESP32-DevKitC V4
VCC 5V
GND GND
SDA GPIO21 (WIRE-SDA)
SCL GPIO22 (WIRE-SCL)

https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32/esp32-devkitc/user_guide.html#pin-layout

Webserver

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

Adafruit_BME280 bme; // I2C

WebServer server(80);

void handleRoot() {
  String html = "<!DOCTYPE html>";
  html += "<html>\n";
  html += "<head>\n";
  html += "<title>Server ESP32</title>\n";
  html += "</head>\n";
  html += "<body>\n";
  html += "<p>" + String(bme.readTemperature()) + "</p>";
  html += "</body>\n";
  html += "</html>";
  server.send(200, "text/html", html);
}

void handleNotFound() {
  server.send(404, "text/plain", "File Not Found");
}

void setup() {

  Serial.begin(115200);
  while (!Serial) delay(100);

  unsigned status;

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

  WiFi.begin("ssid", "passwd");

  Serial.print("Connecting to WiFi... ");
  while (WiFi.status() != WL_CONNECTED) delay(500);
  Serial.println("Ok.");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/", handleRoot);

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");

}

void loop() {

  server.handleClient();
  delay(1);

}