简体   繁体   English

将 BMP280 连接到 ESP8266 NodeMCU 时出现问题 - 检查接线

[英]Problem connecting BMP280 to ESP8266 NodeMCU - check wiring

I am connecting a GY BMP280 to an ESP8266 NodeMCU:我正在将 GY BMP280 连接到 ESP8266 NodeMCU: 在此处输入图像描述

with the wiring:连线:

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

I use the Adafruit BMP280 Library by Adafruit version 2.6.6 And my program is as follows:我使用 Adafruit 版本 2.6.6 的 Adafruit BMP280 库 我的程序如下:

#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:我尝试了不同的端口和不同的代码设置,我认为这是最适合我需要的,但我的串行监视器上一直显示相同的 output:

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?我真的无法弄清楚问题所在,这里有没有人知道可能导致问题的原因是什么?

The message讯息

Soft WDT reset软 WDT 复位

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. ESP8266(或 ESP32)上的代码不应该无限期地运行这样的循环,而不调用yield()delay()来允许其他东西运行。 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?至于为什么您的代码无法检测到传感器,您是否使用 I2C 扫描仪来确认设备连线是否正确?

If it is, the sensor has two possible I2C addresses, 0x76 and 0x77.如果是,传感器有两个可能的 I2C 地址,0x76 和 0x77。 The Adafruit library defaults to 0x77. Adafruit 库默认为 0x77。 Try 0x76.尝试 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.如果这不起作用,那么您遇到了硬件问题,这在这里是题外话,因为 Stack Overflow 是针对软件的。 So if that doesn't work please post about it in the Arduino Stack Exchange .因此,如果这不起作用,请在Arduino Stack Exchange中发帖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM