MH-Z19B detection issue

Hello,

So newb question but I’m not able to read any data from my MH-Z19B sensor. Below is the log after deactivating and reactivating the sensor on the input page. It states to “Review the log lines following Input Activation to investigate why this happened.” but after the Activation line it just says “ERROR - mycodo.controllers.controller_input_ea4c154a - Mycodo is attempting to acquire measurement(s) from an Input that has already critically errored. Review the log lines following Input Activation to investigate why this happened.” :slight_smile: So is there a different log I’m supposed to look at?

2022-06-16 12:58:18,295 - INFO - mycodo.controllers.controller_input_ea4c154a - Deactivated in 33.8 ms
2022-06-16 12:58:45,136 - ERROR - mycodo.controllers.controller_input_ea4c154a - initialize_variables() Exception: Write timeout
Traceback (most recent call last):
File “/var/mycodo-root/mycodo/controllers/base_controller.py”, line 74, in run
self.initialize_variables()
File “/var/mycodo-root/mycodo/controllers/controller_input.py”, line 317, in initialize_variables
self.measure_input = input_loaded.InputModule(self.input_dev)
File “/home/gg/Mycodo/mycodo/inputs/mh_z19b.py”, line 130, in init
self.initialize_input()
File “/home/gg/Mycodo/mycodo/inputs/mh_z19b.py”, line 151, in initialize_input
self.abcoff()
File “/home/gg/Mycodo/mycodo/inputs/mh_z19b.py”, line 199, in abcoff
self.ser.write(bytearray([0xff, 0x01, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86]))
File “/var/mycodo-root/env/lib/python3.9/site-packages/serial/serialposix.py”, line 636, in write
raise SerialTimeoutException(‘Write timeout’)
serial.serialutil.SerialTimeoutException: Write timeout
2022-06-16 12:58:45,146 - INFO - mycodo.controllers.controller_input_ea4c154a - Activated in 6320.0 ms
2022-06-16 12:58:45,148 - ERROR - mycodo.controllers.controller_input_ea4c154a - Mycodo is attempting to acquire measurement(s) from an Input that has already critically errored. Review the log lines following Input Activation to investigate why this happened.
2022-06-16 12:58:55,012 - ERROR - mycodo.controllers.controller_input_ea4c154a - Mycodo is attempting to acquire measurement(s) from an Input that has already critically errored. Review the log lines following Input Activation to investigate why this happened.
2022-06-16 12:59:09,967 - ERROR - mycodo.controllers.controller_input_ea4c154a - Mycodo is attempting to acquire measurement(s) from an Input that has already critically errored. Review the log lines following Input Activation to investigate why this happened.
2022-06-16 12:59:25,028 - ERROR - mycodo.controllers.controller_input_ea4c154a - Mycodo is attempting to acquire measurement(s) from an Input that has already critically errored. Review the log lines following Input Activation to investigate why this happened.

The MH-Z19B is connected directly to the Pi as follows:

Red (VIN) connected to 5V on Pi
Black (GND) connected to GND on Pi
Blue (RX) connected to TXD on Pi
Green (TX) connected to RXD on Pi

From what I could gather from a different post (MH-Z19B Wiring Sanity Check), because I’m connecting the sensor directly to 5V it’s not supposed to show as UART? And if so how do I change that?

Hi, What model Raspberry Pi are you using? If its the Pi 3, I found this the other day.

The Raspberry Pi Foundation has failed to make a working
UART on the Pi 3. Because of this no UART connected devices
can run on a Raspberry Pi 3.

I’m running the Pi Zero W

This is now sorted after disabling Bluetooth and ensuring that “enable_uart=1” is set in /boot/config.txt

After I disabled Bluetooth, the interface /dev/ttyS0 or /dev/serial0, showed up.

I set the input on MH-Z19B to use /dev/ttyS0 as per: Mushroom Cultivation Automation: From Foraging to Fruiting – Projects | Kyle Gabriel and boom it started picking up readings.

References
Similar issue: MH-Z19B Reading problem - #11 by KyleGabriel & MH-Z19B: CO2 Sensor Error · Issue #1162 · kizniche/Mycodo · GitHub
How to disable Bluetooth: Tips - Disabling Bluetooth on Raspberry Pi
Mycodo manual: https://kizniche.github.io/Mycodo/mycodo-manual.pdf#Interfaces/

2 Likes