Strange negative values out of a NDIR-CO2-sensor

Hi,
I’m currently trying to get a MH-Z16 CO2-sensor (NDIR) running. I installed the python-code "grove_co2_example.py and the “grove_co2_lib.py” in a dedicated directory (NOT Dexter/GrovePi etc. etc.)
Typing sudo python grove_co2_example.py, no error message occurs BUT I’m getting for the co2-content MINUS 1 ppm and for the temperature -1 degree as well.
Addition info: the sensor is brandnew, is attached to a Grove±shield using the RPIserial-connector. Firmware is up to date.
Thansk in advance

I think that could happen if the library isn’t using the right serial port. Thing is, not long ago on Raspbian, the hardware serial got dedicated for the Bluetooth device and the pin-serial was made to use the software serial, which resides at /dev/ttyS0. You can change the serial port right here.

You can read more on that on these 2 fine pages:
https://www.raspberrypi.org/documentation/configuration/uart.md

I’m curious if this fixes your issue. Please let us know of how your situation evolves.

Thank you!

Dear Robert,
thanks for your answer and support.
Maybe I was not clear in a particular detail: the CO2-sensor is attached to a Grove±shield und there in the RPIserial-slot.

Does this change your answer?

Best regards

Bernhard

----- Ursprüngliche Mail -----

Hi,
I would like to add something rather important to my answer (indicating, that I use a Grove±shield): My RasPi in use is a type 2, so in my understanding this struggling with the PL011 or the ttySO is only important for Pi3 and Zero W-users???
Best regards

B.

Maybe I was not clear in a particular detail: the CO2-sensor is attached to a Grove±shield und there in the RPIserial-slot.

Does this change your answer?

This didn’t change my answer.

I would like to add something rather important to my answer (indicating, that I use a Grove±shield): My RasPi in use is a type 2, so in my understanding this struggling with the PL011 or the ttySO is only important for Pi3 and Zero W-users???

But this one does. As far as I know, it only applies to Raspberry Pis that have the Bluetooth built in - aka the Pi 3, Pi 3 B+ and more recently the Pi 4.

In this case, I don’t see why that sensor wouldn’t work. I think I have a first gen Raspberry Pi and maybe a CO2 sensor around that I could test with. I’ll try to find them and test that script.

Thanks!

Thanks a lot for this support.
Unfortunately I don’t know, how to test this sensor in the same way as an I2C-sensor with i2cdetect -1 in order to see,
if the sensor is working at all.
The minus-values are only indicated, when the sensor is attached to the rpiserial-port, just to mention it.
So “something” is going on…

Let me know about your results, I’m im stand-by mode.

Best regards

Bernhard

----- Ursprüngliche Mail -----

I tried the sensor too on the /dev/ttyS0 interface and it seems to be behaving the same way as your (getting -1 as you do), although with a small twist: sometimes I get values back, but those values that get returned doesn’t make that much sense:

[28535, 70]
[0, -40]
[0, -40]
[0, -40]
[0, -40]
[17519, 79]
[17519, 79]
[29801, 69]
[2629, 80]
[30067, 61]

The temperature values seem way off - as of this moment, there are 38 Celsius degrees now. And the CO2 concentration is wayyy over what it should be: from what I’ve read in the datasheet, the maximum concentration that can be reported is 5000 and definitely not 38000, 17000 or 30000 - not like the above values.

I looked at the source code and it’s the same thing as what I’ve seen on Seeed’s website/wiki.

And one other strange thing about this is that generally (and not always) the CO2 sensor starts spitting values the moment is connected to a power source and then it goes silent - like almost all the time. And I have confirmed that with the logic analyzer too. Again, the GrovePi only acts as an intermediary - it doesn’t even interfere with the traffic on the Raspberry Pi serial. It’s just as if you only had the CO2 sensor connected to the Raspberry Pi.

In your case, I’d contact Seeed and ask them about this - if maybe this is a sign of a malfunctioned sensor, and thus meaning that both of us have broken modules or if there’s something missing from the source code.

Just to help you out on this, this is Seeed’s wiki page:
http://wiki.seeedstudio.com/Grove-CO2_Sensor/

And for easy access, here’s the CO2’s library on ours:

Thanks so far,
I’m “happy” that the error is reproducible in your lab.

Will you give me an update in case SEED has a sufficent work-around?

Best regards

Bernhard

----- Ursprüngliche Mail -----

@bernhard.edler, I contacted someone from Seeed and now I’m waiting for an answer on this matter. I’ll be back with an answer the moment I get something.

Thanks!