arduinosensorsesp8266nodemcuarduino-esp8266

Problem connecting BMP280 to ESP8266 NodeMCU - check wiring


I am connecting a GY BMP280 to an ESP8266 NodeMCU: enter image description here

with the wiring:

  1. VCC = 3.3V
  2. GND = GND
  3. SCL = D1 (GPIO5)
  4. SDA = D2 (GPIO4)

I use the Adafruit BMP280 Library by Adafruit version 2.6.6 And my program is as follows:

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

Adafruit_BMP280 bmp; // create a BMP280 instance

#define SEALEVELPRESSURE_HPA 1013.25

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial console to open
  }

  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
}

void loop() {
  float temperature = bmp.readTemperature();
  float pressure = bmp.readPressure() / 100.0F;
  float altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA);

  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(pressure);
  Serial.println(" hPa");

  Serial.print("Altitude = ");
  Serial.print(altitude);
  Serial.println(" meters");

  Serial.println();
  delay(2000);
}

I have tried different ports and different code setups, this is in my opinion the most correct for what i need, but i keep getting the same output on my serial monitor:

Soft WDT reset

>>>stack>>>

ctx: cont
sp: 3ffffdf0 end: 3fffffc0 offset: 01a0
3fffff90:  3fffdad0 00000000 3ffee6fc 4020105c  
3fffffa0:  feefeffe feefeffe 3ffee750 40203268  
3fffffb0:  feefeffe feefeffe 3ffe85e0 40100ef5  
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------
�{���4��Could not find a valid BMP280 sensor, check wiring!

I really cant figure out the problem, does anyone here have an idea of what could cause the trouble?


Solution

  • The message

    Soft WDT reset

    means you're triggering the watchdog timer. The watchdog timer is part of the system which halts it with an error in case part of it runs for too long without allowing other parts to run.

    In this case it's this code that triggers it:

     if (!bmp.begin()) {
        Serial.println("Could not find a valid BMP280 sensor, check wiring!");
        while (1);
      }
    

    Code on an ESP8266 (or ESP32) should not run loops like that indefinitely without ever calling yield() or delay() to allow other things to run. That's what triggers the watchdog.

     if (!bmp.begin()) {
        Serial.println("Could not find a valid BMP280 sensor, check wiring!");
        while (1)
           yield();
      }
    

    As for why your code can't detect the sensor, have you used an I2C scanner to confirm that the device is even wired correctly?

    If it is, the sensor has two possible I2C addresses, 0x76 and 0x77. The Adafruit library defaults to 0x77. Try 0x76.

     if (!bmp.begin(0x76)) {
    

    If that doesn't work then you have a hardware problem, which is off-topic here as Stack Overflow is for software. So if that doesn't work please post about it in the Arduino Stack Exchange.