Grove CO2 sensor example code returns bad values

Hi,

Just tried the CO2 sensor example code committed yesterday and am getting bad values. I know the sensor is fine, I tested on an Arduino Uno. I’m using a Pi2, GrovePi+(1.2.5), sensor is plugged into the RPISER port

Here is a sample of the results:

CO2 Conc: 49086 ppm Temp: 173 C
CO2 Conc: 27037 ppm Temp: 154 C
CO2 Conc: 53242 ppm Temp: 187 C
CO2 Conc: 12457 ppm Temp: 70 C
CO2 Conc: 7152 ppm Temp: 79 C
CO2 Conc: 40726 ppm Temp: 58 C
CO2 Conc: 26828 ppm Temp: 145 C
CO2 Conc: 49962 ppm Temp: 5 C
CO2 Conc: 49470 ppm Temp: 99 C
CO2 Conc: 23616 ppm Temp: 10 C
CO2 Conc: 44813 ppm Temp: -15 C
CO2 Conc: 19914 ppm Temp: 3 C
CO2 Conc: 41800 ppm Temp: 103 C
CO2 Conc: 22261 ppm Temp: 96 C
CO2 Conc: 1999 ppm Temp: 150 C
CO2 Conc: 55712 ppm Temp: 9 C
CO2 Conc: 48392 ppm Temp: 203 C
CO2 Conc: 38661 ppm Temp: 14 C
CO2 Conc: 25733 ppm Temp: 51 C
CO2 Conc: 51262 ppm Temp: 112 C
CO2 Conc: 45235 ppm Temp: 93 C
CO2 Conc: 62213 ppm Temp: 43 C
CO2 Conc: 28262 ppm Temp: 58 C
CO2 Conc: 26769 ppm Temp: 96 C
CO2 Conc: 2979 ppm Temp: 67 C

Any ideas why this might be happening?

Thanks,
Keith

Hey Keith,
Not really sure about this since it looks like you are getting the correct values just bad ones. Can you try printing the self.inp here: https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_co2_sensor/grove_co2_lib.py#L48 and posting the buffer output here so that we can check what the Pi is actually reading.

-Karan

He Karan,

I added a line to print:
print " ".join(hex(ord(n)) for n in self.inp)

Here is what I got:
x1 0x7f 0x2 0xd6 0x35 0x49 0x44 0xde 0x0
CO2 Conc: 726 ppm Temp: 13 C
0x0 0x24 0x14 0x0 0x0 0x0 0x0 0x45 0xe8
CO2 Conc: 5120 ppm Temp: -40 C
0x30 0xc2 0x46 0x44 0x4 0x0 0x13 0x24 0xa7
CO2 Conc: 17988 ppm Temp: -36 C
0xc0 0x81 0x92 0x84 0x84 0x50 0xd1 0xd7 0xe
CO2 Conc: 37508 ppm Temp: 92 C
0x1c 0x0 0x2 0xa1 0x2 0x0 0x0 0x9 0x3
CO2 Conc: 673 ppm Temp: -38 C
0x0 0x80 0x2 0x42 0x56 0x24 0x12 0x0 0x0
CO2 Conc: 578 ppm Temp: 46 C
0xe0 0x2 0x5 0x20 0x20 0x8a 0x20 0x0 0x0
CO2 Conc: 1312 ppm Temp: -8 C
0x81 0x0 0x40 0xa0 0x0 0x20 0x48 0x94 0x6
CO2 Conc: 16544 ppm Temp: -40 C
0x80 0x8 0x0 0x3 0x9 0x40 0x20 0x11 0x25
CO2 Conc: 3 ppm Temp: -31 C
0x0 0x80 0x80 0x88 0x42 0x0 0x88 0x40 0x2
CO2 Conc: 32904 ppm Temp: 26 C

FYI, If I use the same code with a FTDI cable and the sensor it gives me what I would expect as valid values.

Keith

And here is the output when using the FTDI cable.

0xff 0x86 0x0 0xbc 0x41 0x0 0x0 0x0 0x7d
CO2 Conc: 188 ppm Temp: 25 C
0xff 0x86 0x0 0xb8 0x41 0x0 0x0 0x0 0x81
CO2 Conc: 184 ppm Temp: 25 C
0xff 0x86 0x0 0xbd 0x41 0x0 0x0 0x0 0x7c
CO2 Conc: 189 ppm Temp: 25 C
0xff 0x86 0x0 0xbe 0x41 0x0 0x0 0x0 0x7b
CO2 Conc: 190 ppm Temp: 25 C
0xff 0x86 0x0 0xc3 0x41 0x0 0x0 0x0 0x76
CO2 Conc: 195 ppm Temp: 25 C
0xff 0x86 0x0 0xc6 0x41 0x0 0x0 0x0 0x73
CO2 Conc: 198 ppm Temp: 25 C
0xff 0x86 0x0 0xc6 0x41 0x0 0x0 0x0 0x73
CO2 Conc: 198 ppm Temp: 25 C
0xff 0x86 0x0 0xc8 0x41 0x0 0x0 0x0 0x71
CO2 Conc: 200 ppm Temp: 25 C
0xff 0x86 0x0 0xcb 0x41 0x0 0x0 0x0 0x6e
CO2 Conc: 203 ppm Temp: 25 C
0xff 0x86 0x0 0xcc 0x41 0x0 0x0 0x0 0x6d
CO2 Conc: 204 ppm Temp: 25 C

These messages are consistent with the datasheet.

Keith

Also I’ve added a checksum calculation and comparison in the library. Would you like a patch for that?

Hey Keith,
I am still looking into this. Can you post the checksum code here on the forums. I’ll try it out later today.

-Karan

Here ya go.