Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By ErikLem
#56991 hmm, not sure why that delay was there, but without it I still get the same result.

I found a blog where someone seems to have the IAQ working on a ESP, although not using the arduino IDE, but with the nodeMCU firmware and LUA script.

Because I was getting nowhere, I flashed my ESP12 with the nodemcu firmware and loaded the script. Unfortunately, still no result :( I would almost think that there's something wrong with my ESP, ar that I fried the sensor...

next step: testing if they still work on a arduino nano, and after that, try it with a wemos board...
User avatar
By ErikLem
#57300 Thanks for your suggestion schufti ! Very nice library! It took me a few days before I tried it on the IAQ sensor, I first tested it on a BMP180 sensor that I know was working before trying to get it to work with the IAQ sensor.

The good news is that I got it to give me some values :) I can now read all 8 bytes the sensor returns, can see what the status is (first 5 minutes, it will be in warm-up mode) and I get some bytes back that should represent CO2 and TVOC (Volatile organic compound).

I do however have a issue with the values I get back.

For the CO2 I get values between 600 and 1200 (the datascheet says it should be around 450)
For TVOC I see values between 150 and 200 (the datascheet says it should be around 125)

My best bet is that I'm not doing the right calculations. In the datasheet, it says:

ss1.PNG

ss2.PNG


And I translated that into:

Code: Select allco2 = buffer[0] * pow(2, 8) + buffer[1];
tvoc = buffer[7] * pow(2, 8) + buffer[8];


I do see the values going up when I breathe on the sensor (wich is certainly not good for the air quality ;) ), so it seems I'm close...

This the my whole code by the way:
Code: Select all#include "brzo_i2c.h"


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

uint8_t buffer[10];

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, 9, true);

   if (buffer[2] == 0x10 ){
       Serial.println("Warming up...");
   } else
   {

    co2 = buffer[0] * pow(2, 8) + buffer[1];
    tvoc = buffer[7] * pow(2, 8) + buffer[8];
   
    Serial.print("CO2 : \t"); Serial.print(co2);
    Serial.print("TVOC : \t"); Serial.println(tvoc);
   }
   
   /*
   Serial.print("Byte 1:\t"); Serial.println(buffer[0]);
   Serial.print("Byte 2:\t"); Serial.println(buffer[1]);
   Serial.print("Byte 3 (status) :\t"); Serial.println(buffer[2]);
   Serial.print("Byte 4:\t"); Serial.println(buffer[3]);
   Serial.print("Byte 5:\t"); Serial.println(buffer[4]);
   Serial.print("Byte 6:\t"); Serial.println(buffer[5]);
   Serial.print("Byte 7:\t"); Serial.println(buffer[6]);
   Serial.print("Byte 8:\t"); Serial.println(buffer[7]);
   Serial.print("Byte 9:\t"); Serial.println(buffer[7]);
   */

   error = brzo_i2c_end_transaction();

   if (error == 0) {
     //Serial.println("No i2c communication errors");
  }
  else {
    Serial.print("Brzo error : ");
    Serial.println(error);
  }

   //Serial.println("-------------------------------------------");
   delay(500);
}
You do not have the required permissions to view the files attached to this post.
User avatar
By schufti
#57305 maybe you are reading data at the wrong time?
You should generally loop the read and only print results if status==0 and skip output otherwise.
mind that in the print data block you have a typo at the last buffer (2 times 7)
Instead of pow(2,8) just use 256 ...
Or like in Arduino: co=buffer[0]<<8 | buffer[1]