MH-Z16 CO2 sensor i...
 
Notifications
Clear all

[Solved] MH-Z16 CO2 sensor issues  

  RSS

davidbanner
(@davidbanner)
Active Member
Joined: 5 days ago
Posts: 8
September 13, 2020 4:06 pm  

Hi,

I have managed to install a MH-Z16 sensor on a Pi Running mycodo, but the sensor stops logging data and errors out after a few mins.

This is what is happening in the logs:

2020-09-13 21:03:01,924 - INFO - mycodo.controllers.controller_input_32cfe4b5 - Activated in 3465.6 ms
2020-09-13 21:03:03,616 - DEBUG - mycodo.controllers.controller_input_32cfe4b5 - Adding measurements to InfluxDB with ID 32cfe4b5-4796-4040-a984-9069eebb47a7: {0: {'measurement': 'co2', 'unit': 'ppm', 'value': 387.0, 'timestamp_utc': None}}
2020-09-13 21:03:06,482 - DEBUG - mycodo.controllers.controller_input_32cfe4b5 - Adding measurements to InfluxDB with ID 32cfe4b5-4796-4040-a984-9069eebb47a7: {0: {'measurement': 'co2', 'unit': 'ppm', 'value': 387.0, 'timestamp_utc': None}}
2020-09-13 21:03:11,672 - DEBUG - mycodo.controllers.controller_input_32cfe4b5 - Adding measurements to InfluxDB with ID 32cfe4b5-4796-4040-a984-9069eebb47a7: {0: {'measurement': 'co2', 'unit': 'ppm', 'value': 383.0, 'timestamp_utc': None}}
2020-09-13 21:03:16,483 - DEBUG - mycodo.controllers.controller_input_32cfe4b5 - Adding measurements to InfluxDB with ID 32cfe4b5-4796-4040-a984-9069eebb47a7: {0: {'measurement': 'co2', 'unit': 'ppm', 'value': 379.0, 'timestamp_utc': None}}
2020-09-13 21:03:22,437 - DEBUG - mycodo.controllers.controller_input_32cfe4b5 - Adding measurements to InfluxDB with ID 32cfe4b5-4796-4040-a984-9069eebb47a7: {0: {'measurement': 'co2', 'unit': 'ppm', 'value': 374.0, 'timestamp_utc': None}}
2020-09-13 21:03:27,279 - ERROR - mycodo.inputs.mh_z16_32cfe4b5 - InputModule raised an exception when taking a reading: index out of range
Traceback (most recent call last):
  File "/var/mycodo-root/mycodo/inputs/base_input.py", line 128, in read
    self._measurements = self.get_measurement()
  File "/home/pi/Mycodo/mycodo/inputs/mh_z16.py", line 130, in get_measurement
    low = resp[3]
IndexError: index out of range
2020-09-13 21:03:32,331 - ERROR - mycodo.inputs.mh_z16_32cfe4b5 - Cannot set a value of None. Must be a float or string representing a float. Check the sensor and Input module is working correctly.
2020-09-13 21:03:32,396 - DEBUG - mycodo.controllers.controller_input_32cfe4b5 - Adding measurements to InfluxDB with ID 32cfe4b5-4796-4040-a984-9069eebb47a7: {}

Has anyone got any suggestions as to what my be the issue? or do I have a faulty sensor unit?



Quote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 302
September 13, 2020 4:18 pm  

Hi David,

Can you test the sensor operation when you have nothing else connected to your Pi except the CO2 sensor?

Mycodo Developer


ReplyQuote
davidbanner
(@davidbanner)
Active Member
Joined: 5 days ago
Posts: 8
September 13, 2020 6:39 pm  

Hi @kylegabriel!

How are you?

Thanks for the super quick reply 😀 

 

I tried the sensor again without anything else attached to the Pi (except the wifi dongle). All other sensors have been deactivated in mycodo

It's a Pi Model B+ V1.2 and the sensor is on the UART via GPIO pins.

 

