UPDATE 20.01.2020: I added crc_errors and range_errors to the MHZ19_AS.py class and in this video https://youtu.be/wdhZWGnmWlU I demonstrate the problem:Divergentti wrote: ↑Tue Jan 19, 2021 9:38 pmThank you for heads up.marcidy wrote: ↑Tue Jan 19, 2021 7:15 pmThat looks like noise, \xff\x86\x01 is there in both cases. Leading \x00 can be that the connected device isn't powered up yet, pulling down the lines and triggering a phantom transfer.
Code: Select all
Do you have external pull-ups? Can you (electrically) enable the sensors after initializing the UART? This probably not a code / micropython issue but an electrical issue. If you can't do anything else, you can read bytes in a loop till you get \xff on initialization.
It's good to have sensible hardware defaults via pull-ups, and control the start-up and initialization of connected devices whenever possible. If you have access to the pins, you might want to add some external pull-ups to RX and TX.
It indeed looks like a noise and perhaps I shall add error frame counter to the MHZ19_AS.py class. If checksum from UART bytearray is wrong, counter increases. Noise is possible, because chip is SMD chip in the programming board and I use dupont connectors, which are bad. I am not using pullups, because I understood ESP32 has pullups as default and if I would like to use open drain GPIO, I have to turn them off? At least I have done so for circuits which are "grounding" through GPIO pin.
But then the but: this problem can be repeated without any changes to the hardware (= noise theory do not apply). With deletion of the sensor object everything works robust without errors (tested over night), but if I do not delete the sensor object as in the code I do, nothing works after power on boot, but works fine with soft boot.
- UART2 re-creation is disabled in the main.py code
- first boot is soft boot and as you see, everything works fine
- second boot is power on boot and you see that UART2 (= MHZ19_AS.py) related crc_errors start increasing each reading cycle and no CO2 values are read.
I hope this helps to find root cause for this problem.