I’m a little confused now … are you using ESP8266 or ESP32?
Try updating the “firmware” e.g. run the Git GUI update process as listed above.
That just may be the solution, as it appears @psoro can get that same sensor working, more often than not, on his ESP32.
ESP32
Desculpe por confundi-lo
now I’m not confused anymore.
Hi there,
maybe you can put some sort of condition there.
First define your min temperature and max temperature.
example:
#define MIN_TEMPERATURE 0
#define MAX_TEMPERATURE 100
int failed = 0;
void leeTEMP()
{
sensors.requestTemperatures();
temp = sensors.getTempCByIndex(0);
if (temp == NAN
|| temp > MAX_TEMPERATURE
|| temp < MIN_TEMPERATURE
{
// if any sensor failed, bail on updates
failed = 1;
}
else
{
failed = 0;
Serial.println("TEMPERATURE: ");
Serial.println(temp);
Blynk.virtualWrite(V0, sensors.getTempCByIndex(0));
}
The error is still there, but you wont see it because the program will skip the reading.
will not be the solution because the correct reading sometimes takes a lot of time and would disrupt the project. I would need to read at least every 1 minute.
thank you anyway.
I am experiencing the same problem. It seems to be an issue when running Wifi & OneWire. Seems strange cause it works fine with the 8266 and the ESP32 is suppose to have a separate processor for the Wifi so it should be better. I posted an issue on the ESP32 GitHub but not sure if anything will be done about it soon. For my project I might have to move away from the ESP32 for now and go back to the 8266 until they get things worked out with the ESP32.
@Northernboy it’s strange that @psoro has an almost working system with his ESP32 i.e 1 in 50 bad readings and he could code around that margin of error. Suggest you try his exact sketch.
I tested psoro’s code just and I get about 1 in 50 good readings. If I comment out the Blynk starts and run that all readings are good all the time. The only difference is I am using Pin 14 instead of Pin 12 because I get a bunch of resets and script doesn’t run. I am also using DFRobot ESP-Wroom-32.
Hi!
I’m still thinking about this issue and I had the idea to use the two cores of the ESP32 for different purposes, the Core 1 to do Blynk Stuff and the Core 0 to read the sensor and update a few virtual pins… easy…
The result is that the sensor is giving me always -127.00, obviously I’m doing something wrong but I can’t see where…
@Gunner, you were interested about the two cores and their loops time ago, could you please be so kind to have a look and let me know where the mistake is located?
The sketch of the code goes like this:
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include _Sensor libraries and other stuff...._
.
.
void setup()
{
sensors.begin();// Sensor
.
.
_Blynk stuff_
.
.
xTaskCreatePinnedToCore(loop1, "loop1", 4096, NULL, 1, NULL, 0);
xTaskCreatePinnedToCore(loop2, "loop2", 4096, NULL, 1, NULL, 1);
}
void loop1(void *pvParameters) //Core 0
{
while (1){
sensors.requestTemperatures();
temp = sensors.getTempCByIndex(0);
.
.
Updating Vpins
.
.
delay(2000); //Core 0, nothing to do with Core1, delays are allowed.
}
void loop2(void *pvParameters) //Core 1
{
while (1){
if (Blynk.connected()){
Blynk.run();
}
timer.run();
delay(1);
}
}
void loop()
{
// Emtpy loop!
}
Using this code the Virtual pins are updated every 2 seconds so loop1 is working. On the other hand, Blynk is up and running so loop2 is fine also…
Despite this statements, the sensor is not working…it should be the way I have to “start” the sensor or something similar but I can’t see it…
Do I have to write an extra setup for the other core?
Any help will be appreciated…
Unfortunately I haven’t pursued multi core testing since… I have to pick my mental focus battles, and this one hadn’t come up again (I am currently focusing on non-Blynk RPi video streaming via user proof kiosk options for my dad’s viewing of his security cameras in his living room - Linux, my nemesis, has left me with almost no functional brain cells remaining but if I suddenly get a burst of energy/focus I will see what I can see).
I still think this OP issue has to do with basic ESP32 IDE Core issues causing possible Onewire/WiFi conflict… I think best option is to keep testing with each new release from espressif. Possibly take Blynk out of the picture, but still have somthing WiFi related actively running… OTA perhaps?.. just to see if that makes a difference. Process of trial, error and elimination.
No worries Gunner, I really appreciate your support in this forum and my question is not directly Blynk related…
I’ll try to find the way to do it properly somehow… Positive thinking! At least at the moment…
+1 here. That’s the reason I wanted to split the code using the two cores, one for Wifi (Blynk) stuff and the other to take measurements. Not sure if this statement has sense or not to be honest… The ESP32 is still unknown for me.
Thank you anyway!
I’ve been working with programming the two cores and multi-tasking. I have Blynk running on ESP32 and reading two DS18B20 temperature sensors. It’s working good but still working on it. One thing that doesn’t work so good is the Blynk timer so multi-tasking must be used with a different approach. I should have something to post over the next few days.
Note that .requestTemperatures()
takes about 750 ms to complete when using the default resolution of 12 bits. But setting .setWaitForConversion(0)
(false) you just initiate the sensors temperature conversation and don’t get stuck waiting for it to complete, i.e. freeze the program. Then check back later and just do the actual reading.
You could look at my project and the RF433_Master.ino-sketch how I use 2 timers to do a reading every 10 minute. The DS18B20 has a limited number of EEPROM writes, that’s why I don’t check it all that often. Some more details can be read in the code:
Hi @Northernboy,
I tried reading the DS18B20 without success using the two cores, could you please be so kind to post the main tips to achieve it?
Thanks in advance!!
Below is the basic code that has worked for me. I get about one bad reading in 50 and I’m still working on perfection, but this works good. Instead of using timer, instead create more tasks and modify the delay.
I am testing a bigger project that does communicates with the Blynk server as well has a touch screen on SPI that has been working great. Also I am still learning about the FreeRTOS so my code might not be the best way but it works and I am still learning.
Also the below example uses the DallasTemperature library and simple code to read the temperature, however I find this slow and creates more errors than the code I normally use which requires the addresses of the sensors. But use whatever code works for you to read temperatures.
Good Luck
NB
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 15
char auth[] = "***********************************"; //
const char* ssid = "***";
const char* pass = "************";
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;
float buff;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();
DS18B20.begin();
xTaskCreatePinnedToCore(WifiTask,"WifiTask ",4000,NULL,2,NULL,0); //Task for Core 0 priority set at 2
// xTaskCreatePinnedToCore(####Task,"####Task ",4000,NULL,1,NULL,0); //Example of another task pinned to Core 0 at a lower priority
xTaskCreatePinnedToCore(tempTask,"tempTask ",4000,NULL,5,NULL,1); //Task for Core 1 priority set at 5
// xTaskCreatePinnedToCore(####Task,"####Task ",4000,NULL,1,NULL,1); //Example of another task pinned to Core 1 at a lower priority
}
void loop() {
vTaskDelete( NULL );
}
void tempTask( void * pvParameters ) //Task for reading Temperature on Core 1
{
while(1){ //Use whatever code you use to measure temperature
DS18B20.requestTemperatures();
buff = DS18B20.getTempCByIndex(0);
if(buff!=-127.00){temp=buff;}
Blynk.virtualWrite(V10, temp);
vTaskDelay( 1000 / portTICK_PERIOD_MS); //Delay for this task allows the core to do other tasks
}
}
void WifiTask( void * pvParameters ) //Wifi&Blynk tasks on Core 0
{
WiFi.disconnect(); //Code here runs once same as setup
Blynk.begin(auth, ssid, pass);
while (Blynk.connect() == false) {}
while(1){ //Code here runs continously same as loop
Blynk.run();
vTaskDelay( 500 / portTICK_PERIOD_MS); //Little delay here is necessary
}
}
Many thanks @Northernboy,
Your sketch is really similar to the one I posted without success, except for the priorities and delays…
I’ll give it a try once at home.
Regards!
@psoro from what I have learnt delays are necessary to allow other tasks to be done. The project I am working on now I have 5 or 6 tasks running on each core and different delays.
@Northernboy I ran your code with a few cosmetic changes and it’s pretty good.
4 25.94
5 25.94
6 25.94
7 25.94
8 25.94
9 26.00
10 25.94
11 25.94
12 26.00
13 26.00
14 26.00
15 26.00
16 -127.00
17 26.00
18 26.00
19 -127.00
20 26.00
21 26.00
22 26.00
23 26.00
24 26.00
25 26.00
26 26.00
27 -127.00
28 26.00
29 26.00
30 26.00
31 26.00
32 26.00
33 26.00
34 26.00
35 25.94
36 25.94
37 25.94
38 25.94
39 25.94
40 25.94
41 25.94
42 25.94
43 25.94
44 25.87
45 -127.00
46 25.87
47 25.87
48 25.87
49 25.87
50 25.87
51 25.87
52 25.87
53 -127.00
54 25.87
55 25.87
56 25.87
57 25.87
58 25.87
59 25.81
60 25.81
61 25.87
62 25.87
63 25.87
64 25.87
65 25.94
66 25.94
67 25.94
68 25.94
69 25.94
70 25.94
71 25.94
72 25.94
73 25.94
74 25.94
75 25.94
76 25.94
77 25.94
78 25.94
79 25.87
80 25.87
81 25.87
82 25.87
83 25.81
84 25.81
85 25.81
86 25.81
87 25.81
88 25.81
89 25.75
90 25.81
91 25.75
92 25.75
93 25.75
94 25.75
95 25.75
96 25.75
97 25.75
98 25.69
99 25.69
100 25.69
101 25.69
102 25.69
103 25.69
104 25.69
105 25.69
106 25.69
107 25.69
108 25.69
109 25.69
110 25.69
111 25.69
112 25.69
113 25.69
114 25.69
115 25.69
116 25.69
117 25.69
118 25.69
119 25.69
120 25.69
121 25.62
122 25.62
123 25.62
124 25.62
125 25.62
126 25.62
127 25.62
128 25.62
129 25.62
130 25.62
131 25.62
132 25.62
133 25.62
134 25.62
135 25.62
136 25.62
137 25.69
138 25.69
139 25.69
140 25.69
141 25.69
142 25.69
143 25.69
144 25.69
145 25.69
146 25.75
147 25.69
148 25.69
149 25.75
150 25.75
151 25.75
152 25.75
153 25.75
154 25.75
155 25.75
156 25.75
157 25.81
158 25.81
159 25.81
160 25.81
161 25.81
162 25.81
163 25.87
164 25.87
165 25.87
166 25.87
167 25.87
168 25.87
169 25.87
170 -127.00
171 25.94
172 25.94
173 25.94
174 25.94
175 25.94
176 25.94
177 25.94
178 25.94
179 26.00
180 25.94
181 26.00
182 25.94
183 25.94
184 25.94
185 25.94
186 25.94
187 25.94
188 26.00
189 26.00
190 26.00
191 26.00
192 26.00
193 -127.00
194 26.00
195 26.00
196 26.00
197 26.06
198 -127.00
199 26.06
200 26.06
Just 8 false results in the 200 requests and none between request 54 and 169. As you have it in your sketch you can code around the odd bad result.
Come on… It’s not fair… I have to wait for a few hours to be able to “play” a little bit with the Esp32!
It seems the bad result is always there somehow…