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) |

- Sketch > Include Library > Manage Libraries > adafuit bme280
- (Sketch > Include Library > Manage Libraries > adafuit unified sensor)
- File > Examples > Adafruit BME280 library > bme280test
- Comment lines (ligne 20) ''#include <SPI.h>'' et de ''/#define BME_SCK 13'' à ''#define BME_CS 10/'' (line 24 à 27)
- Ajouter 0x76 (ligne 46) -> ''status = bme.begin(0x76);''
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);
}