DS18B20 value -127º, but only when connecting to Blynk, on ESP32

@Costas I’m glad it worked for you. I am looking into how to modify the tick frequency to try to give the Onewire function more time to complete. I believe the bad readings are because the task is existing before it has time to get a value. I’ll report back once I get some more testing and tuning.

1 Like

I don’t know if my previous post was overlooked or just ignored :wink: but I still believe its valid and worth looking into.

Use two timers instead of waiting for the temperature conversation to finish!

Following @Costas example I did a run for 200 reading, with three sensors in parasitic mode, with a total cable lenght of 17 meters, only powered by the Arduino and got ZERO errors. Albeit not a dual core MCU, but all my timing issues are gone with this setup!


The best is yet to come!
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.88
1
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
2
Bedroom: 21.50
Livingroom: 22.25
Extra: 21.94
3
Bedroom: 21.50
Livingroom: 22.25
Extra: 21.94
4
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
5
Bedroom: 21.50
Livingroom: 22.25
Extra: 21.94
6
Bedroom: 21.50
Livingroom: 22.25
Extra: 21.94
7
Bedroom: 21.50
Livingroom: 22.25
Extra: 21.94
8
Bedroom: 21.50
Livingroom: 22.25
Extra: 21.94
9
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
10
Bedroom: 21.50
Livingroom: 22.25
Extra: 21.94
11
Bedroom: 21.50
Livingroom: 22.25
Extra: 21.94
12
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
13
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
14
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
15
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
16
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
17
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
18
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
19
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
20
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
21
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
22
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
23
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
24
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
25
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
26
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
27
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
28
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
29
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
30
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
31
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
32
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
33
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
34
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
35
Bedroom: 21.50
Livingroom: 22.19
Extra: 21.94
36
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
37
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
38
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
39
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
40
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
41
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
42
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
43
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
44
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
45
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
46
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
47
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
48
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
49
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
50
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
51
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
52
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
53
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
54
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
55
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
56
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
57
Bedroom: 21.50
Livingroom: 22.19
Extra: 22.00
58
Bedroom: 21.57
Livingroom: 22.19
Extra: 22.00
59
Bedroom: 21.57
Livingroom: 22.25
Extra: 22.00
60
Bedroom: 21.57
Livingroom: 22.38
Extra: 22.00
61
Bedroom: 21.57
Livingroom: 22.44
Extra: 22.00
62
Bedroom: 21.50
Livingroom: 22.50
Extra: 22.00
63
Bedroom: 21.50
Livingroom: 22.63
Extra: 22.00
64
Bedroom: 21.50
Livingroom: 22.69
Extra: 22.00
65
Bedroom: 21.50
Livingroom: 22.75
Extra: 22.00
66
Bedroom: 21.57
Livingroom: 22.75
Extra: 22.00
67
Bedroom: 21.50
Livingroom: 22.82
Extra: 22.00
68
Bedroom: 21.50
Livingroom: 22.82
Extra: 22.00
69
Bedroom: 21.57
Livingroom: 22.88
Extra: 22.00
70
Bedroom: 21.50
Livingroom: 22.88
Extra: 22.00
71
Bedroom: 21.50
Livingroom: 22.88
Extra: 22.00
72
Bedroom: 21.57
Livingroom: 22.94
Extra: 22.00
73
Bedroom: 21.50
Livingroom: 22.94
Extra: 22.00
74
Bedroom: 21.57
Livingroom: 22.94
Extra: 22.00
75
Bedroom: 21.57
Livingroom: 22.94
Extra: 22.00
76
Bedroom: 21.57
Livingroom: 22.94
Extra: 22.00
77
Bedroom: 21.50
Livingroom: 23.00
Extra: 22.00
78
Bedroom: 21.57
Livingroom: 23.00
Extra: 22.00
79
Bedroom: 21.57
Livingroom: 23.00
Extra: 22.00
80
Bedroom: 21.50
Livingroom: 23.07
Extra: 22.00
81
Bedroom: 21.50
Livingroom: 23.07
Extra: 22.00
82
Bedroom: 21.57
Livingroom: 23.07
Extra: 22.00
83
Bedroom: 21.50
Livingroom: 23.07
Extra: 22.00
84
Bedroom: 21.50
Livingroom: 23.13
Extra: 22.00
85
Bedroom: 21.57
Livingroom: 23.13
Extra: 22.00
86
Bedroom: 21.50
Livingroom: 23.13
Extra: 22.00
87
Bedroom: 21.57
Livingroom: 23.13
Extra: 22.00
88
Bedroom: 21.50
Livingroom: 23.19
Extra: 22.00
89
Bedroom: 21.57
Livingroom: 23.19
Extra: 22.00
90
Bedroom: 21.50
Livingroom: 23.19
Extra: 22.00
91
Bedroom: 21.50
Livingroom: 23.19
Extra: 22.00
92
Bedroom: 21.50
Livingroom: 23.19
Extra: 22.00
93
Bedroom: 21.50
Livingroom: 23.19
Extra: 22.00
94
Bedroom: 21.50
Livingroom: 23.19
Extra: 22.00
95
Bedroom: 21.57
Livingroom: 23.19
Extra: 22.07
96
Bedroom: 21.57
Livingroom: 23.25
Extra: 22.13
97
Bedroom: 21.57
Livingroom: 23.38
Extra: 22.19
98
Bedroom: 21.50
Livingroom: 23.50
Extra: 22.32
99
Bedroom: 21.57
Livingroom: 23.63
Extra: 22.38
100
Bedroom: 21.57
Livingroom: 23.75
Extra: 22.50
101
Bedroom: 21.50
Livingroom: 23.88
Extra: 22.57
102
Bedroom: 21.50
Livingroom: 23.94
Extra: 22.63
103
Bedroom: 21.50
Livingroom: 24.00
Extra: 22.69
104
Bedroom: 21.50
Livingroom: 24.07
Extra: 22.75
105
Bedroom: 21.50
Livingroom: 24.13
Extra: 22.75
106
Bedroom: 21.57
Livingroom: 24.25
Extra: 22.82
107
Bedroom: 21.50
Livingroom: 24.32
Extra: 22.88
108
Bedroom: 21.50
Livingroom: 24.38
Extra: 22.88
109
Bedroom: 21.50
Livingroom: 24.44
Extra: 22.94
110
Bedroom: 21.50
Livingroom: 24.50
Extra: 22.94
111
Bedroom: 21.57
Livingroom: 24.57
Extra: 23.00
112
Bedroom: 21.57
Livingroom: 24.57
Extra: 23.07
113
Bedroom: 21.57
Livingroom: 24.57
Extra: 23.07
114
Bedroom: 21.50
Livingroom: 24.63
Extra: 23.13
115
Bedroom: 21.57
Livingroom: 24.63
Extra: 23.13
116
Bedroom: 21.50
Livingroom: 24.63
Extra: 23.19
117
Bedroom: 21.57
Livingroom: 24.63
Extra: 23.25
118
Bedroom: 21.57
Livingroom: 24.63
Extra: 23.25
119
Bedroom: 21.57
Livingroom: 24.57
Extra: 23.32
120
Bedroom: 21.50
Livingroom: 24.44
Extra: 23.32
121
Bedroom: 21.50
Livingroom: 24.44
Extra: 23.32
122
Bedroom: 21.57
Livingroom: 24.38
Extra: 23.38
123
Bedroom: 21.50
Livingroom: 24.32
Extra: 23.32
124
Bedroom: 21.57
Livingroom: 24.19
Extra: 23.32
125
Bedroom: 21.57
Livingroom: 24.13
Extra: 23.25
126
Bedroom: 21.50
Livingroom: 24.00
Extra: 23.19
127
Bedroom: 21.50
Livingroom: 23.88
Extra: 23.13
128
Bedroom: 21.57
Livingroom: 23.82
Extra: 23.13
129
Bedroom: 21.57
Livingroom: 23.75
Extra: 23.07
130
Bedroom: 21.57
Livingroom: 23.69
Extra: 23.07
131
Bedroom: 21.57
Livingroom: 23.63
Extra: 23.00
132
Bedroom: 21.57
Livingroom: 23.57
Extra: 23.00
133
Bedroom: 21.50
Livingroom: 23.57
Extra: 22.94
134
Bedroom: 21.50
Livingroom: 23.50
Extra: 22.94
135
Bedroom: 21.57
Livingroom: 23.44
Extra: 22.88
136
Bedroom: 21.50
Livingroom: 23.44
Extra: 22.88
137
Bedroom: 21.57
Livingroom: 23.38
Extra: 22.82
138
Bedroom: 21.50
Livingroom: 23.38
Extra: 22.82
139
Bedroom: 21.57
Livingroom: 23.38
Extra: 22.82
140
Bedroom: 21.63
Livingroom: 23.32
Extra: 22.75
141
Bedroom: 21.75
Livingroom: 23.32
Extra: 22.75
142
Bedroom: 21.88
Livingroom: 23.32
Extra: 22.69
143
Bedroom: 22.00
Livingroom: 23.25
Extra: 22.69
144
Bedroom: 22.19
Livingroom: 23.25
Extra: 22.69
145
Bedroom: 22.32
Livingroom: 23.25
Extra: 22.63
146
Bedroom: 22.44
Livingroom: 23.19
Extra: 22.63
147
Bedroom: 22.50
Livingroom: 23.19
Extra: 22.63
148
Bedroom: 22.63
Livingroom: 23.19
Extra: 22.57
149
Bedroom: 22.69
Livingroom: 23.13
Extra: 22.57
150
Bedroom: 22.69
Livingroom: 23.13
Extra: 22.57
151
Bedroom: 22.75
Livingroom: 23.13
Extra: 22.57
152
Bedroom: 22.75
Livingroom: 23.07
Extra: 22.50
153
Bedroom: 22.75
Livingroom: 23.07
Extra: 22.50
154
Bedroom: 22.75
Livingroom: 23.00
Extra: 22.50
155
Bedroom: 22.75
Livingroom: 23.00
Extra: 22.50
156
Bedroom: 22.75
Livingroom: 23.00
Extra: 22.50
157
Bedroom: 22.75
Livingroom: 23.00
Extra: 22.44
158
Bedroom: 22.75
Livingroom: 22.94
Extra: 22.44
159
Bedroom: 22.69
Livingroom: 22.94
Extra: 22.44
160
Bedroom: 22.69
Livingroom: 22.88
Extra: 22.44
161
Bedroom: 22.69
Livingroom: 22.88
Extra: 22.44
162
Bedroom: 22.69
Livingroom: 22.88
Extra: 22.44
163
Bedroom: 22.69
Livingroom: 22.88
Extra: 22.38
164
Bedroom: 22.63
Livingroom: 22.88
Extra: 22.38
165
Bedroom: 22.63
Livingroom: 22.88
Extra: 22.38
166
Bedroom: 22.63
Livingroom: 22.82
Extra: 22.38
167
Bedroom: 22.63
Livingroom: 22.82
Extra: 22.38
168
Bedroom: 22.57
Livingroom: 22.82
Extra: 22.38
169
Bedroom: 22.57
Livingroom: 22.82
Extra: 22.38
170
Bedroom: 22.57
Livingroom: 22.82
Extra: 22.38
171
Bedroom: 22.50
Livingroom: 22.82
Extra: 22.38
172
Bedroom: 22.50
Livingroom: 22.75
Extra: 22.38
173
Bedroom: 22.50
Livingroom: 22.75
Extra: 22.32
174
Bedroom: 22.50
Livingroom: 22.75
Extra: 22.32
175
Bedroom: 22.50
Livingroom: 22.75
Extra: 22.32
176
Bedroom: 22.44
Livingroom: 22.69
Extra: 22.32
177
Bedroom: 22.44
Livingroom: 22.69
Extra: 22.32
178
Bedroom: 22.44
Livingroom: 22.69
Extra: 22.32
179
Bedroom: 22.44
Livingroom: 22.69
Extra: 22.32
180
Bedroom: 22.38
Livingroom: 22.69
Extra: 22.32
181
Bedroom: 22.38
Livingroom: 22.69
Extra: 22.32
182
Bedroom: 22.38
Livingroom: 22.69
Extra: 22.32
183
Bedroom: 22.38
Livingroom: 22.69
Extra: 22.32
184
Bedroom: 22.38
Livingroom: 22.69
Extra: 22.32
185
Bedroom: 22.32
Livingroom: 22.69
Extra: 22.32
186
Bedroom: 22.32
Livingroom: 22.63
Extra: 22.25
187
Bedroom: 22.32
Livingroom: 22.63
Extra: 22.25
188
Bedroom: 22.32
Livingroom: 22.63
Extra: 22.25
189
Bedroom: 22.32
Livingroom: 22.63
Extra: 22.25
190
Bedroom: 22.25
Livingroom: 22.63
Extra: 22.25
191
Bedroom: 22.25
Livingroom: 22.63
Extra: 22.25
192
Bedroom: 22.25
Livingroom: 22.63
Extra: 22.25
193
Bedroom: 22.25
Livingroom: 22.57
Extra: 22.25
194
Bedroom: 22.25
Livingroom: 22.57
Extra: 22.25
195
Bedroom: 22.25
Livingroom: 22.57
Extra: 22.25
196
Bedroom: 22.19
Livingroom: 22.57
Extra: 22.25
197
Bedroom: 22.25
Livingroom: 22.57
Extra: 22.25
198
Bedroom: 22.19
Livingroom: 22.50
Extra: 22.25
199
Bedroom: 22.19
Livingroom: 22.50
Extra: 22.25
200