The behavior is the same as before, it reads ok for a few times and then this:

2020-09-13 23:34:21,930 - DEBUG - mycodo.controllers.controller_input_32cfe4b5 - Adding measurements to InfluxDB with ID 32cfe4b5-4796-4040-a984-9069eebb47a7: {0: {'measurement': 'co2', 'unit': 'ppm', 'value': 364.0, 'timestamp_utc': None}}
2020-09-13 23:34:37,564 - ERROR - mycodo.inputs.mh_z16_32cfe4b5 - InputModule raised an exception when taking a reading: index out of range
Traceback (most recent call last):
  File "/var/mycodo-root/mycodo/inputs/base_input.py", line 128, in read
    self._measurements = self.get_measurement()
  File "/home/pi/Mycodo/mycodo/inputs/mh_z16.py", line 130, in get_measurement
    low = resp[3]
IndexError: index out of range
2020-09-13 23:34:52,652 - ERROR - mycodo.inputs.mh_z16_32cfe4b5 - Cannot set a value of None. Must be a float or string representing a float. Check the sensor and Input module is working correctly.
This post was modified 5 days ago by davidbanner

ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 302
September 13, 2020 7:42 pm  

How is the sensor connected? Can you be specific about the wiring? 

This post was modified 4 days ago by Kyle Gabriel

Mycodo Developer


ReplyQuote
davidbanner
(@davidbanner)
Active Member
Joined: 5 days ago
Posts: 8
September 14, 2020 5:04 am  

I am using short wires for testing, with 4 way connectors.

These are the pin connections to the GPIO I am using

CO2 Sensor MH-Z16 Device     Raspberry Pi  
  PIN Name   Pin Name
  4 VIN   2 +5V
  3 GND   6 GND
  5 RXD   8 TXD0
  6 TXD   10 RXD0
           

ReplyQuote
davidbanner
(@davidbanner)
Active Member
Joined: 5 days ago
Posts: 8
September 14, 2020 12:43 pm  

I am using a 2.5 amp power supply so it's unlikely to be a power consumption issue


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 302
September 14, 2020 12:47 pm  

You said it's a Pi model B+, but what version Pi is it (1, 2, 3, or 4)?

Mycodo Developer


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 302
September 14, 2020 12:48 pm  

Have you tried updating the firmware?

sudo rpi-update
This post was modified 4 days ago by Kyle Gabriel

Mycodo Developer


ReplyQuote
davidbanner
(@davidbanner)
Active Member
Joined: 5 days ago
Posts: 8
September 14, 2020 1:33 pm  

Thanks for all your help Kyle :)

Tried the update as suggested, the issue remains.

The full model details: Raspberry Pi Model B+ V1 2
2014

I have a Pi 4 B being delivered on Wed as this one is ancient and super slow, maybe that will eliminate the issue - I will drop a post here either way.


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 302
September 14, 2020 1:40 pm  

Just making sure, but rpi-update was successful at downloading and installing the latest firmware and you did reboot after it completed, correct? 

Mycodo Developer


ReplyQuote
davidbanner
(@davidbanner)
Active Member
Joined: 5 days ago
Posts: 8
September 14, 2020 1:54 pm  
Posted by: @kylegabriel

Just making sure, but rpi-update was successful at downloading and installing the latest firmware and you did reboot after it completed, correct? 

always good to check these things :)

 

yes, the update was successful and I rebooted using: sudo reboot


ReplyQuote
davidbanner
(@davidbanner)
Active Member
Joined: 5 days ago
Posts: 8
September 15, 2020 7:26 am  

The Pi 4 came early!

The mh-z16 seems to be working better now, it's staying connected, the initial reading was at 784 ppm in my home office with me next to it and i've moved it into a room with some house plants and no people and it's reading 442.

I think upgrading to a Pi 4 has solved the issues. 

 

 

This post was modified 4 days ago by davidbanner

ReplyQuote