12 Replies Latest reply on Jan 23, 2020 4:16 AM by RakshithM_16

    dht22

    AnMo_4196841

      Hi everyone, I have done a project with PSoC 4200 and sensor DHT22. The problem is that when I show the temperature o humidity data on a screen, two values for each one are shown to me (the real value and 9), both with temperature and humidity happen the same thing. I attached pictures.

       

      Can anybody help me?

        • 1. Re: dht22
          rola_264706

          Please post your project so we can determine what the issue is.

          • 2. Re: dht22
            AnMo_4196841

            Here you have the project.

            • 3. Re: dht22
              RakshithM_16

              Hi AnMo_4196841,

               

              I went through your project and the project is quite similar to the one that I had. I just want to mention that the way the humidity and temperature is calculated is very interesting

               

              To answer your question, whenever the communication timeout occurs i.e., when timeout is greater than 500,

              r99 label is executed -

              This sets the value 99 to both humidity and temperature. The LCD prints this value divided by 10.

              Therefore, 9 (99/10) is displayed on the LCD.

               

              Hope this helps,

               

              Thanks and Regards,

              Rakshith M B

              • 4. Re: dht22
                AnMo_4196841

                Hi,

                 

                you are right but how can I solve this so that it doesn't show me?

                 

                Thanks

                • 5. Re: dht22
                  RakshithM_16

                  Hi AnMo_4196841,

                   

                  Can you let me know how often you are getting this timeout error?

                   

                  The timeout is before the sensor starts sharing the data and as far as I know the logic implemented is correct.

                   

                  Can you try these steps and see if this resolves your issue?

                   

                  1. Can you add the following lines before line 64 -

                                           DHT_Write(1u);

                                           CyDelay(500);

                  2. Change the delay in line 68 from 19 to 18 miliseconds and see if this helps.

                  3. You can also enter Debug mode, put a break point at line 147 - humidity = 99; and check at what point exactly the timeout occurs.

                  4. Another debug method is to probe the data line with any logic analyzer and check what is causing the timeout.

                   

                  Thanks and Regards,

                  Rakshith M B

                   

                  • 6. Re: dht22
                    AnMo_4196841

                    Hi,

                     

                    The problem has not been solved with your instructions. I cannot do the debugging because the bluetooth cannot be connected while it is being performed and therefore does not enter the condition of the connected device and notification.

                    My idea in this project is that the sensor continuously reads values but only sends the value through the ble when it is different and how it takes the "9" because the value continuously changes between 9 and the real value.

                    • 7. Re: dht22
                      RakshithM_16

                      Hi AnMo_4196841,

                       

                      I probed the data line using a logic analyzer and I was debugging your program.

                      This is what I found -

                      So the program fails (writes 99 to variables) at the last START sequence -

                      We can see that the sensor does not acknowledge the START sequence which is why the program fails. Another interesting thing is that the delay between any 2 successful communication (here - 2.5 seconds) is much greater than the delay between a successful communication and the failed communication (here - 0.5 seconds).

                      In the code a START sequence is sent to the sensor, the value is compared with the previous value and if it is not equal then the values are printed. If the values are equal then the DHTread() function is called again -

                      So there is no delay between the 2 function calls. You can add a 1 second delay before each of the DHTread() return statement to resolve this issue. I did the same and I was able to get correct readings.

                       

                      Adding to this I found this information in the datasheet -

                      Hope this helps,

                       

                      Thanks and Regards,

                      Rakshith M B

                      • 8. Re: dht22
                        AnMo_4196841

                        Hi,

                         

                        I tried what you told me to put 1 second before DHTread () calls (attached photo).

                        I have included it in the case of the 3 inequalities (humidity == humidityant, temperature == temperatureant and proximity == proximityant). Doing this keeps measuring me the "9". I have also put it in the DHTread () of line 185 and in this way it does not let me connect to the device.

                        Exactly what have you changed?

                        Greetings and thank you.

                        • 9. Re: dht22
                          RakshithM_16

                          Hi AnMo_4196841,

                           

                          I am sorry but I am not able to find any attached photo.

                          I added CyDelay(1000); before the return 0; statement in DHTread() function as shown (line number 152) -

                           

                          Regards,

                          Rakshith M B

                          • 10. Re: dht22
                            AnMo_4196841

                            Hi RakshithM_16

                             

                            It doesn't let me increase that delay more than 300 milliseconds, if I put a higher amount, it doesn't let me establish the connection

                            • 11. Re: dht22
                              AnMo_4196841

                              Hi everyone,

                               

                              The solution has been to put a delay of 1 second after the call to the DHTread () function that are within the if (humidity == humidityant),

                              (temperature == temperatureant) and (proximity == proximityant).

                               

                              Thanks for your help.

                              • 12. Re: dht22
                                RakshithM_16

                                Hi RakshithM_16,

                                 

                                Adding to the solution, the reason why giving the delay in the DHTread() function was causing BLE connection issues is the BLE events need to be processed regularly.
                                There is a delay of 1 second in line 262. So giving a delay of another 1 second in the DHTread() function will force the system to wait for 2 seconds and BLE events will not be processed during that interval.

                                 

                                There are 2 things that would optimize the solution. The first being to process the events more regularly and in the DHTread() function. Call CyBle_ProcessEvents in regular intervals, this function must be called for atleast once every connection interval or advertisement interval, whichever is smaller.  If any custom function is consuming more time for execution, please call CyBle_ProcessEvents() inside it.

                                 

                                Second, when the temperature and humidity values are same there is actually no need to call the DHTread() function again. DHTread() is called at the beginning of the for loop and the sensor value between the 2 function calls will not change as the time difference between these two function calls are very less.

                                 

                                Anyway, glad your issue got resolved

                                 

                                Regards,

                                Rakshith M B