【问题标题】:BME680 gas sensor's value keeps increasingBME680气体传感器价值不断提升
【发布时间】:2018-09-16 21:21:02
【问题描述】:

我一直在努力让 BME680 正常工作,而且在大多数情况下,它似乎工作得很好。我确实有一个问题,那就是气体传感器。

我把BME680的所有内容都写到一个网页上,其他的值都保持一致。

Temperature: 77.29 *F
Humidity: 59.12 %
Pressure: 1010.45 millibars
Air Quality: 3.24 KOhms

每次刷新页面时,温度、湿度和压力的值都保持接近它们的值。他们纠正了一会儿,并正确显示了微小的波动。当开始下雨时,压力下降,湿度上升等等......问题是气体传感器。每次刷新时,值都会不断增加。无论我是每分钟刷新一次还是每小时刷新一次,它都会不断增加。我显然做错了什么。

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#include <WiFi101.h>
#include <WiFiUdp.h>

#include "arduino_secrets.h" 

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
WiFiServer server(80);

#define SEALEVELPRESSURE_HPA (1023.03)

Adafruit_BME680 bme; // I2C

void setup() {
  //Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);      // set the LED pin mode
  bme.begin();

  // Set up oversampling and filter initialization
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150); // 320*C for 150 ms

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    //Serial.println("WiFi shield not present");
    while (true);       // don't continue
  }

  // attempt to connect to WiFi network:
  while ( status != WL_CONNECTED) {
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();                           // start the web server on port 80
}

void loop() {

  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    //Serial.println("new client");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        //Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();


            if (! bme.performReading()) {
              client.print("Failed to perform reading :(<br>");
              return;
            }
            // the current weather condidtions
            client.print("Temperature: ");
            client.print((bme.temperature * 9/5) + 32);
            client.print(" *F<br>");

            client.print("Humidity: ");
            client.print(bme.humidity);
            client.print(" %<br>");

            client.print("Pressure: ");
            client.print(bme.pressure / 100.0);
            client.print(" millibars<br>");

            client.print("Air Quality: ");
            client.print(bme.gas_resistance / 1000.0);
            client.print(" KOhms<br>");

            delay(2000);

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          }
          else {      // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        }
        else if (c != '\r') {    // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    // close the connection:
    client.stop();
    //Serial.println("client disonnected");
  }
}

【问题讨论】:

  • 来自Adafruit page:“我们建议您在第一次收到此传感器时运行 48 小时以“烧入”,然后每次以所需模式运行 30 分钟传感器正在使用中。这是因为传感器的灵敏度水平会在早期使用期间发生变化,并且随着 MOX 升温到其基线读数,电阻会随着时间缓慢上升。"
  • 我投票结束这个问题,因为它看起来像一个硬件问题,而不是编程问题。
  • @gre_gor 完全正确。预烧期已完成。代码对你来说看起来不错?我没有看到任何明显的问题,但我想也许我错过了某种初始化方法或其他东西。

标签: arduino


【解决方案1】:

我看到了两个重点。两个为开始。缺少环境温度和海平面。

默认环境温度:25℃ 默认海平面为:500米

将正确的值添加到您的代码中。然后你必须在刻录后做一些自动校准。我自己的经验是,需要 2 周 24/7 的时间让传感器根据需要变得更旧。下一步查看 BOSCH 原始库和示例代码。然后重新开始。目前我正在为 Tasmota (github) 重写 BME 和 BMP 系列的驱动程序。很多工作相信我。我来自物理和化学方面。所以一些研究总是有帮助的。

【讨论】:

  • 我定义了它,但我不确定如何使用它。 #define SEALEVELPRESSURE_HPA (1023.03)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多