Page 1 of 3

DS18B20 not reading every time

Posted: Fri Mar 04, 2022 11:37 am
by jollybv
Hi Guys

Im having a bit of a problem with the DS18B20 what i have is The node MCU ESP32 module with a TFT display connected. The DS18B20 is connected to PortA.0 and has a 4k7 resistor from 3.3V to data line what happens is it sometimes reads the temp correctly and sometimes just gives me weird readings see below.
Read DS18B20.PNG
Read DS18B20.PNG (44.63 KiB) Viewed 6318 times
Feedback - -0.062500
DutyCycle - 84
Temp - -0.0° C
PV - 0
SV1 - 78
SetPoint - 78
Feedback - 25.687500
DutyCycle - 59
Temp - 25.6° C
PV - 25
SV1 - 78
SetPoint - 78
Feedback - -166.312500
DutyCycle - 0
Temp - -166.° C
PV - 65370
SV1 - 78
SetPoint - 78
Feedback - -0.062500
DutyCycle - 84
Temp - -0.0° C
PV - 0
SV1 - 78
SetPoint - 78
Feedback - 25.687500
DutyCycle - 59
Temp - 25.6° C

Any idears on how I can sorting this problem out?

Re: DS18B20 not reading every time

Posted: Fri Mar 04, 2022 11:45 am
by BenR
Hello,

After the sample all devices command you might need to call the AddressNextDevice or AddressSpecificDevice macro to point the read to the sensor you want to read. Hopefully this should help.

You could also maybe try reducing the bit depth of the DS18B20 component, this will speed up temperature conversion and might give us a clue e.g. if a timeout is happening.

To know more I might need to see your project or a simple version of that demonstrates the issue. I am using DS18B20 devices here on a heating controller and they are working great so hopefully it's something specific and simple that we can iron out.

Re: DS18B20 not reading every time

Posted: Sat Mar 12, 2022 11:30 am
by jollybv
Hi Ben

I've been playing around to try find out why the DS18B20 stops reading and I have narrowed it down to when you initialise the WLAN- ESP32 component. Not sure if I'm doing something wrong or there is a clash somewhere
DS18B20Test.fcfx
(64.07 KiB) Downloaded 536 times

Re: DS18B20 not reading every time

Posted: Mon Mar 14, 2022 10:56 am
by BenR
Hello,

Hmm that's interesting, the delays for the one wire are all done using the microsecond delay, I wonder if this becomes less stable when WIFI is active. How often do you get garbage results, is it say one in 10 or 1 in 2? If it's usually correct but every now and then you get a problem value then you could simply pass the sensor value via a median filter to remove any inconsistent data. If the error is much more often then you could instead look at the data and try to decide if the value is possible based on the difference from the last good value. Temperature is a slow changing thing so it should be possible to tame it one way or another.

I can look at the timings again with wifi active but this might not be an easy one to solve unless I can find a happy medium that works in all cases. To completely remove timing based issues you could use the DS2482 which will do all the timings for you and just allow you to communicate via I2C.

Re: DS18B20 not reading every time

Posted: Mon Mar 14, 2022 1:25 pm
by jollybv
Hi Ben

To answer your question it is not reading most of the time, every now and then it reads.

I have looked at my local suppliers and non of them stock the DS2482 and can only get from AliExpress but that's not going to work as the shipping is $60 and the chip is $2 it will take +- 3 months to get here so just not practical. I have the max 6675 on board as well which also works but wanted to use the DS18B20 as it is a nice cheap probe.

Re: DS18B20 not reading every time

Posted: Mon Mar 14, 2022 2:56 pm
by medelec35
Hi Brian,
If you are stuck, this thermistor version has given me excellent results over short and long distances.
It's good enough for a production version!

Re: DS18B20 not reading every time

Posted: Mon Mar 14, 2022 3:55 pm
by BenR
I'll try and replicate the issue for you tomorrow and see if I can tweak it to the point where it's stable again with wifi enabled.

Re: DS18B20 not reading every time

Posted: Tue Mar 15, 2022 6:16 am
by jollybv
@ Martin

I will look into the NTC probe and see what I can get here in South Africa

@ Ben

[I'll try and replicate the issue for you tomorrow and see if I can tweak it to the point where it's stable again with wifi enabled.]
that would be much appreciated

Re: DS18B20 not reading every time

Posted: Tue Mar 15, 2022 1:53 pm
by jollybv
Hi Martin

I managed to get a NTC prob and I have taken your program and modified it to work with the ESP32 and TFT display. I cant seem to get it to work on the hardware but it works in simulation. I have a 10k pull up resistor from +3.3V to A0 then have the probe between A0 and GND but I cant seem to reed the temperature on hardware.
NTC-test.fcfx
(16.66 KiB) Downloaded 562 times

Re: DS18B20 not reading every time

Posted: Tue Mar 15, 2022 4:41 pm
by medelec35
Hi Brian.
The issue is caused by the ADC of ESP32 is 12bit but the ADC values of the calculations are based on PIC/AVR 10bit ADC.
The solution is to add

Code: Select all

.ReadThermistorADC = (.ReadThermistorADC >> 2)
Just above

Code: Select all

.ThermistorCalc = SeriesPullUpResistance * 1.0 / (1023.0 / .ReadThermistorADC * 1.0 - 1.0)
So you should have

Code: Select all

.ReadThermistorADC = (.ReadThermistorADC >> 2)
.ThermistorCalc = SeriesPullUpResistance * 1.0 / (1023.0 / .ReadThermistorADC * 1.0 - 1.0)