ESP8266 + 18B20-parasite - Will not work

Hi,

Noob on this. Trying to get the serial number of my 18B20 on a ESP8266. Only get 0000000000000000. Getting the temperature works. Ide?

// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// arrays to hold device address
DeviceAddress insideThermometer;

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  while(!Serial);
  
  Serial.println("Dallas Temperature IC Control Library Demo");
  Serial.println(sensors.getDeviceCount());
  
  // Start up the library 
  sensors.begin(); 
  
}


void loop() 
{

    // show the addresses we found on the bus
    Serial.print("Device 0 Address: ");
    printAddress(insideThermometer);
    Serial.println();

    if (sensors.isParasitePowerMode()) Serial.println("ON");
     else Serial.println("OFF");

    delay(10000);
    sensors.requestTemperatures();
    
    Serial.println(sensors.getTempCByIndex(0));
    delay(10000);
    
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }

}

Best regards
Magnus

Why the huge delays , adding up to 20 seconds ?

Not looked at your sketch ( always try an example with the library ) , but worth noting a lot of “ebay” ds18b20’s ( 3 wire versions) won’t work in parasitic mode .

Hi @mgk73,

test this sketch:

RV mineirin

// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// arrays to hold device address
DeviceAddress insideThermometer;

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  while (!Serial);

  // Start up the library
  sensors.begin();
  Serial.println("Dallas Temperature IC Control Library Demo");
  Serial.println(sensors.getDeviceCount());
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  
}


void loop()
{

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();

  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");

  delay(10000);
  sensors.requestTemperatures();

  Serial.println(sensors.getTempCByIndex(0));
  delay(10000);

}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }

}

Yep, if you think based on your code, datas will come in same millisecond...
But you will do delay party arround it but in the most important step (during waiting) for datas to come you will not use any delay there.