Monitoring air quality with IAC-core c and ESP8266

Yes I would. However they give you different information. The BME680 gives you a air quality %, based on some calculations. The CCS811 returns eCO2 and TVOC.
If you are planing to use on the RPi you will need to reduce the baudrate on i2c.

1 Like

I did not yet have any luck with the ccs811. Normaly I first start with the i2c scanner (https://playground.arduino.cc/Main/I2cScanner) when I get a new i2c sensor, but the ccs811 did not show up with that, not on a arduino or ESP8266.

I now did some testing with the BRZO library (https://github.com/pasko-zh/brzo_i2c), that I used for the IAQ core sensor too. I made a very simple sketch that should return at least some data:

#include "brzo_i2c.h"


uint8_t SDA_PIN = 4;
uint8_t SCL_PIN = 5;
uint8_t iaq_adr = 0x5A;

uint8_t buffer[14];

uint8_t error = 0;

uint16_t co2;
uint16_t tvoc;

void setup() {
  Serial.begin(115200);
  brzo_i2c_setup(SDA_PIN, SCL_PIN, 3000);
}

void loop() {
   brzo_i2c_start_transaction(iaq_adr, 100);
   brzo_i2c_read(buffer, 14, true);

   Serial.println(buffer[0]);

   error = brzo_i2c_end_transaction();

   if (error != 0) {
    Serial.print("Brzo error : ");
    Serial.println(error);
  }

   delay(500);
}

But all I got was error nr4, which means: no communication. I even tried pulling the addr pin to high, so the address would change into 0x5B, but to no avail. I’m guessing that these cheap ccs811 sensors from aliexpress are just bogus (wouldn’t be the first time I get fake ic’s from aliexpress).

My testing setup got pretty messy by the way :smile:

My next project will be testing this sensor:

It’s a NDIR (nondispersive infrared sensor) co2 sensor, which should give more reliable CO2 readings.

Erik I was only able to get the CCS811 on my RPi. I have the Sparkfun BME280+CCS811 combo. I couldn’t get to work with their own ESP32. Didn’t try on 8266 NodeMCU.

I should correct my thoughts to badstraw. The BME680 has a great advantage that is compatibility around all platforms.

1 Like

Hmm, interesting, but there shouldn’t actually be any reason for it now to work on a esp8266 or arduino. Just to be sure, I now ordered one from adafruit, together with a bme680 and a SGP30 sensor (https://www.adafruit.com/product/3709)

I hope to get them all running together so that I can compare then and see wich one gives me the best results.

I did some work on the MH-Z14a, got it working on a arduino, now I want to get it working on a ESP8266 so that I can send the values via MQTT to home assistant

I now have the MH-Z14a working on a ESP8266 and am able to send over the values via MQTT to home assistant. Code sample here:

It was a bit tricky to get it running because the MH-Z14a required 5v, while the ESP8266 needs 3.3v.

I will soon report on the values I get out of it, they seem to be a bit lower than what the IAQ core-c is reporting.

I also got the CCS811 in from adafruit, so I hope I can soon compare the three.

I got some results, I nog had the IAQ-core-C, CCS811 and MH-Z14a running alongside for one day. If I put all of then together in one graph, it looks like this:

image

It’s interesting to see that the IAQ-core-C and CSS811 follow the same path, but the CCS811 is reporting a much higher value. The co2 values the CSS811 are reporting are way above what is considered to be healthy.
In this graph it looks like the MH-Z14a is not doing much, but when I only put that sensor in a graph, it looks like this:

image
if you look at it closely, you can see that it is the same pattern as the IAQ-core-C and CCS811, but with much lower values. This sensor also works in a very different way and can report lower values than the other 2 sensors.

Not sure what conclusion I can draw from these values, I think I just let them run for a few more days, while I wait for the bme680 and SGP30 sensors.

I did publish my code for the CCS811 here:

I will try your CCS811 code later the week. My CCS811 has a tendency to “crash”.
I was able to get the BME680 ruining with the BSEC (official bosh) code.
It is way more sophisticated than the other BME680 codes. Including the one for the home assistant.

On the Pi the C code runs flawlessly just need to figure it out how to mqtt the data from C.

For the Arduinos (ESP32 and ESP8266)

The setup is way easier on platformio. Just place the libalgobsec.a and add build_flags = -L/Users/username/Documents/PlatformIO/Projects/BSEC_BME680/lib/ -lalgobsec

I now got the BME680 and SGP30 sensors in too. I now have all 5 sensors running next to each other.
I made 2 sketches to run them on a ESP822 once more:

The BME680 is a interesting sensor, because it can also report temperature, humidity and pressure. It however doesn’t give a CO2 or eCO2 value, it just gives a resistance value, that you should somehow convert into a values that makes sense.

I will leave all 5 sensors running for a while now, see if I can make sense out of their output values and see which one is the most reliable.

To make it sense of the gas resistance from the BME680 you need the precompiled Bosch BSEC library. It’s easier to run on the pi than the Arduino. If you want I can post later how to get to work on the esp via platformio IDE.
Without the Bosch library the BME680 is running like a BME280 with meaningless gas readings.

Here is how I got to get the BME680 running using Bosch BSEC Arduino Library on Platformio IDE.

  1. Create a project for the board that you are going to use.

  2. Copy the https://github.com/BoschSensortec/BSEC-Arduino-library/

  3. Copy the files from BSEC-Arduino-library/src to your src folder on Platformio IDE.

  4. Copy the files from BSEC-Arduino-library/examples/basic_config_state/ also to the src folder (bsec_serialized_configurations_iaq.cpp and bsec_serialized_configurations_iaq.h)

  5. Copy the source code from the https://github.com/BoschSensortec/BSEC-Arduino-library/blob/master/examples/basic_config_state/basic_config_state.ino to your main.cpp

  6. Download the latest library at https://www.bosch-sensortec.com/en/bst/products/all_products/bsec

  7. Copy the libalgobsec.a file for the ESP8266 to the folder lib on your platformio project.

  8. Add this line at the end of your platformio.ini
    build_flags = -L/Users/USER/Documents/PlatformIO/Projects/BSEC_BME680/lib/ -lalgobsec

Hopefully,​ it will build. I know it sounds complicated but is less than changing your Arduino IDE to use precompiled libraries.

1 Like

Thanks! Will soon give it a try.

I gave it a try, but I’m stuck at point 7 and 8. I couldn’t find a platformio file, but maybe that’s the platform you are using from https://platformio.org/ ?

I also tried to follow the steps at https://github.com/BoschSensortec/BSEC-Arduino-library/, but got stuck at 4. Modify the platform.txt file , the lines in it I should change differ from what they say there. I’m also not sure what platform.txt I should edit, I have a very small one in C:\Program Files (x86)\Arduino\hardware and one in C:\Program Files (x86)\Arduino\hardware\arduino\avr

I did some more testing yesterday by the way, Iwas working from my home office, so I was able to see what the sensors reported when I closed the door and window.

8:00 : started working with window & door closed
11:30 Oped window and door
13:00 Closed window

ccs811: Seemed to have picked up all changed nicely
ccs811

IAC core C: Same pattern, only reporting much higher values
iaq%20core%20c
I hope these values are not the real co2 values, because that would be quite unhealthy according to this table:
image

SGP30: Same pattern again, little bit lower than the cc811. Goes back to 400 when the CO2 concentration is on the low side
sgp30

MH-Z14a: Same story again :), only did not pick up what happened around 17:00 (I actually can’t remember what I did at that time, I think I was in and out of the room a few times.
mhz14a

BME680: Ok, no c02 values here, I just plotted the resistance values, higher is better in this case. I also picked up the same changes, so that’s good, but it died just before 16:00 (worked again after a ESP reset)
bme680

I did notice that the IAC core C and ccs811 sometime drift off to way too high values. I seem to get the best “real co2” results from the MH-Z14a, but that’s not really surprising since it works in a much different way than the other 4. The good news is that all are capable of giving you a general idea of the indoor air quality.

I eventually want to be able to install a air quality sensor in every room in the house, not sure yet which one it’s going to be (and with what other sensors I’m going to combine it, for instance with a dust sensor)

1 Like

I’m using with Atom. You need to create a new project on Platformio IDE.

But honestly, you seem more used to the Arduino IDE. Then follow the BSEC-Arduino guide.

On step 4 is the plataform.txt file that is in C:\Program Files (x86)\Arduino\hardware\arduino\avr

If you are using a 8266 you will need step 5. The address to the file on windows seems to be:
C:\Users\USERNAME\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\tools\sdk\ld\eagle.app.v6.common.ld

https://scottsnowden.co.uk/esp8266-arduino-text-will-not-fit-in-region-iram1_0_seg-error/

The data look interesting. Hopefully, I can run some tests with the CS811 and the BME680 this week.

A thanks, didn’t know we where talking about a different IDE, seems like a interesting one too, have to look into that some day :slight_smile:

I’m now still trying to get it working with the Arduino IDE, I’ve made some progress. I turned out the platform.txt I had to modify was located in C:\Users<username>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1

After modifying that, I edited eagle.app.v6.common.ld, that was located in C:<username>\Erik\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\tools\sdk\ld to add libalgobsec.a and copied libalgobsec.a to my BSEC library location in C:\Users<username>\Documents\Arduino\libraries\BSEC-Arduino-library-master\src\esp8266

I also had to modify bme680_defs.h , I had to change:

/** BME680 I2C addresses */
#define BME680_I2C_ADDR_PRIMARY		UINT8_C(0x76)
#define BME680_I2C_ADDR_SECONDARY	UINT8_C(0x77)

into

/** BME680 I2C addresses */
#define BME680_I2C_ADDR_PRIMARY		UINT8_C(0x77)
#define BME680_I2C_ADDR_SECONDARY	UINT8_C(0x76)

I’ve now been able to get the basic sample compiled and it is returning some values.
Temperature and humidity seem to be ok, but for IAQ I constantly get 25 and a accuracy of 0, so I have to look into that, maybe it needs a burn in time or something.

The accuracy and the values will change once it has enough data. The basic_config_state.ino saves on the data on the EEPROM.

The history BSEC considers for the automatic background calibration of the IAQ in days. That means changes in this time period will influence the IAQ value.

  • 4days means BSEC will consider the last 4 days of operation for the automatic background calibration.
  • 􏰀28days, means BSEC will consider the last 28 days of operation for the automatic background calibration.

On basic_config_state.ino
#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // 360 minutes - 4 times a day

There is more info on the pdf from Bosch. I haven’t really look into. Also, at least on Linux there are different modes for the 1.8v (closed cube) and the 3.3v.

It is different than the most sensor that just gives you the right data. The temperature tracking is really good however it does not comes calibrated from the factory. Mine are usually higher than other factory calibrated temperature sensors. I still need to find on their documentation how to adjust the temperature delta.

Just change:
iaqSensor.begin(BME680_I2C_ADDR_PRIMARY, Wire); to iaqSensor.begin(BME680_I2C_ADDR_SECONDARY, Wire); then you don’t need to change bme680_defs.h.

I’m considering opening a topic about the BME680 since I don’t believe the implementation that we have on Home Assistant is the best one.

Found this thread - I found these sensors that calculate “eco2”, “equivalent” co2 and this seems to be the only reasonable discussion comparing them to actual co2 sensors. The only sensor you’re testing here that’s actually a co2 sensor is the MH-Z14a, correct? The other three are “equivalent”?

I’m guessing the other sensor picks up other gasses. Could you try this experiment: At the sensors, put a glass of alcohol (wine, rubbing alcohol, etc). See if they think this is co2? It should register as tvoc, but it should not register as co2.

Hi Mirar,

Sorry for my very late reply :hushed:
unfortunately I don’t have my test setup running anymore, so I can’t easily do that test.

The MH-Z14a was indeed the only “real” co2 sensor. Since it gave me the most consistent results, I eventually wend with that sensor and created a board for it:

!
On top of the board the mh-z14a can be placed:

and together they can fit in this housing:

Unfortunately the thing still has a few flaws:

  • The co2 sensor stops reporting values after a while. Sometimes after a hour, sometimes after several days
  • the si7021 sensor I combined it with to report humidity and temperature is giving much too high temperature values, possibly because of the proximity to the ESP8266

Hi - Thanks a lot… this code worked great with a Wemos D1 Mini (adjusted the pin) - getting great reading after 24 hours - and connected to home assistant via MQTT.
However, I am having trouble with the sensor code in configuration.yaml
mqtt:
broker: 192.168.0.87
port: 1883

Sensors

sensor:

  • platform: mqtt
    name: “CO2”
    state_topic: “ccs811/co2”
    qos: 0
    unit_of_measurement: ‘PPM’

Any help? Sorry really don’t understand the json syntax… and/or how it translates to the sensors in the UI.
Thanks

Does anyone have a wiring schematic for the IAQ-core C and the ESP8266 (I’ve got one of these laying around: AliExpress NodeMCU esp8266 CH340

On Erik’s GitHub page the schematic is still a ToDo :slight_smile:

Edit:

Did some Googling so I’ll save whoever comes across this post the hassle:

In the code SDA=4, this is D2 on the NodeMCU v3 board (source)
SCL=5, this is D1 on the board

3V3 connects to 3V on NodeMCU
GND with G

So basically:

IAQ Pin 1 - unconnected
IAQ Pin 2 - NodeMCU D1
IAQ Pin 3 - NodeMCU G (any is OK)
IAQ Pin 4 - NodeMCU D2
IAQ Pin 5 - unconnected
IAQ Pin 6 - NodeMCU 3V

Hint: you can sample these parts for free on the AMS website if you’re lucky.

Hmm, all I get out of the I2C communication is all zeroes… @ErikNL any ideas what could be wrong?