Is this garbage only occuring during the first exchange or for every other ones?
If it is only on the first one, it is surely a problem linked to the setup of the sensor. In that case, maybe you can add a few seconds delay before entering the flush loop I suggested. The delay shall be longer than the time it takes for the sensor to make its internal calibration and end its setup.
Problem with UART reading (MH-Z19B sensor)
Re: Problem with UART reading (MH-Z19B sensor)
The garbage comes with each reading no matter how long I waited. Really strange.fdufnews wrote: ↑Mon May 24, 2021 7:44 amIs this garbage only occuring during the first exchange or for every other ones?
If it is only on the first one, it is surely a problem linked to the setup of the sensor. In that case, maybe you can add a few seconds delay before entering the flush loop I suggested. The delay shall be longer than the time it takes for the sensor to make its internal calibration and end its setup.
Re: Problem with UART reading (MH-Z19B sensor)
If I look at your screen copies, the garbage comes at the first read, causing an offset of 3 bytes. That offset continues through the following reads of 9 bytes each and results in bad results. Again: every time before sending out a command to the sensor you have to ensure that nothing is already in the receive buffer.
Re: Problem with UART reading (MH-Z19B sensor)
Thanks again for your advice, Robert!Roberthh wrote: ↑Mon May 24, 2021 6:57 pmIf I look at your screen copies, the garbage comes at the first read, causing an offset of 3 bytes. That offset continues through the following reads of 9 bytes each and results in bad results. Again: every time before sending out a command to the sensor you have to ensure that nothing is already in the receive buffer.
I connected the sensor now to Arduino. Quite interesting, there is no such problem, the reading for the first two minutes shows zero, after correct value was displayed.