How to use CO2 grove sensor with serial GrovePi+

HEllo I would like to interface the grove CO2 Sensor :

with my grove Pi+ Board in Python, but I didn’t find any way to do it, could give me some example code?


The Grove CO2 sensor gives the output on the Serial port. We don’t have code for it yet for the GrovePi but it is indeed compatible with the GrovePi, but you’ll have to write some code for it to make it work.

Basically, you’ll have to send commands to it in Python using Pyserial and then read the sensor to find out the values from the sensor.


Thanks for the answer, I was indeed able to access the sensor using pyserial trough the raspberry serial port (let me know where I can publish it) but I was wondering if it is possible to access the sensor using the grovepi+ serial port? is there any special command for this port?


Hey Doms,
Glad to hear that you were able to get the sensor working. It would be great if you send a pull request to the GrovePi github repository here so that other can use it too.

Right now we don’t have a good way to access the Serial port connected to the GrovePi. The Raspberry Pi Serial port is more than enough for most of the applications. Do let us know if there is a specific use-case that you would want to use it for, we might be able to find a work around that .


Hi Doms,

I was wondering if you still had that working code for the CO2 sensor with the GrovePI?

I’m trying to get mine running and am experience some really odd behavior, and was thinking that finding a sample would help a lot.

Alternatively Karan, do you think your team has the capacity to provide any help or guidance on this?


I don;t think we got the pull request for the CO2 sensor code, so you are a bit on you own on this since we don’t have access to the sensor our self but we’ll be happy to help you solve the problem.

If you look at the code here:, you basically have to send a 9byte command: {0xff, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79} to the CO2 sensor at 9600 baud and recieve the data back and convert it to PPM values. The easiest way to do this would be use Pyserial. This might help you with that:

Let us know if this helps and if you need any more help.


Hi guys,

please find an example of python code in attachment
I’ve also pulled a request with some example of code to access the CO2 sensor on

this is a python code that uses either the serial port of the raspberry or an external serial port.

I used the datasheet provided in the wiki :



the file

You sir are my hero.

Thank you, I wasn’t letting it finish warming up and was getting nonsense readings - among other issues.

With the same code were you getting reasonable data from the rpiser port? Or did you switch to USB in order to improve performance?

When I run the code I get unusable readings from the sensor connected through the rpiser port.

Here is an example. (I adjusted the code to loop the print section with a 2 second pause in order to generate the follow-up readings, that and adjusting from USB to Serial are the only adjustments I made).

Read before calibration–> [5644, -32]
CO2 sensor zero calibrated
Read after calibration–> [8204, 0]
Reading value --> [33264, 184]
Reading value --> [8364, -36]
Reading value --> [17222, -14]
Reading value --> [24882, -28]
Reading value --> [37504, 10]
Reading value --> [1200, -37]
Reading value --> [33862, -12]
Reading value --> [18434, 200]
Reading value --> [53717, 96]
Reading value --> [1092, -12]
Reading value --> [1373, 90]
Reading value --> [4736, -20]
Reading value --> [32769, 136]

Hello inexhist,

I was able to read properly from rpiser port, may be you should adjust the timeout when you setup the port:
ser = serial.Serial(’/dev/ttyAMA0’, 9600, timeout = 0.1)
make some tests to adsjut to the proper value :slight_smile:

Some other advice : according to the manual of the sensor it is not necessary to calibrate every time but regularly they say :

“7.1 The sensor should be calibrated regularly. The cycle time is better to be no more than 6 months”

hope it helps.

Hello @inexhist,

I just wanted to let you know that I am seeing the exact same thing. In fact, I also printed out the bytes coming back from the sensor using this same code that was posted, and it’s not even close - both failing to begin with the 0xff, and the checksum is no good.

I went further in testing, as I was getting such random values, that I then changed the read, and was getting huge amounts of data back from the serial port … not just the 9 bytes.

Something must be wrong with my configuration of the RPiSer port … or something related to that.

Today I was thinking of removing the GrovePi entirely, to simply see if I can get the CO2 Sensor to work on the RPi Serial Port without anything else involved … just to isolate the possible issues.

@domsgen thanks for the code sample - as it verified that I had written nearly identical code - but both the code that I wrote, and testing with your code, produce the completely random values that @inexhist printed above, and invalid start byte and checksums.

Same. Junk data.

Just another update here on my CO2 sensor testing.

I am able to get all of my sensors working with the Arduino. No problem. I am NOT able to get it working on the RPiSer port for some reason … power? Current? Voltage?

The CO2 sensor DOES want 5vdc … and again it works perfectly with the Arduino (several different ones) so something is not quite right trying to run it from the RPiSer port on the GrovePi.

Hi Everyone!

I am also experiencing the same issue as others have mentioned above when using the RPISER port. No matter how I try to calibrate, it just seems to give garbage data back. I did notice that the commands that were specified in the calibration code differed from the commands in the manual. I fixed that but it didn’t make the situation any better.



@dpucciMS: What image are you using with the GrovePi. Is it your own image or Raspbian for Robots.


Hi Karan,

I am using Raspbian-Jesse found at this link:

The version I am using is older than the currently listed one at that link, however.


I have the same Problem with the CO2 Sensor. Ich am using a raspberry pi with the grovepi extension and a humiditiy / temperature, loudness and co2 sensor. When I try to start the co2 sensor with the example python file from the library the outcoming results are between 0 and 50000 with no logical pattern. I have connected the sensor to the RPISER adapter.

Is there already a solution for that (couldn’t find one on the internet)?

Thank you very much!

@FreshGrove @dpucciMS: just wanted to let you know that we are looking into the issue with the CO2 sensor and get back to you in some after we have tested it.


Any updates yet? I’m also having this issue and cannot seem to find a way around it.