DS18B20 sometimes gives me back -127 C

Hello, i have 10 DS18B20 sensors connected in parasite mode. Sometimes (I guess because of electrical noise) one of sensors gives me back -127, sensors working constantly without any delays, i am having -127 few times in a day. All my sensors is in the same room, so it's 2-3 meters from Arduino. When i connect another one which is 10 meters far away, i am getting -127 constantly. How it's come and what's bad in my code ? By the way, i can't use any big delays, because programme must work without any delays. There is how i read them:

float kp; 
float kg ;
float sp ;
float sg ;
float ap ;
float tl;
float x2;
float x3;
float x4;
float tb;

DeviceAddress sgg = {
  0x28,0xAB, 0xBD,0xDA,0x2,0x0,0x0,0x4C};
DeviceAddress spp = {
  0x28,0x68, 0xCF,0xDA,0x2,0x0,0x0,0x64};
DeviceAddress kgg = {
  0x28,0x12, 0xBF,0xDA,0x2,0x0,0x0,0x5E};
DeviceAddress kpp = {
  0x28,0xF1, 0xFF,0x8D,0x2,0x0,0x0,0x99};
DeviceAddress app = {
  0x28,0x49, 0xD6,0xDA,0x2,0x0,0x0,0x6A};
DeviceAddress tll = {
  0x28,0x2B, 0xD5,0xDA,0x2,0x0,0x0,0x89};
DeviceAddress tbb = {
 0x28, 0x7F,0xBC, 0xDA, 0x2, 0x0,0x0,0x99};
DeviceAddress x11 = {
0x28,0xE5,0x0,0x9F,0x3,0x0,0x0,0x43};
DeviceAddress x22 = {
0x28,0xFE,0xAC,0xDA,0x2,0x0,0x0,0x38};
DeviceAddress x33 = {
0x28,0xF4,0x52,0xCB,0x2,0x0,0x0,0x44};

void loop{
  kp = sensors.getTempC (kpp);
  kg = sensors.getTempC (kgg);
  sp = sensors.getTempC (spp);
  sg = sensors.getTempC (sgg);
  ap = sensors.getTempC (app);
  tl = sensors.getTempC (tll);
  tb = sensors.getTempC (tbb);
  x2 = sensors.getTempC (x11);
  x4 = sensors.getTempC (x22);
  x3 = sensors.getTempC (x33);
 
  sensors.requestTemperatures();
}

Any ideas ? i can make external clock i guess, if it's needed some delays or so.

I have never had any success using parasite mode, even over short distances and clearly, 10m is causing you issues. Is there any reason you can't run another wire with power?

What are you measuring that changes so fast that you can't have delays (not that I'm advocating them) - is the DS18B20 responsive enough to measure rapid fluctuations accurately?

An array or two and a for loop would make your sketch rather simpler.

Edit: spelling

sorry, i wasn't clear, actually my sensors is connected in this way: http://jonis.eu/forumas/download/file.php?id=62
so it's not called parasite mode, i guess.

In parasite mode they sensors do not have a constant 5V connection.

You might need some pull up resistors, like described here for I2C - Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino - (search pull up on this page)

I already have pull-up resistors.. I think i should use some crc check, or longer reading period, i don't know. I am using 4.7k resistors, should i try to use 2.2k instead of 4.7k ?

The problem is probably caused by the capacitance of the long cable. Try a lower value pullup resistor, but not below 1K.

Do i really need 2.2k resistor if connected them in this mode: http://chipenable.ru/images/stories/articles/DS18B20/1-podkluchenie-ds18b20-ds18s20.png
That's not parasite mode, i though it's useful 2.2k only for parasite mode.

A lower value pullup resistor will help when the capacitance of the line is high due to its length.

Okay, thank you, i will try it :slight_smile: Don't you think i could just change something in code for better results ? or it's fair good ?

No. The DQ pin needs a pullup and the wire characteristics may dictate use of a stronger pullup value (Lower Resistance) to overcome the cable "losses".

ignas:
Okay, thank you, i will try it :slight_smile: Don't you think i could just change something in code for better results ? or it's fair good ?

@ignas did you find out a solution for you problem? I'm also having the -127 reading.

I have this issue as well. I use parasite mode as well. the sensor works fine for half an hour then dead. no matter I reboot the arduino or disconnect and reconnect the sensor, it dose not back online. I have to change the pin in the program and re-upload it to get it to work for another half an hour.