dht22

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
AnMo_4196841
Level 3
Level 3
First like received First like given

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?

0 Likes
1 Solution

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

Thanks and Regards,
Rakshith M B

View solution in original post

0 Likes
12 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

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

0 Likes
lock attach
Attachments are accessible only for community members.

Here you have the project.

0 Likes

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,

pastedImage_14.png

r99 label is executed -

pastedImage_15.png

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

Thanks and Regards,
Rakshith M B
0 Likes

Hi,

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

Thanks

0 Likes

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);

pastedImage_0.png

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

Thanks and Regards,
Rakshith M B
0 Likes

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.

0 Likes

Hi AnMo_4196841,

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

This is what I found -

pastedImage_0.png

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

pastedImage_1.png

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).

pastedImage_2.png

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 -

pastedImage_3.png

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 -

pastedImage_4.png

Hope this helps,

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes

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.

0 Likes

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) -

pastedImage_2.png

Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes

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

0 Likes
AnMo_4196841
Level 3
Level 3
First like received First like given

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.

0 Likes

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

Thanks and Regards,
Rakshith M B
0 Likes