[md]# BME280
BME280是一款气压传感器,因附带有温湿度传感器,让其显得很超值。
## 硬件&接入方式
开发板使用esp8266开发板,接入方式为WiFi接入
BME280支持SPI和IIC两种模式,本示例使用IIC驱动,传感器连接到开发板IIC接口即可
## 驱动库(两个都需要装)
https://github.com/adafruit/Adafruit_BME280_Library
https://github.com/adafruit/Adafruit_Sensor
## 示例程序
```
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "Your Device Secret Key";
char ssid[] = "Your WiFi network SSID or name";
char pswd[] = "Your WiFi network WPA password or WEP key";
BlinkerNumber TEMP("temp"); // Temperature
BlinkerNumber PRES("pres"); // Pressure
BlinkerNumber ALTI("alti"); // Altitude
BlinkerNumber HUMI("humi"); // Humidity
// Download Adafruit-BMP085-Library library here:
// https://github.com/adafruit/Adafruit_BME280_Library
// https://github.com/adafruit/Adafruit_Sensor
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void heartbeat()
{
TEMP.print(bme.readTemperature());
HUMI.print(bme.readHumidity());
PRES.print(bme.readPressure());
ALTI.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Blinker.attachHeartbeat(heartbeat);
if (!bme.begin()) {
BLINKER_LOG("Could not find a valid BME280 sensor, check wiring!");
while (1) {delay(100);}
}
}
void loop()
{
Blinker.run();
}
```[/md]
|