So I'm stumped. I am trying to complete this tutorial: https://lastminuteengineers.com/bme280-esp8266-weather-station/, because I want to use a BME-280 sensor connected to the NodeMCU WIFI arduino module to turn on and off a smart switch based on room temp. The NodeMCU connects with the network and transmits what it has just fine all is well. But when reading the BME-280 it just doesn't. It says NaN if I connect it to the Node 3.3v source and ground. It says some absurd value like -143c if I hook it up to a different 3.3v source but leave it connected to the Node via the SLC (D1) SDA (D2) pins (Uno R3 which if I connect the BME-280 to it, works perfectly), If I disconnect the power all together it gets intermittent signals which look about correct (1300 meters above sea level, about 27c) and just garbage mixed in. I've confirmed the NodeMCU seems to work (passes the blink test, transmits what it's getting over wifi) and I've confirmed that the BME-280 works. But when I put them together they simply don't. Any ideas?
Edit: This is the code, I added the serial logging to see what was going on, it's not reading correctly at the serial either
#include <ESP8266WebServer.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
float temperature, humidity, pressure, altitude;
/*Put your SSID & Password*/
const char* ssid = "myqwest4333"; // Enter SSID here
const char* password = "autotime29"; //Enter Password here
ESP8266WebServer server(80);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(100);
bme.begin(0x76);
Serial.println("Connecting to ");
Serial.println(ssid);
//connect to your local wi-fi network
WiFi.begin(ssid, password);
//check wi-fi is connected to wi-fi network
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected..!");
Serial.print("Got IP: "); Serial.println(WiFi.localIP());
server.on("/", handle_OnConnect);
server.onNotFound(handle_NotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
// put your main code here, to run repeatedly:
server.handleClient();
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println("*C");
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();
delay(1000);
}
void handle_OnConnect() {
temperature = bme.readTemperature();
humidity = bme.readHumidity();
pressure = bme.readPressure() / 100.0F;
altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
server.send(200, "text/html", SendHTML(temperature,humidity,pressure,altitude));
}
void handle_NotFound(){
server.send(404, "text/plain", "Not found");
}
String SendHTML(float temperature,float humidity,float pressure,float altitude){
String ptr = "<!DOCTYPE html> <html>\n";
ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
ptr +="<title>ESP8266 Weather Station</title>\n";
ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n";
ptr +="p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n";
ptr +="</style>\n";
ptr +="</head>\n";
ptr +="<body>\n";
ptr +="<div id=\"webpage\">\n";
ptr +="<h1>ESP8266 Weather Station</h1>\n";
ptr +="<p>Temperature: ";
ptr +=temperature;
ptr +="°C</p>";
ptr +="<p>Humidity: ";
ptr +=humidity;
ptr +="%</p>";
ptr +="<p>Pressure: ";
ptr +=pressure;
ptr +="hPa</p>";
ptr +="<p>Altitude: ";
ptr +=altitude;
ptr +="m</p>";
ptr +="</div>\n";
ptr +="</body>\n";
ptr +="</html>\n";
return ptr;
}