[Solved] MH-Z19B C02 sensors with UART-to-USB adapters
The one thing to check for when you see sensors misbehave is the power rail used. Things like mechanical relays present an inductive load - and if they are missing a clamping diode on the coil - they will surely trash up the power rails. If this is on USB devices only - you can perhaps isolate the problem with a powered USB hub. See if that stabilizes the issue. Once you get past a few low current sensors - you can really stress the Pi power supply - look for the red LED flashing if it detects a problem. The Pi3 and Pi4 really need a stiff 5.1v to properly regulate the 5v rail.
Have you disconnected all hardware except for each sensor in order to isolate if there are any hardware conflicts occurring? If each piece of hardware works fine when only it is connected, it would indicate the issue lies with the combination of hardware you have when connected together.
@kylegabriel it appears that when I have only one MH-Z19B connected, it runs without issues.
@carboncycle Here's a link to the USB adapters I am using to connect to my MH-Z19B's: https://www.amazon.com/gp/product/B07D9R5JFK/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&psc=1
It's only my USB devices that are acting up (sensors connected via the Pi's pins work fine) so I will look into a powered USB hub.
I think I see the problem. The device you reference is not CP2102. That cable uses a PL2303TA and is not programmable for a unique serial number, if I'm not mistaken. They may have some utility on their support site to modify them in some way to be unique.
They have a warning about counterfeits of their devices on the product page.
@carboncycle I don't think that's the issue, since I am identifying the serial devices using "by-path" (ex. "/dev/serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0") and just remembering not to change which USB ports they are plugged into. FWIW, I was previously using a different USB adapter (link below) but switched up after I seemed to keep running into issues.
Check the output of 'dmesg' after something odd happens. The driver registers there and should report any reconfig. Those new adapters should be programmable, but I haven't tested that specific module. I've found sourcing the usb modules to be sometimes problematic. I have 20 modules that would need rework to be usable, and that isn't cost effective. I just find a different vendor and module source.
I've been testing three modules at a time, using an un-powered hub. The modules pull ~100ma when taking a sample. I use the Mycodo 8.6.4 code to calibrate the devices.
@carboncycle Attached here is a screenshot of output from dmesg when one of the sensors isn't working. Those last 4 lines seem relevant but I'm not sure what they mean.
I tried attaching my MH-Z19B's to the Pi using a USB hub (connected to a separate power source). Still, it seems that I can't connect all three MH-Z19B's without one of them failing within a few hours, sometimes much sooner.
That is from the pl2303 USB driver.
This is a pointer to the source code ( for reference )
This problem has been documented on the interwebs:
I've actively avoided using this particular chip - I've had good results with FTDI and SiliconLabs parts.
Here is more information on Pi USB port specifics and troubleshooting: