Beetle ESP32 v2.0 + SEN0335 (CCS811 + BME280 )

userHead Michal.Zezulák 2024-04-20 03:59:53 308 Views0 Replies

Hi all,

I want ask for help. I have 2 ESP32 with 2 environmental modules CCS811 + BME280 and have 2 problems. 

   First problem is, that readings aro not accurate (temperature, hunidity). Temperature on the first module is around 3 degrees C higher than temp measured with 3 other temp meters, but it is not linear so i cant count with it. Humidity is also moch lower than other meaurements about 15. The second one is about 1 degree on temp and 5 on humidity so not so different but beyond standard (±0.5℃ temperature error and ±2%RH humidity error). Does wire lenght, diametter or other variables affect the readings (on my test no, but i want to be sure) ?

 

   On one of beetle i have problem with readings of air quality. There are nearly no readings at all. Sometimes it gets one per day (with 1 minute sampling) no matter which of two module i attache to it (both works fine on the other beetle).

 

Here is my code

 

#include <DFRobot_ENS160.h>
#include "DFRobot_BME280.h"
#include <SPI.h>
#include "WiFi.h"

 

#define SEA_LEVEL_PRESSURE    1015.0f

DFRobot_ENS160_I2C ENS160(&Wire, /*i2cAddr*/ 0x53);
typedef DFRobot_BME280_IIC    BME;    // ******** use abbreviations instead of full names ********
BME   bme(&Wire, 0x76);   // select TwoWire peripheral and set sensor address

char server[] = "server_address";
// piny pro připojení Trig a Echo z modulu
WiFiClient client;

// inicializace proměnných, do kterých se uloží data
//long temp, press, alti, humi;

float temp, alti, humi, tempe;
uint32_t press;
uint8_t Status, AQI;
uint16_t TVOC, ECO2;

const char* ssid     = "SSID";         // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "password";     // The password of the Wi-Fi network


// show last sensor operate status
void printLastOperateStatus(BME::eStatus_t eStatus)
{
 switch(eStatus) {
 case BME::eStatusOK:    Serial.println("everything ok"); break;
 case BME::eStatusErr:   Serial.println("unknow error"); break;
 case BME::eStatusErrDeviceNotDetected:    Serial.println("device not detected"); break;
 case BME::eStatusErrParameter:    Serial.println("parameter error"); break;
 default: Serial.println("unknow status"); break;
 }
}

void setup(void)
{
 Serial.begin(115200);
 bme.reset();

 WiFi.begin(ssid, password);             // Connect to the network
 Serial.print("Connecting to ");
 Serial.print(ssid); Serial.println(" ...");

 int i = 0;
 while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
   delay(1000);
   Serial.print(++i); Serial.print(' ');
}
 
 Serial.println("bme read data test");
 while(bme.begin() != BME::eStatusOK) {
   Serial.println("bme begin faild");
   printLastOperateStatus(bme.lastOperateStatus);
   delay(2000);
 }
 Serial.println("bme begin success");
 delay(100);
 // Init the sensor
 while( NO_ERR != ENS160.begin() ){
   Serial.println("Communication with device failed, please check connection");
   delay(3000);
 }

 /**
  * Set power mode
  * mode Configurable power mode:
  *   ENS160_SLEEP_MODE: DEEP SLEEP mode (low power standby)
  *   ENS160_IDLE_MODE: IDLE mode (low-power)
  *   ENS160_STANDARD_MODE: STANDARD Gas Sensing Modes
  */
 ENS160.setPWRMode(ENS160_STANDARD_MODE);

 /**
  * Users write ambient temperature and relative humidity into ENS160 for calibration and compensation of the measured gas data.
  * ambientTemp Compensate the current ambient temperature, float type, unit: C
  * relativeHumidity Compensate the current ambient temperature, float type, unit: %rH
  */
 ENS160.setTempAndHum(/*temperature=*/bme.getTemperature(), /*humidity=*/bme.getHumidity());

}

void loop()
{
 temp = bme.getTemperature();
 press = bme.getPressure();
 alti = bme.calAltitude(SEA_LEVEL_PRESSURE, press);
 humi = bme.getHumidity();
 

 Serial.println();
 Serial.println("======== start print ========");
 Serial.print("temperature (unit Celsius): "); Serial.println(temp);
 Serial.print("pressure (unit pa):         "); Serial.println(press);
 Serial.print("altitude (unit meter):      "); Serial.println(alti);
 Serial.print("humidity (unit percent):    "); Serial.println(humi);
 Serial.println("========  end print  ========");
 /**
  * Get the sensor operating status
  * Return value: 0-Normal operation, 
  *         1-Warm-Up phase, first 3 minutes after power-on.
  *         2-Initial Start-Up phase, first full hour of operation after initial power-on. Only once in the sensor’s lifetime.
  * note: Note that the status will only be stored in the non-volatile memory after an initial 24h of continuous
  *       operation. If unpowered before conclusion of said period, the ENS160 will resume "Initial Start-up" mode
  *       after re-powering.
  */
 Status = ENS160.getENS160Status();
 Serial.print("Sensor operating status : ");
 Serial.println(Status);
 /**
  * Get the air quality index
  * Return value: 1-Excellent, 2-Good, 3-Moderate, 4-Poor, 5-Unhealthy
  */
 AQI = ENS160.getAQI();
 Serial.print("Air quality index : ");
 Serial.println(AQI);

 /**
  * Get TVOC concentration
  * Return value range: 0–65000, unit: ppb
  */
 TVOC = ENS160.getTVOC();
 Serial.print("Concentration of total volatile organic compounds : ");
 Serial.print(TVOC);
 Serial.println(" ppb");

 /**
  * Get CO2 equivalent concentration calculated according to the detected data of VOCs and hydrogen (eCO2 – Equivalent CO2)
  * Return value range: 400–65000, unit: ppm
  * Five levels: Excellent(400 - 600), Good(600 - 800), Moderate(800 - 1000), 
  *               Poor(1000 - 1500), Unhealthy(> 1500)
  */
 ECO2 = ENS160.getECO2();
 Serial.print("Carbon dioxide equivalent concentration : ");
 Serial.print(ECO2);
 Serial.println(" ppm");
 Serial.println();

 Sending_To_phpmyadmindatabase_temp();

 delay(60000);
}
 
void Sending_To_phpmyadmindatabase_temp()   //CONNECTING WITH MYSQL
{
  if (client.connect(server, 80)) {
   Serial.println("connected");
   // Make a HTTP request:
   Serial.print(server);
   Serial.print("GET /dht_temp.php?temp=");
   client.print("GET /dht_temp.php?temp=");
   client.print(temp);     //YOUR URL
   client.print("&press=");
   client.print(press);
   client.print("&alti=");
   client.print(alti);
   client.print("&humi=");
   client.print(humi);
   client.print("&Status=");
   client.print(Status);
   client.print("&AQI=");
   client.print(AQI);
   client.print("&TVOC=");
   client.print(TVOC);
   client.print("&ECO2=");
   client.print(ECO2);
           
   client.print(" ");      //SPACE BEFORE HTTP/1.1
   client.print("HTTP/1.1");
   client.println();
   client.println("Host: server_address);
   client.println("Connection: close");
   client.println();
 } else {
   // if you didn't get a connection to the server:
   Serial.println("connection failed");
 }
}