RobTillaart / DHTNew

Arduino library for DHT11 and DHT22 with automatic sensor recognition
MIT License
96 stars 15 forks source link

Si7021 by Sonoff #79

Closed phiguimaran closed 1 year ago

phiguimaran commented 1 year ago

Hi, I'm usinng your library in various proyects, it's great !! I'm trying to use it with the sensor that's came with Sonoff TH. It's a board that include Si7021 sensor and some circuits to comunicate with 1 wire. To make this work I have to change the wakeup delay to a value near 500 microseconds If I coment lines : do { // HANDLE PENDING IRQ yield(); // 180 gives good wakeup delay on UNO for DHT22 / DHT11 (issue #72) delayMicroseconds(180UL); } while((micros() - startWakeup) < (_wakeupDelay * 1100UL)); and change for delayMicroseconds(500UL); its work well.

I wonder if there is a way to configure this without having to edit the library?

Thanks in advance

RobTillaart commented 1 year ago

Thanks for the issue. I will investigate later today.

RobTillaart commented 1 year ago

I created a develop branch in which I will introduce a new type 70 besides the 11 and the 22 later today. Lets get started!

RobTillaart commented 1 year ago

@phiguimaran Pushed initial version of experimental Si7021 support. (not tested as I have no such sensor)

I added the SI7021 to the auto detect part in read().

Please download the develop branch and test if this sensor detection works. You need to add Serial.println(sensor.getType()) after the read() function.

If detection does not work:

phiguimaran commented 1 year ago

Good morning, and thanks for the fast update. I tested and the type autodetection works well. The problem is the total delay now is 720 (because 180x3 < 550 so the next iteration add 180 micros more) With 720 this sensor doesent work. Let me test delay min and max that makes the sensor works well and see if it can be a 180 multiple I'll tell you the results in a bit

RobTillaart commented 1 year ago

Good afternoon (15:30 here) I can patch those numbers relative easily, only thing is that delayMicroseconds() uses a multiple of 4 on AVR. Can reduce to 40 instead of 180.

phiguimaran commented 1 year ago

Perfecto I need a time for test and determine a stable wakeupdelay multiple of 40 I write you later

phiguimaran commented 1 year ago

Well, I make a lot of test and de only way I can use the Sonoff Si7020 stably is the next: line 71: #define DHTLIB_SI7021_WAKEUP (500UL) line 233: if ((_type == 22) || (_type == 70)) // DHT22, DHT33, DHT44, compatible line 360: if (_type==70){ delayMicroseconds(500); } else { original loop }

This board is extremely sensitive about wekeup time.

RobTillaart commented 1 year ago

Thanks for your extensive testing, I will fix in the library as you proposed. Will be done within 15 minutes.

Need to order such sensor myself to do more testing.

RobTillaart commented 1 year ago

Branch pushed, build is running (just able to fix and run a test in time :)

RobTillaart commented 1 year ago

@phiguimaran I've updated the code to your proposal - used the #define DHTLIB_SI7021_WAKEUP

Other changes do not affect the code

Unless there are problems I will merge later today.

RobTillaart commented 1 year ago

@phiguimaran Merged develop branch into master, feel free to reopen this issue if needed.

RobTillaart commented 1 year ago

@phiguimaran FYI https://github.com/RobTillaart/DHTNew/issues/81

phiguimaran commented 1 year ago

Hi Rob, I was away for the weekend. You made the changes very quickly :-) I can't test it today but y see line #183 if (_type == 22) // DHT22, DHT33, DHT44, compatible should be if ((_type == 22) || (_type == 70)) // DHT22, DHT33, DHT44, compatible

otherwise we get wrong readings

best regards

RobTillaart commented 1 year ago

From - https://github.com/RobTillaart/DHTNew/issues/81

A DHT22 got recognized as a type 70 and still got good data.

Need to look at the code to see if I understand what is happening.

RobTillaart commented 1 year ago

Yes, understand the issue. I will create a new develop branch.

(exactly the reason why testing is so important).

RobTillaart commented 1 year ago

TOPIC is continued in #84