乐鑫技术交流
直播中

王伟

7年用户 1462经验值
私信 关注
[问答]

让BMP280温度和压力传感器在NodeMCU ESP8266板上工作,无法从BMP280获得任何输出是怎么回事?

大家好
试图让 BMP280 温度和压力传感器在我的 NodeMCU ESP8266 板上工作,但我似乎遇到了问题!
昨天设法让它在 Arduino 上正常工作,但是当我在 ESP8266 上运行草图时,我似乎无法从 BMP280 获得任何输出。  
我想检查一下接线是否正确,因为在研究电路板的引脚图时,我看不到哪些引脚分配给了 I2C 引脚的 SCL 和 SDA。在 Arduino 上,它们是 A4 和 A5,但我不确定 NodeMCU 上哪些是正确的 I2C 引脚。
这是我正在使用的代码。谁能帮忙。谢谢
代码:全选/***************************************************************************
  This is a library for the BMP280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BMEP280 Breakout
  ---->

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
***************************************************************************/

#include
#include
#include
#include

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10

int altitude;

Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));

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

void loop() {
  Serial.print("Temperature = ");
  Serial.print(bme.readTemperature()*9/5+32);
  Serial.println(" *f");

  Serial.print("Pressure = ");
  Serial.print(bme.readPressure() / 100);
  Serial.println(" mB");

  Serial.print("Approx altitude = ");
  Serial.print(bme.readAltitude(1035)); // this should be adjusted to your local forcase
  Serial.println(" m");

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


               


                        

回帖(1)

张娟

2023-9-19 14:44:42
可能的原因有以下几点:

1. 接线错误: 确认连接到正确的引脚。在 NodeMCU 上,I2C 引脚通常是 D1 (SCL) 和 D2 (SDA)。

2. 电源问题:BMP280 需要 3.3V 的电源,而不是 5V。确保将该传感器电源连接到 NodeMCU 板上的 3.3V 引脚。

3. 代码问题:请确保你在代码中正确的引用 Wire 库,并且在 setup() 中初始化 Wire 库,代码应该像这样:

Wire.begin(D1, D2); // 初始化 I2C 引脚

另外,请检查一下 BMP280 模块是否可以在其他设备上正常工作,如 Arduino 或者 Raspberry Pi。

在解决问题之前,建议先确保 BMP280 被正确接线并且接收到正确的电源信号。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分