Got more errors on the ESP32 with this setting than the test without it.

Just running another test at 9 bit resolution.

95	23.81	Errors: 5
96	23.81	Errors: 5
97	23.87	Errors: 5
98	23.87	Errors: 5
99	23.87	Errors: 5
100	23.87	Errors: 5
101	23.87	Errors: 5
102	-127.00	Errors: 6
103	23.87	Errors: 6
104	23.87	Errors: 6
105	23.81	Errors: 6

Already 6 errors from 105 readings. 12 errors from 200 readings.

@distans I’ve used the wait for conversion in the past and it does work great. However I believe it is not problem with the ESP32. FreeRTOS freezes tasks and switches to another if there is one with a higher priority, I feel that this momentary pause effects some of timing in onewire function. If you look at the library there are delays in the microSeconds and it also disables interrupts during this timing. I could be wrong but it seems this way is working for now and I am still researching and learning.

Mkay, that’s seems weird! :crazy_face:

Well yes (and no) :stuck_out_tongue_winking_eye: When I use setWaitForConversion(false), it takes requestTemperature() less than 2 ms to send the command to the sensors. When I check back, the reading takes about 30 ms.

Have you tried using deviceAddress instead of getTempCByIndex? It’s a little bit faster.

@distans are you testing on a ESP32 with wifi enabled?

