-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange readings #11
Comments
The strange numbers seem to indicate that some bits are not read correctly. 12 equls 8+4 so 2 bits. |
The fact that all diagrams don't show a pull up can be caused by the fact that they use short wires?
|
sorry.. I do not have an o-scope since the university has closed
this was not documentation, it was a reply a user left on a purchase.
The tutorials (plural) that are on their site all show them using the same cable that is shipped with it.
That DHT 22 is not on a PCB and is instead just the raw sensor and yes the raw sensor very much does require a pull up between VCC and data, but the DFrobot version is the raw sensor mounted to a PCB and the PCB has a 10k pull-up between VCC and data just as shown in that example.
Isn't it also supposes to through a crazy number at you (-999 if I remember) when it gets an error and we have none of those?
that library is just a fork of the Arduino-DHT library so I didn't think it would be any different, I also wanted to use yours lol. However, It does say
he is specifically talking about the dht22 so this might actually be legit |
Thanks for your replies
Add this line before DHT.read()
With my next purchase-round I'm going to add a number of ESP32 so I can do more testing. |
so I powered up the project again to see if it would reoccur and sure enough, it did. However, I have found something interesting. When I press the reboot button my readings stay stable for quite some time before doing it ~8 passes. If I unplug the sensor and plug it back in I get 1-3 good passes then it rapidly drops to -12 after 2-5 passes it bumps to 12 and after another 2-5 int recovers. What could this mean??? |
Further analysis In the software to read the DHT sensors the timing is the most critical part. For the much faster ESP32 (compared to UNO) this timing should not be a problem however the "multitasking" behavior of the ESP has been mentioned as a possible cause in this and other timing issues. However differences in hardware including differences in quality of the sensors (including fake and cheap clones) have caused many problems in the past too. In this analysis I will prove the cause is not in the software but in the hardware, and that a work around can possibly be made in software. Humidity Temperature
reversing these lines of code gives us
Notice : the Most Significant Bit has shifted 1 place to the left. cause negative sign cause high humidity AS far as I can see all wrong readings have a humidity of 100. So we might assume that when shift happens, we always shift in a HIGH bit. Where does that come from and WHY? Cause of the shift
As we get an extra HIGH bit we must conclude the time is larger than 40 us. The number 40 is based upon the specs in the datasheet of the DHT sensors:
40 us is 42% larger than the 28us So for some reason the data pin stays HIGH too long (sometimes), or has difficulties to become LOW fast enough. An detailed analysis of the hardware is mandatory to find the cause. CONCLUSION A possible solution to work around this incorrect behavior is to adjust the timing threshold value in the software, in concreto the value in line 176 from 40 to 50. Please test if this proposal solves the issue |
You are amazing... You literally broke it down and explained it so well. How do I buy you a coffee??? Anyways, I was on board with the idea that it was a hardware issue not explicitly software related. I modified the
I will keep you informed on the status of the next 24 hours. Might I suggest that if it does not falter again meaning this minuscule increase in time was able to eliminate the problem, you should make this an update to prevent future people from suffering as I (briefly) did? Thank you for all the time you have put into your responses - Hale |
Thanks for the compliments, No wizard otherwise I would focus on other things than software. I still think it is a hardware issue somehow as the timing is out of specification. I will prepare a PR with the adjusted threshold and wait for the results of your 24h test. |
dang it...
that's with 50... The lower numbers are bc its colder inside today.
and that's with 60....
I tried 30 just for fun and got this ^^^ |
It's so weird tho... after reverting back to 40, It gives those dips then recovers and never does it again... |
So 40 behaves pretty good in long run, 50 is slightly better at start. 60 same. 30 is definitely too short as it adds 1 bits (numbers are larger). It seems that the processor in the sensor got locked somehow in the end. Resetting the sensor helps. This could be done under program control by switching the powerline by means of a mosfet, |
no, everything was the same temperature as the box ~23°C. so all I'm needing is an internal temp and humidity sensor so we can monitor the temp to see if it gets cooked in the sun and to know if water is getting in (humidity will spike). I'm concluding these are duds so if you have any hardware change suggestions I'm up for some modding. Or do you have any suggestions on what to buy? |
I'll come back to it later. |
ALTERNATIVE SENSOR Accuracy is better than DHT22 although resolution is approx. same. It has a build in heater to evaporate any condensation (e.g. if humidity goes very high) but you need to use that with care, my library supports this heater function and has some hooks to check the timing of the heater There are three known sensors with slightly different accuracy etc. Check the datasheet Adafruit has a breakout version of the SHT31 - https://www.adafruit.com/product/2857 DHT22 One option is (again a workaround) is to power up and down the sensor from the ESP, this will cost you an extra pin and minimal code (pin HIGH wait 2 seconds, read sensor pin LOW). This will work quite well and in fact it is used in systems that are battery powered to safe energy. |
This question is still not answered: That gives more information where in the protocol the handshake fails. |
The long run usage of DHT22 really depends on the individual sensor. If price is no issue => give the SHT31 a try (try it anyway to get some experience / reference) |
Studied the datasheet again, and I see this phrase "Data-bus's free status is high voltage level." but it is not specified if the host or the sensor should keep the data line HIGH . A quick look in two alternative libraries shows none pulls the line up after the sensor is read. To test if this causes the long term failure you can add 2 lines to DHT._read() at the start (around line 86) int DHTNEW::_read()
{
// READ VALUES
if (_disableIRQ) noInterrupts();
int rv = _readSensor();
if (_disableIRQ) interrupts();
// put databus in HIGH state between reads.
pinMode(_pin, OUTPUT); <<<<<<<< add line
digitalWrite(_pin, HIGH); <<<<<<<< add line
_lastRead = millis(); Can you give this a try with a long run? |
FYI |
I think I will try the sht31, I would like to buy form DFrobot as that's where I get all my parts for this project, I just hope it actually works... I would appreciate it if you visited their site and glanced over it to see if it looks compatible and decent. Also, that is quite a large increase in pins going from one to three where I have almost all of my pins populated. Are all of the pins necessary? Or is there any other sensor that is a 1 pin? Of course this is just me being nitpicky As for the checking what the error is, what code would you like me to insert together this error code? I would gladly do some error testing for you. also with your comment saying the no breadboard version should I just desolder it from the breadboard and try it raw like you did and put my own pull up resistor and everything to see if that fixes it. Maybe it's just their combination of capacitor and resistor. |
DFRobotics makes quite good stuff normally and the price is a bit better than Adafruits. Because I2C is a bus other devices may use the same I2C pins (e.g. LCD or OLED display, FRAM EEPROM etc) |
void getDHT(){
for (int i = 0 ; i < DHTReadings; i++) {
int status = DHT.read(); // Gets a reading from the DHT sensor
Serial.println(status); |
Than I would just order a plain sensor. Your breadboard version works well way too often I would say. |
Shure you can, the idea is good to do that test but I would buy a new sensor. And then compare the results. |
Started
|
This is what I meant by it appears that I am right. My suspicion was that the esp32 is causing it. |
I cannot prove it is the ESP32, as the DHT11 test you did work for more than 7 days. |
Disabling the interrupts did not solve the DHT22 reading failures
Burst duration: 8.38 same range
Time to bursts 17759 * 2000 = 35.518.000 millis Conclusion |
I did not do a full 7 days (slight exaggeration...) I got through about 4 1/2 I think and then I rebooted it because I had to do some maintenance so if you were saying the error should have occurred on the 6th day, I never got there. I will have one up and running for 7 days though once I get all of my problems sorted out.
it only seems to happen when using an esp32 with the dht22 so if we try more boards such as an 8266 an Uno a mega a nano and if none of them give problems but the 32 then there has to be a conclusion that the 32 is causing the error. right? (Even if we don't explicitly know why) |
Analyzing the bug takes already a lot of my time and I will not test other boards as these will not give me information as far as I can see. From my head I have never seen the error in combination with the MEGA and NANO, that is no proof for this version of the lib etc. You are not right, you mix up correlation and causation. If we see the problem only occurring in the combination of DHT22 and ESP32 we cannot conclude which one causes it. We only see the correlation. (that is the point we are now) Most important step to make is a way to trigger the error explicitly at any time. |
Bit of searching and reading found back the 8266 discussion
from that thread
ADAfruit DHT22
Checked latest ADAfruit library - https://github.com/adafruit/DHT-sensor-library/blob/master/DHT.cpp
I will add the timing/ interrupt related points [1..4] and do a 24 hr test run when time permits... |
Results of test with interrupts disabled. As predicted the failure burst came at 16:20
Burst duration: 6:30 lowest so far but same order of magnitude
Interval since previous burst 40189 - 17958 = 22231 * 2000 = 44.462.000 Conclusions
Time for next test with patches mentioned above |
So I'm using an esp32 with a cellular modem on it and I use this cellular modem to send my data to my web server but I do not use the Wi-Fi on it at all. I'm curious if I still need to disable Wi-Fi because as soon as the chip boots up it turns the Wi-Fi modem on, you just don't use it so it's a low-power mode. Same goes for the Bluetooth module, I wonder if that needs disabled as well. |
Test with extended timing + extra yield() call ran for 12 hours and ZERO failures so far. So it looks like disabling wifi / bluetooth is not needed. |
That's promising! What exactly did you change? Just added 1 and 4? Can you post a snippet. |
@Mr-HaleYa https://github.com/RobTillaart/DHTNew/tree/test_timing I want to understand which timing changes did the trick, or was it the call to yield()? The other changes I will revert as I want to keep implementation in line with the datasheet as much as possible. |
@RobTillaart |
I need more coffee in the morning, sorry. Fixed. (now I only need to fix a coffee) |
pushed 0.3.0 alpha in test_timing, Current test runs now 22:30 so that is 10:00 + 12:25 hrs so normally second burst would be about now. Good to see zero fails so far. |
Zero failures in 23:30; so starting test now with 0.3.0 alpha. update: 9300+ reads OK |
0.3.0 alpha - ran for 13:00 hrs
next steps
|
So you think you figured it out then? 😃 |
Not understood in all details, but I think I'm closing in. This is my current hypothesis. Observations
Hypothesis Solution 0.3.0
|
so basically it does what it wants when it wants lol. sometimes quick readings and replies other times its to slow and doesn't fully respond before the read req is over |
Yes it is alive :) |
Issue closed as issue is fixed. Please reopen if these burst of failed reads occur again. |
@RobTillaart Wow, amazing work! I really don't know what I will do with my mornings now that this is closed 😭 I really enjoyed reading your in-depth explanations lol 😄 Well I hope the issue never arises again as that was (at the least) inconvenient, It is good that it was fixed tho. I wish you the best of luck on all your other projects and thank you again for the amazing work you have done here. |
@Mr-HaleYa Are you going back to the DHT22 now in your project? Or do you keep the DHT11. |
Well if you say it works then I see no reason not to use the DHT22 🙂 I have 5 so I will switch out some of the DHT11's in my projects and see if I get any errors 😆 |
In my tests it looks stable so please give it a try, But you know that the fact that you see no bug is no proof there is none 😊 Success! |
I am using
esp32 ttgo sim 800l (https://rb.gy/ogywnq)
Dfrobot dht22 (https://www.dfrobot.com/product-1102.html)
my code
DHTNEW DHT(18);
DHT.setWaitForReading(true);
So my problem is that even tho I use a filtering algorithm to get rid of highs and lows by taking 7 readings then choosing a median I will occasionally get some massive dips in temperature (and spikes in humidity as a result). my temperature in my room stays about 24°C and the dips are -12 and 12 °C so half the temp and half * -1. I have no clue why it is doing this... It runs every ~2 mins and when the bad readings start it does it consistently for a few runs before correcting itself.
Nothing moves nothing is touched nothing changes... It just goes wack... Could it be a library error? I don't see how it could be but you're a smart man @RobTillaart so you may see something I'm missing. I have also thought of the potential that its a dud sensor. I hope not bc i ordered 20 more before testing the one I'm using. I had the thought that maybe adding more reading (like 15 instead of 7) so there is more to data to filter but it looks like all the readings it's taking in those fault zones are bad...
Would appreciate any suggestion - Regards Hale
The text was updated successfully, but these errors were encountered: