S8 CO2 reading of -2

Does anyone know what the -2 error means? When I get -2 error it does not send data. I can recover by power cycling the unit and breathing on the sensor. After a couple try’s it’s back. It has only happened twice when I was first setting it up and moving it to different locations. Also, I can’t seem to find the recommended power supply current rating, if someone knows that would be helpful.

Thanks

Hi,

It is a return code of the function AirGradient::getCO2_Raw() in the library airgradient.cpp

As you can see in the code snippet below in the third line from the bottom it says return -2; and means that no value could be read because the software deemed the CO2 sensor not available. Why this is/was the case is not clear for me etiher but I guess a flaw of the softserial library which is having some timing difficulties.

First thing I would do, is check for any electrical issues (check for bad solderings at the sensor and D1).

int AirGradient::getCO2_Raw(){
  // CO2_READ_RESULT result;
  const byte CO2Command[] = {0xFE, 0X44, 0X00, 0X08, 0X02, 0X9F, 0X25};
  byte CO2Response[] = {0,0,0,0,0,0,0};
  
  _SoftSerial_CO2->write(CO2Command, 7);
  delay(25);
  
  if (_SoftSerial_CO2->available()){
	for (int i=0; i < 7; i++) {
      int byte = _SoftSerial_CO2->read();
      CO2Response[i] = byte;
	  Serial.print (CO2Response[i],HEX);
	  Serial.print (":");
	  if (CO2Response[0] != 254) {
		  Serial.println("Invalid serial read");

		  return -1;
	  }
		  // Serial.print (CO2Response[i],HEX);
	      // Serial.print (":"); 	  
	} 
	Serial.println();
    unsigned long val = CO2Response[3]*256 + CO2Response[4];  
    return val;	
  }	
  else
  {
    return -2;
  }
}

I also get a -2 on the CO2 sensor. However, when I have the USB cable attached to my computer and the Arduino IDE serial monitor active, it works just fine. Close the serial monitor and the CO2 sensor stops working.

In case it helps anyone, I too was seeing the -2 value from the S8. I went back and rechecked all of my solder joints and noticed one that needed a bit of touchup. That fixed the problem and it has been working fine since.

The S8 needs a very stable power supply. So make sure you have a high quality power adapter. This often helps with these issues as well.

Even with my bench top power supply, it’s a bit flaky… I’ll have my improved circuit boards in the next week. I’ll let you know how that works out once I get everything connected.

So… I have my updated board running an SGP30 with an S8 CO2 and SHT31, all sensors are working as expected on my updated board.

Readings are a bit wonky right now as I’ve only had it up for a few minutes… Seems none of these sensors play nicely for the first couple of days.

I’m still missing the PM sensor on this board, but it’s somewhere in transit between China and me.

# HELP particle_count Count of Particulate Matter in µg/m3
# TYPE particle_count gauge
particle_count{id="",mac="30:83:98:XX:XX:XX",type="PM2.5"}0
# HELP particle_count Count of Particulate Matter in µg/m3
# TYPE particle_count gauge
particle_count{id="",mac="30:83:98:XX:XX:XX",type="PM1.0"}0
# HELP particle_count Count of Particulate Matter in µg/m3
# TYPE particle_count gauge
particle_count{id="",mac="30:83:98:XX:XX:XX",type="PM10.0"}0
# HELP rco2 CO2 value, in ppm
# TYPE rco2 gauge
rco2{id="",mac="30:83:98:XX:XX:XX"}2564
# HELP atmp Temperature, in degrees Fahrenheit
# TYPE atmp gauge
atmp{id="",mac="30:83:98:XX:XX:XX"}72.46
# HELP rhum Relative humidity, in percent
# TYPE rhum gauge
rhum{id="",mac="30:83:98:XX:XX:XX"}39.34
# HELP sensors_boot_time AirGradient_Internal boot time, in unixtime.
# TYPE sensors_boot_time gauge
sensors_boot_time{id="",mac="30:83:98:XX:XX:XX"}1647090391
# HELP total_volatile_organic_compounds total of armful gaz detected.
# TYPE total_volatile_organic_compounds gauge
total_volatile_organic_compounds{id="",mac="30:83:98:XX:XX:XX"}34
# HELP ethanol ethanol level.
# TYPE ethanol gauge
ethanol{id="",mac="30:83:98:XX:XX:XX"}19092
# HELP hydrogen hydrogen level.
# TYPE hydrogen gauge
hydrogen{id="",mac="30:83:98:XX:XX:XX"}13854

image

This board revision is a definite win. With no mods, everything is working just fine including the CO sensor and SGP30.

Just got a PM sensor and it’s working as well. I will attach the gerbers later after I do a couple small edits.

Modified Board Gerber Files

Tested to 3.73 volts on the 5v rail. Still runs just fine.