No, I only have Arduino UNO’s at the moment and using W5100 Ethernet shield (only outdated cheap stuff hehe). I had a fair amount of issues with disconnects before. I even tapped the network connection and dumped all traffic thru Wireshark. It seemed like the problem was due to the W5100’s small RX buffer got full when left unattended for a period of time (i.e. the program was stuck on a functions delay).

But after I rearranged how I call the sensors and a more modest polling for external data (time and connection) I haven’t had any problem.

I’ve been thinking about buying an ESP32 or two, but I’m not so sure anymore :laughing: But I hope you figure it out!

If you want something that works buy an ESP8266.

2 Likes

@Northernboy,
It’s working now! Unfortunately I’ve got the same fails as using a “normal” sketch… Anyway I have learnt a little bit more about the ESP32 and at least I can use both cores to do different things in a proper way.

I think I may have found a fix. Testing it now 250 reads and no failures. I going to try to modify the onewire library so it will work however you run it. Ill report back later after more testing.

2 Likes

I tested it on two of the above scripts and it works perfect without any need to do anything with tasks or programming both Cores.

First initialize the sensor in setup before starting Blynk.
Then after whenever reading the sensor a command before to stop interrupts and after to start interrupts
See the following example:

void temp_read()
{
  portDISABLE_INTERRUPTS();
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0);
  portENABLE_INTERRUPTS();
 
  Serial.println("TEMP");
  Serial.println(temp);
 
  Blynk.virtualWrite(V0, temp);
}

