大家好
试图让 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);
}