DS18B20 works only with pin D4 and D3 on nodeMCU....not others

Hello amazing people!
when this sensor is connected with any pin,other than mentioned above, along with required change in code....sensor shoots value of -127 ....what could be possible reason
Thanks already

Confirmed.
On my WeMos D1 mini only GPIO_2 and GPIO_13 work.
Leo..

Confirmed. You are both incorrect.

The DS18B20 (actually a pair of them) work fine on any of pins D1 through D7.

This is on the NodeMCU hardware running the DallasTemperature library available through the Library Manager.

Don

Just got GPIO_12 as well to work on the WeMos.
No joy on the other inputs.
Leo..

GPIO16 won't work (it doesn't have an interrupt available).
GPIO15 won't work (it requires a pull-down for proper boot).

All other pins should work fine - no obvious reason they wouldn't be able to handle this sensor.

wvmarle:
GPIO16 won't work (it doesn't have an interrupt available).
GPIO15 won't work (it requires a pull-down for proper boot).

All other pins should work fine - no obvious reason they wouldn't be able to handle this sensor.

I have tested my NodeMCU ESP-12 Kit + DS18B20 + OneWire.h. The setup has worked for D1(GPIO-5) to D7(GPIO-13); it has not worked for D0(GPIO-16) and D8(GPIO-15).

//12-bit default resolution; external power supply
#include<OneWire.h>
#define OneWireBusPin 5
OneWire ds(OneWireBusPin);  //2
byte addr1[8];         //to hold 64-bit ROM Codes of DS1
byte data[9];        //buffer to hold data coming from DS18B20
float celsius;
byte busStatus;

void setup()
{
  Serial.begin(115200);
  
  ds.reset();
  ds.search(addr1);  //collect 64-bit ROM code from sensor (DS1)
}

void loop()
{
  
  ds.reset();       //bring 1-Wire into idle state
  ds.select(addr1); //slect with DS-1 with address addr1
  ds.write(0x44);    //conversion command
  do   //let sensor take as much time as it needs to finish conversion
  {
    busStatus = ds.read();
  }
  while (busStatus != 0xFF);
  //---------------------------
  ds.reset();
  ds.select(addr1);  //selectimg the desired DS18B20
  ds.write(0xBE);    //Function command to read Scratchpad Memory (9Byte)
  ds.read_bytes(data, 9); //data comes from DS and are saved into buffer data[8]
  //---------------------------------

  int16_t raw = (data[1] << 8) | data[0]; //---data[0] and data[1] contains temperature data : 12-bit resolution-----
  celsius = (float)raw / 16.0;  //12-bit resolution
  Serial.println(celsius);
  
  delay(3000);
  
}

Confirmed. You are both incorrect.

The DS18B20 (actually a pair of them) work fine on any of pins D1 through D7.

This is on the NodeMCU hardware running the DallasTemperature library available through the Library Manager.

Don

but we declare the pin no. in the code and send that to function or object of library.....dosent that mean its we who decide the pin to be used not the library?????

Yes, of course it's us who decide which pin to use. In fact you must tell the library which pin to use, or it won't work.

Yes, of course it's us who decide which pin to use. In fact you must tell the library which pin to use, or it won't work.

Then am damn curious to know why aint it workin for what i tell it to do......I even replaced my device in the past claiming that it anit workin

You are obviously doing something wrong but until you provide more information we cannot help you.

Don


and this is the code

// 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);

/*
 * The setup function. We only start the sensors here
 */
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
}

/*
 * Main function, get and show the temperature
 */
void loop(void)
{ 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  // After we got the temperatures, we can print them here.
  // We use the function ByIndex, and as an example get the temperature from the first sensor only.
  Serial.print("Temperature for the device 1 (index 0) is: ");
  Serial.println(sensors.getTempCByIndex(0));  
}

On a NodeMCU, pin 2 is not the same as pin D2 (while on an Arduino it is).

If you define the bus as 2 (which refers to GPIO2 of the ESP8266), you should connect your sensor to pin D4 on the NodeMCU. Refer to the image in #5.

On a NodeMCU, pin 2 is not the same as pin D2 (while on an Arduino it is).

If you define the bus as 2 (which refers to GPIO2 of the ESP8266), you should connect your sensor to pin D4 on the NodeMCU. Refer to the image in #5.

thanks for your reply....I know that and connected it to D4 already

sabishaw:

and this is the code
. . .

And that is only some of the information that we need. You claim to have connected it properly but how can we check that without a photo?

The DS18B20 can be operated in two different modes. If you are using it in parasitic mode then all bets are off.

Don

i did in normal mode not parasitic

I seem to have the same problem when trying to read two thermocouple K sensors using Adafruit's MAX31850 amplifier boards and Adafruit's example code (Wiring and Test | Adafruit 1-Wire Thermocouple Amplifier - MAX31850K | Adafruit Learning System). I am using Wemos D1 Pro Mini (ESP8266).

I get the readings OK through the pins D3 and D4, but no luck with any of the other pins.

In the past I have succesfully read the same sensor through Wemos pin D2 (one_wire_bus 4) but now it does not seem to work anymore.

I fixed the problem by enabling the pull up resistor on the pin I am using.

It seems that the pull up resistors are on by default (I might be wrong here, but this is how I interpreted: https://wiki.wemos.cc/products:d1:d1_mini). And when using D5 (14) I had to add

PinMode(14, INPUT_PULLUP);

to the setup.

I am also facing the same issue. i am using nodemcu board , using dallas and onewire to read one of the value connected to D7 (pin 13) but it shoot me -127 . it work fine wheni am using D4 and D3 but don't seems to work with rest of the D(n) pins.

Pins D3 and D4 are used by the device during the boot procedure and as a result those pins have physical pullup resistors mounted on the board.

Most (all ??) of the other pins do not have physical pullup resistors mounted on the board. If you want to use any of those pins you will have to provide your own pullup. The value is not critical. Typically 4700 ohms is used but anything between 2000 and 10000 will probably work.

Don