BME680气体传感器的价值不断提高

时间:2018-09-16 21:21:02

标签: arduino

我一直在尝试使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");
  }
}

1 个答案:

答案 0 :(得分:0)

我看到两个要点。首先是两个。缺少环境温度和海平面。

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

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