ESP8622 and DS18b20 problem with something

My project must get temperature from GPIO0 and send to Virtual 3…
Check on Arduino, all sensors work fine, but not with esp…
My sketch:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DallasTemperature.h>
#include <SimpleTimer.h>

char auth[] = "*******";

  
char ssid[] = "*****";
char pass[] = "*****";

int oat;

#define ONE_WIRE_BUS 0

OneWire oneWire_oat(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire_oat);

SimpleTimer timer;

void setup()
{
  WiFi.begin(ssid, pass);

  Blynk.config(auth, IPAddress(*****), 8442);

  while (Blynk.connect() == false) {
  }
  sensors.begin();
  timer.setInterval(1000, sendTemps);
  
}

BLYNK_READ(V3)
{
  Blynk.virtualWrite(3, oat);
}

void sendTemps()
{
  sensors.requestTemperatures(); 
  int oat = sensors.getTempCByIndex(0);
  Blynk.virtualWrite(3, oat); 
}

BLYNK_CONNECTED() 
  {
    Blynk.syncVirtual(V3);
  }

void loop()
{
  Blynk.run();
  timer.run();
}

Whats wrong with it? Its work on Arduino Mega

Which ESP do you have and what physical pin are you connecting the DS18B20 to?

Unlike an Arduino, D0 on an ESP development board is NOT GPIO 0.

it s esp8266MOD AI-THINKER I try GPIO0 and 5… It’s not help…

Is it just the Espressif chip or is it on a development board?
If it’s just the chip have you wired it up correctly?
If it’s a board which physical pin, not which GPIO, are you using?

Also is the DS18B20 a chip or a probe?

I bought 2 batches of probes from different suppliers and they only worked with Arduino 5V, not ESP’s 3.3V. There are DS18B20 probes that work at 3.3V, like the bare chips, but some don’t.

VCC +5v, it’s temperature digital sensor work on one wire

Physical pin GPIO 0 and 5 I’ll try! Do you seen ESP?

I know what a DS18B20 is but it comes in different forms (bare sensor, sensor on a board and sensor on the end of a metal covered cable known as a probe).

Many, many, many users that move from Arduino’s to ESP don’t understand the pins on the ESP.
Arduino’s are labelled correctly. ESP development boards are all “WRONGLY” labelled, understand?

I think you kidding me…

Ok… About many many ds18b20…
search google ds18b20

About ESP
search google ESP-14

Whats wrong with it? -) Can you answer about sketch? Or ardiono IDE sketch too have many many differents?

I have around 60 of these sensors, in 3 DIFFERENT forms.
Good luck.

I have LOTS of copies of the datasheet, thanks.

Ask on the ESP8266 forum, not their GitHub, why you can’t get your DS18B20 to work with the ESP8266.

Your issue is NOT Blynk related.

I found that I often needed a small delay between requesting temp and reading results…

  DS18B20.requestTemperatures();
  delay(500); // adjust to as minimum a delay as needed
  Blynk.virtualWrite(V3, DS18B20.getTempCByIndex(0));

but I am also using parasitic power, so that might be part of it?

And even when running on a 3.3v ESP, my sensors need 5v (direct or parasitic) before they work

Post a photo of your ESP board that shows how your sensor is connected.

Pete.

When are they ever? :wink:

I’ve never had that problem actually, but in this example it could be a real problem!

We all know that the default 12 bit resolution has a 750 ms conversion time (yes?). Adding a 500 ms delay to that while running the timer every 1000 ms is probably not a good idea.

@chrisru Set the timer to once every 10 second to rule out any timing issues!

2 Likes

dont know if this is any help, but I found a tutorial/sketch with a DS18b20 “id reader” and then a sketch for using the DS18b20 with a nodemcu. Its a more manual approach but works.

The ID reader:

include <SimpleTimer.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2 // This is the ESP8266 pin D4
OneWire ds(ONE_WIRE_BUS);
DallasTemperature sensors(&ds);

SimpleTimer timer;

void setup()
{

Serial.begin(115200); // See the connection status in Serial Monitor

getDeviceAddress();
}

void getDeviceAddress(void) {
byte i;
byte addr[8];

Serial.println(“Getting the address…\n\r”);
/* initiate a search for the OneWire object we created and read its value into
addr array we declared above*/

while(ds.search(addr)) {
Serial.print(“The address is:\t”);
//read each byte in the address array
for( i = 0; i < 8; i++) {
Serial.print(“0x”);
if (addr[i] < 16) {
Serial.print(‘0’);
}
// print each byte in the address array in hex format
Serial.print(addr[i], HEX);
if (i < 7) {
Serial.print(", ");
}
}
// a check to make sure that what we read is correct.
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print(“CRC is not valid!\n”);
return;
}
}
ds.reset_search();
return;
}

void loop(void) {
timer.run();
}

It outputs hex string(s) which is the ID(s) of the DS18b20(s)
Insert those in below sketch

then a DS18b20 blynk sketch with two sensors:

#include <SimpleTimer.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2 // (nodemcu D4 = 2) This is the ESP8266 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress tempSensor1 = { INSERT HEX HERE }; // Temperature probe #1
DeviceAddress tempSensor2 = { 0x28, 0xFF, 0x8F, 0x35, 0x16, 0x15, 0x03, 0x4F }; // Temperature probe #2

char auth = “******”; // Put your Auth Token here. (see Step 3 above)

SimpleTimer timer;

float temperature1, temperature2; // Variables for storing temperatures

void setup()
{
WiFi.mode(WIFI_STA);
Serial.begin(115200); // See the connection status in Serial Monitor
Blynk.begin(auth, “SSID”, “PASSWORD”); //insert here your SSID and password

while (Blynk.connect() == false) {
// Wait until connected
}

sensors.begin();
sensors.setResolution(tempSensor1, 12); // More on resolutions: http://www.homautomation.org/2015/11/17/ds18b20-how-to-change-resolution-9101112-bits/
sensors.setResolution(tempSensor2, 12);

// These timers are used to keep the loop() nice and leak… keeps Blynk from getting flooded.
timer.setInterval(5000L, sendSensor1);

}

void loop()
{
Blynk.run();
timer.run();
}

void sendSensor1() {
sensors.requestTemperatures(); // Polls the sensors
temperature1 = sensors.getTempC(tempSensor1); // Stores temp in F. Change getTempF to getTempC for celcius.
Blynk.virtualWrite(5, temperature1); // Send temp to Blynk virtual pin 1
temperature2 = sensors.getTempC(tempSensor2);
Blynk.virtualWrite(6, temperature2);
Blynk.virtualWrite(7, temperature1-temperature2);

}

void sendWifi()
{
Blynk.virtualWrite(1, map(WiFi.RSSI(), -105, -40, 0, 100) );
}

Where:
V5 is Temp1
V6 is Temp2
V7 is Temp diff between the two (something I needed in my project)
V1 is wifi signal