Spikes in CO2 and TVOC measurements with CJMCU-811 sensor
I have two of those sensors in a long term setup and I know those spikes very well. I once put lots of effort in debugging and I personally gave up on the ccs811 and use a different sensor now.
Back then I have already tried what Jaromanda suggests in his comment.
Both of my sensos showed the same behaviour while the spikes on both sensors did not correlate in any form.
Also, if I remember it right, those erronous readings appeared to be at dedicated values.
I tried several pullups, which also didn't make any difference and on the oscilloscope everything looked fine.
Printing the output of the I2C related functions revealed that communication was always stable. If it was I2C related I would expect those erronous readings to be completely random anyway (which they aren't from my experience).
My final (vague) theory was that maybe there exist race conditions between the computation and the I2C interface or maybe the adc and the approximation algorithm (that's all &quot;inside&quot; of the sensor). I once produced such a bug myself which resulted in a similar behaviour.
At least I'm pretty sure that there is nothing you can do in your sketch to fix this problem, because for the mentioned reasons it is very unlikely related to communication problems. You might want to work-around it or look for an updated firmware.
Or (my prefered solution) choose a sensor which does a true CO2 measurement (the ccs811 only returns a pseudo, calculated CO2-equivalent approximation).
Those higher-class sensors use NDIR technique and are only a bit more expensive (still under 50$) but you'll probably have much more reliable readings, less problems and a wider measurement range (up to 0-40000ppm vs 400-8192ppm).
Ps: did you follow the guidelines concerning the &quot;burn-in time&quot;? Because honestly, that was a mistake I did: I simply plugged it in of curiosity to test communication and read about this step afterwards. But I don't believe it has something to do with this problem, because there are physical reasons why one should do so, but those artifacts seem to be of digital nature.