I think this is stopping any of the multitasking that is enabled with the wifi on.

Give it a try and let me know.

3 Likes

Looking excellent here, this is how the trusty DS18B20 should perform:

90	23.50	Errors: 0
91	23.50	Errors: 0
92	23.50	Errors: 0
93	23.44	Errors: 0
94	23.44	Errors: 0
95	23.44	Errors: 0
96	23.50	Errors: 0
97	23.50	Errors: 0
98	23.50	Errors: 0
99	23.50	Errors: 0
100	23.44	Errors: 0
101	23.50	Errors: 0
102	23.50	Errors: 0
103	23.44	Errors: 0
104	23.50	Errors: 0
105	23.50	Errors: 0
106	23.44	Errors: 0
107	23.44	Errors: 0
108	23.44	Errors: 0
109	23.50	Errors: 0
110	23.44	Errors: 0
111	23.50	Errors: 0
112	23.50	Errors: 0
113	23.50	Errors: 0
114	23.50	Errors: 0
115	23.44	Errors: 0
116	23.50	Errors: 0
117	23.44	Errors: 0
118	23.44	Errors: 0
119	23.50	Errors: 0
120	23.50	Errors: 0
121	23.44	Errors: 0

Thanks for the fix.
I will change the timer to 30s and leave it running for a few hours.

