pstolarz / OneWireNg

Arduino 1-wire service library. OneWire compatible. Dallas thermometers support.
BSD 2-Clause "Simplified" License
89 stars 20 forks source link

Issues with DS18B20 #44

Closed indymx closed 2 years ago

indymx commented 2 years ago

I'm having an issue where after a random amount of time the DS18B20 will stop sending valid data. I don't have any good debug showing what data is being sent or if any when the issue starts, but I do have my script go into a failure loop when it see's a 0 for temp on the sensor.

It usually requires a complete power cycle of the ESP32 to get it to read again. Is there a way to force the sensor to reset ?

pstolarz commented 2 years ago
indymx commented 2 years ago

only on OneWireNG, as that's the only lib that I have found that works with ESP32-S2 and DS18B20.

I believe I'm using .10

I'm including the following in my sketch:

include

include <drivers/DSTherm.h>

include <utils/Placeholder.h>

Could be cheap china sensors. I'm going to take one apart tonight to see what exactly is in there..

I have the following in my "failure" loop:

    while (tmpread <= 0)
    {
      getTemp();
      debugln("checking sensor... ");
      delay(500);
      TelnetStream.println("Sensor Failed. Checking");
      delay(500);
      debugln("Toggle pin state");
      digitalWrite(OW_PIN, LOW);
      delay(500);
      digitalWrite(OW_PIN, HIGH);
    }; 

    does not help... 

    https://github.com/indymx/TpLink-Arduino/blob/main/TpLink-Arduino_TempControl.ino
pstolarz commented 2 years ago

I need to know exact version. There is a problem with 0.10.2 on ESP32. Use 0.10.3 or 0.11.0 (preferred). Check with the DallasTemperature example if the problem occurs.

indymx commented 2 years ago

Just checked, I'm showing 0.10.3 in the library.properties file.

I'll update to 0.11 tonight when I get home to see if that helps.

pstolarz commented 2 years ago

I run the DallasTemperature example on my ESP32-S2 setup for about 1 hour and didn't get any single error for temp. reading.

indymx commented 2 years ago

This time it ran for about 7 hours before it stopped working.

On Thu, Apr 7, 2022 at 2:54 PM Piotr Stolarz @.***> wrote:

I run the DallasTemperature example on my ESP32-S2 setup for about 1 hour and didn't get any single error for temp. reading.

— Reply to this email directly, view it on GitHub https://github.com/pstolarz/OneWireNg/issues/44#issuecomment-1092092215, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGXRTNP2Q34W2JDNNX2SODVD4VOFANCNFSM5SYYNDQQ . You are receiving this because you authored the thread.Message ID: @.***>

indymx commented 2 years ago

It seems that authentic Dallas / Maxim Integrated sensors are impossible to get right now. Hopefully the ones I just got on Ebay are real..

pstolarz commented 2 years ago

You may consider push-pull circuit controlled by dedicated GPIO which will reset the DS18B20 (shorts its VDD pin to GND) in case of such deadlock.

https://open4tech.com/open-drain-output-vs-push-pull-output/

pstolarz commented 2 years ago

https://github.com/cpetrich/counterfeit_DS18B20

indymx commented 2 years ago

I will have to do some research on the push/pull. I read that link, I understand the concept, but need to see exactly how to implement that..

Second link is awesome. Thanks for sharing. That will definitely come in handy.

indymx commented 2 years ago

Well, it appears that I am dealing with Family C clones. 28-FF-64-1E-08-75-19-06: Family C (Clone).

Since it's near impossible to get genuine sensors right now, do you have any suggestions beyond the push/pull circuit?

pstolarz commented 2 years ago

The circuit is very simple and consists of 2 MOSFETS (P and N)

Work mode

pp-on

GPIO is set to low (GND), therefe Q1 is conducting Q2 is not. DS18B20's VDD pin is provided with voltage.

Reset mode

pp-off

GPIO is set to High (Vcc), therefe Q1 is not conducting and VDD is shorted to GND via Q2. DS18B20 is not powered in this case (reset state).

The question is if it's really a problem with DS18B20 and it's reset will solve your issue.

pstolarz commented 2 years ago

If you would like to experiment with this circuit I recommend this simulator: https://www.falstad.com/circuit

The above circuit is described by:

$ 1 0.000005 12.050203812241895 50 5 50
f 336 176 384 176 33 1.5 0.02
f 336 272 384 272 32 1.5 0.02
w 336 224 336 272 0
w 256 224 336 224 0
w 384 160 384 128 0
w 384 288 384 320 0
g 384 336 384 352 0
R 384 128 384 80 0 0 40 5 0 0 0.5
w 384 192 384 224 0
S 256 224 224 224 0 0 false 0 2
w 336 224 336 176 0
w 384 336 384 320 0
w 384 224 480 224 0
w 384 256 384 224 0
R 224 208 224 160 0 0 40 5 0 0 0.5
g 224 240 224 272 0
x 178 227 208 230 4 12 GPIO
x 396 275 412 278 4 12 Q2
x 403 183 419 186 4 12 Q1
x 476 211 501 214 4 12 VDD
pstolarz commented 2 years ago

At first try you may to use GPIO (in the output mode) connected directly do DS18B20's VDD pin to power it. In working mode GPIO is high, for reset low. Maybe it will be sufficient for your case and you dont need to bother with push-pull circuit. But in this case you must be sure the GPIO output type is not open-drain, since this type of output is not able to provide voltage source to VDD.

indymx commented 2 years ago

I'm not finding anything in the datasheets that explicitly says whether or not it's open-drain.

I'm using an Adafruit ESP32S2 TFT. The ESP32-S2 datasheet has this: (but that's the only reference I can find)

image

It's also possible that I'm in way over my head on this..

pstolarz commented 2 years ago

Connect DS18B20 as follows: temp

digitalWrite(GPIO_VDD, 0); ow.setBus(0); delay(1000);

NOTE: `OneWireNg_BitBang::setBus()` method is protected so you need to move this method from protected to public in `OneWireNg_BitBang.h` file

* Back to life after reset. `GPIO_VDD` to high. `GPIO_DQ` set to high impedance (as input):
```cpp
auto& ow = (OneWireNg_CurrentPlatform&)_ow;

ow.setBus(1);
digitalWrite(GPIO_VDD, 1);