Qengineering / DHT22-Raspberry-Pi

DHT22 sensor on Raspberry Pi with WiringPi
https://qengineering.eu/opencv-c-examples-on-raspberry-pi.html
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

prog delivers confused/zero values inbetween #2

Open woodz- opened 4 months ago

woodz- commented 4 months ago

When compiling and running your program with g++

$ g++ ./src/main.cpp ./src/DHT22.cpp -I./include -lwiringPi -o dht22

$ ./dht22

the output looks like

Temp : 12.00 °C,  Humidity : 99.90 %                                                            
Temp :  0.00 °C,  Humidity :  0.00 %                                                            
Temp : 12.00 °C,  Humidity : 99.90 %                                                            
Temp : 24.00 °C,  Humidity : 199.80 %                                                           
Temp :  0.00 °C,  Humidity :  0.00 %                                                            
Temp :  0.00 °C,  Humidity :  0.00 %                                                            
Temp :  0.00 °C,  Humidity :  0.00 %                                                            
Temp : 12.00 °C,  Humidity : 99.90 %                                                            
Temp : 12.00 °C,  Humidity : 99.90 %                                                            
Temp : 12.10 °C,  Humidity : 99.90 %                                                            
Temp : 12.10 °C,  Humidity : 99.90 %                                                            
Temp : 24.20 °C,  Humidity : 199.80 %

Note I've been reformatting the output a bit and changing the loop delay to 5000ms inmain.cpp.

We can see zero values and sporadic doubled temperature values and +100 humidity values.

Why is that?

Qengineering commented 4 months ago

The cause is simple, your timing jitters. The cure is difficult.

The code is more or less a foundation on which to build further. For example, no threading is used. In practice, all processes run simultaneously parallel to the DHT22 code and can influence the timing. As can be found in the documentation, timing needs to be quite precise.

You can address the issue from two sides.