Still going strong:

357	23.56	Errors: 0
358	23.56	Errors: 0
359	23.56	Errors: 0
360	23.56	Errors: 0
361	23.56	Errors: 0
362	23.56	Errors: 0
363	23.56	Errors: 0
364	23.56	Errors: 0
365	23.56	Errors: 0
366	23.56	Errors: 0
367	23.56	Errors: 0
368	23.56	Errors: 0
369	23.56	Errors: 0
370	23.56	Errors: 0
371	23.50	Errors: 0
372	23.56	Errors: 0
373	23.50	Errors: 0
374	23.50	Errors: 0
375	23.50	Errors: 0
376	23.50	Errors: 0
/* RGB-DS18B20-OTA.ino RGB with DS18B20, local OTA and timers for ESP32 
from https://community.blynk.cc/t/esp32-pwm-and-blynk/18277
and https://community.blynk.cc/t/ds18b20-value-127-but-only-when-connecting-to-blynk-on-esp32/18336/112
and https://community.blynk.cc/t/starting-an-esp32-thread/18809 (Lounge)
and https://community.blynk.cc/t/timer-help/18812
*/

1 Like

I am happy that the topic is generating good results, I had a health problem (herniated disc crisis), and I will follow the tests and suggestions posted here in the topic.

1 Like

Update:

748	23.31	Errors: 0
749	23.31	Errors: 0
750	23.25	Errors: 0
751	23.37	Errors: 0
[23481449] Time sync: OK
752	23.44	Errors: 0
753	23.37	Errors: 0
754	23.50	Errors: 0
755	23.56	Errors: 0

woohoo!

TEMPERATURE: 
23.62
FAILS: 
0
READINGS: 
1601

Many thanks for that tips!!

Go steady with the EEPROM.

I’m really very happy, this code it was the only one that really worked, and best of all, no mistakes.
Thank you very much for the help the all.

HI I have encountered the same problem, can you send me your program please because it tried to follow the steps but still it doesnt work.

Use your own code that u use for Blynk but change your reading to Northernboy void temp_read()
It works for me, good luck.