DS18B20 shows only 25 degrees and never changes

I’ve connected up two DS18B20 sensors to a esp32 with 5V, GND, signal and a 4.7 Ohm pull-up resistor. Everything works well except that the output is 25.00 on serial monitor and never changes. Specifying resolution 9 or 12 doesn’t matter - the output is the same. Pulling one of the sensors changes the output to -127 which shows that the function is OK (I think). I’ve put one of the sensors in the freezer for 15 minutes to see if there was any change but there wasn’t. I suspect that the output shows something else than temperature but I can’t figure out what it might be.

Esp32 do not support 5volts on ports. The port is probably destroyed. The 18B20 must be powerd with 3.3v and the pullup connected to 3.3v

The esp32 is powered with a USB cable. I’m feeding the DS18B20 from the 5V pin.

5 volt from USB is regulated down to 3.3V with a LDO regulator.
Upper left in this schematics: https://user-images.githubusercontent.com/1180107/37556716-20616fd8-29fa-11e8-9542-c7f0d03da3b5.jpg

OK but I can still take out 5V to feed the sensor - the datasheet says so. I switched to 3.3V to the sensor for a test and it still shows 25. Is the pull-up too weak or too strong?

No.
You must connect 18B20 to 3.3V
Pull- up at 4,7 Kohm

jjl
I followed your idea and connected to 3V with a pullup of 4.7 kOhm and there is no change.

jjl is correct, in all probability you’ve cooked the ESP32 port.
The 5V5 max you see in the DS18B20 datasheet relates to the DS18B20, not the ESP32

Which port on esp32 are we talking about?

Any GPIO; in the old money a port is basically an input or output of which a COM is but one type. Sorry, my age starting to show.

So, if I have cooked a port on the Lolin esp32, I connected the sensors to 3V and changed the sensor port from 16 to 4 (GPIO4). All other wiring unchanged, the sensors now show -127 meaning wiring problem. Is the 4.7 kOhm pullup to weak for 3V?

Edit:
I changed back to pin 16 and uploaded. It’s back with 25C on both sensors. So pin 4 doesn’t work for some reason.

Edit #2:
This is my wiring of the DS18B20s. Wiring the sensors to pin 4 didn’t work while 16 and 25 gave an output. The sensors are powered from the 3.3V pin on the esp32. The sketch shows one sensor. I have wired two and tested with a third to make sure the first two weren’t burned. All three show the same, 25.00 on serial monitor. Could it have somethign to do with conversion from the float variable that holds the temp?

Code

#include <Arduino.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONEWIRE_BUS 25

const int DISP_COLS = 128;
const int DISP_ROWS = 64;
const int DISP_RESET = -1;
const char DISP_ADDR = 0x3C;
float leftC, rightC;
char tArray[4];

int k;
int start = 0;
int stop = 8;
char symbol = char(247);
bool toggle = true;

DeviceAddress MagLeft =  {0x28, 0x4E, 0xB0, 0x75, 0xD0, 0x01, 0x3C, 0xDE};
DeviceAddress MagRight = {0x28, 0x9E, 0x9D, 0x75, 0xD0, 0x01, 0x3C, 0x0E};

Adafruit_SSD1306 OLED(DISP_COLS, DISP_ROWS, &Wire, DISP_RESET);
OneWire oneWire(ONEWIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup()
{ 
  Wire.begin(5, 4);       // SDA, SCL
  Serial.begin(9600);
  sensors.begin();

  sensors.setResolution(MagLeft, 12);
  sensors.setResolution(MagRight, 12);
  delay(500);

  if (!OLED.begin(SSD1306_SWITCHCAPVCC, DISP_ADDR, false, false))
  {
    Serial.println(F("OLED allocation failed"));
    for(;;);  // Don't proceed, loop forever
  }

  OLED.setTextSize(2);
  OLED.setTextColor(WHITE);
}  

void loop()
{
  delay(2000);
  OLED.clearDisplay();

  leftC = sensors.getTempC(MagLeft);
  rightC = sensors.getTempC(MagRight);

  OLED.setCursor(0, 0);
  OLED.println(" Mag temps");
  OLED.display();

  OLED.setCursor(0, 18);
  itoa(leftC, tArray,10);          // int > char*
  OLED.print("L: ");
  OLED.print(tArray);
  OLED.print(" ");
  OLED.print(symbol);  
  OLED.println("C");
  OLED.display();
  Serial.print("L: ");
  Serial.println(leftC);

  OLED.setCursor(0, 36);
  itoa(rightC, tArray,10);          // int > char*
  OLED.print("R: ");
  OLED.print(tArray);
  OLED.print(" ");  
  OLED.print(symbol);  
  OLED.println("C");
  OLED.display();
  Serial.print("R: ");
  Serial.println(rightC);
}

Hi hans,
I had exactly the same problem. I came across this thread. I found the solution in the 2nd sketch ianow posted. Before reading the temperature of a sensor, he executes requestTemeratures().

sensors.requestTemperatures();
  tempSensor1 = sensors.getTempC(sensor1);

This is probably not important, but he defines the sensor addresses like this:

uint8_t sensor1[8] = { 0x28, 0x28, 0xF6, 0x75, 0xD0, 0x01, 0x3C, 0xDA };

I personally read them in the program (right before setting the precision) and do not define them manually:

if(!temperaturesensor.getAddress(sensors, 0)) Serial.print("Unable to find address for Device 0");
else { Serial.print("Device 0 Address: "); printAddress(sensors); Serial.println(""); }