If I remove the part of the code responsible for connecting with the Blynk the sensor works normally.
My code below.
My hardware is an esp-32.
// inicio BLYNK ***********************************************************
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "**************************";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*********";
char pass[] = "****************";
//fim BLYNK *************************************************************
//inicio sensor temperatura
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 13 // DS18B20 on arduino pin4 corresponds to GPI12 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;
//fim sensor temperatura
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
Serial.println();
//BLYNK
Blynk.begin(auth, ssid, pass);
//Inicializa SENSOR TEMPERATURA
DS18B20.begin();
}
void loop() {
// put your main code here, to run repeatedly:
//BLYNK
temperatura();
delay(1000);
}
void temperatura()
{
//inicio SENSOR TEMPERATURA
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.println("TEMPERATURA");
Serial.println(temp);
Blynk.virtualWrite(V10, temp);
}
Even with the modification done as shown in the code below, the problem continues.:desapontado:
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = " *********** ";
// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = " ************ ";
char pass[] = " ******************* ";
//fim BLYNK *************************************************************
//inicio sensor temperatura
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 15 // DS18B20 on arduino pin4 corresponds to GPI12 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;
//fim sensor temperatura
BlynkTimer timer;
void temperatura()
{
//inicio SENSOR TEMPERATURA
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.println("TEMPERATURA");
Serial.println(temp);
Blynk.virtualWrite(V10, temp);
delay(1000);
}
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
Serial.println();
//BLYNK
Blynk.begin(auth, ssid, pass);
//Inicializa SENSOR TEMPERATURA
DS18B20.begin();
timer.setInterval(1000L, temperatura);
}
void loop()
{
// put your main code here, to run repeatedly:
//BLYNK
Blynk.run();
timer.run();
}
Reinstate Blynk and paste Serial Monitor from the start. Just wondering if you are failing to connect to the Blynk server and it’s too busy trying, and failing to connect, to be able to read the sensor.
So, to confirm, it works with the timer as well as without (as you have tested before)?
Blynk itself shouldn’t affect how it reads that sensor… unless there is some strange incompatibility with something in the Blynk library and the relatively “new to Blynk” ESP32.
Have you tried any other pins on the ESP32… as many have multiple applications and perhaps may contribute to the conflict.
I’ve tried all the pins, and the temperature reading only shows -127º and the actual temperature when the application is connected to Blynk.
I noticed that when connected to Blynk, the Gauge widget used to show the temperature initializes with a value of 0 and each reading increases by 1 unit to the value. 1,2,3,4,5,6,7, …
I am trying to work a process of elimination here… we already know that -127 is a default error reading and we are currently not worried about widgets…since you are also seeing the error in the serial monitor…
So… please confirm my question, and if possible test that other library.