The I2C spec allows for the data line to have a maximum of 400pF to ground. You don't show your wiring, but if the data is in a twisted pair with ground, then your data is likely being corrupted.
The capacitance of CAT-5E is 52pF per meter, so at 50-meters the cable will add way more than the 400pF max, so I2C should deliver erratic data.
If you're using the DS18B20 parasitic power mode, I'd strongly recommend supplying 5 V to the DS18B20 via another twisted pair of your cable (both ground wires connected at both ends).
I'd try also using a 2.4 k Ohm pullup at both the Arduino and DS18B20 at both ends of the cable.
terryking228:
This is unusual; the data is digital, as mentioned.
Yes, expected -127 and I'm getting it occasionally.
terryking228:
If you read the data 100 times is it consistent, or changing values??
Here is a log for last 2 hours (10 mins interval):
13.19
13.63
13.75
13.94
14.19
14.25
13.63
14.00
13.06
12.94
12.81
13.88
13.56
14.19
(actual air temp is around +7 (+-0.5)
terryking228:
Does a local-connected DS18B20 give right results with exact same code???
Yes, I confirm, that I checked the sensor connected directly to arduino without long cable, but with 4.7k pullup and it was working well.
I read a lot on various Arduino forums regarding DS18 running on long cables.
I've read to:
a) avoid parasitic mode
b) use twisted pair cat5e (5vcc/ground, data/ground pairs)
c) use 2k pullup resistor on Arduino side
I didn't read about DS18 shifting result by some value.. Strange. Shound't it just return -127?
Sensors are from China, not original from from MAxim.
Data are digital and there is a checksum so I have strong doubts that the problem is in a cable. No way. It is something with a sensor.
Try another sensor and the best is the genuine one as was mentioned.
d187:
I read a lot on various Arduino forums regarding DS18 running on long cables.
I've read to:
a) avoid parasitic mode
b) use twisted pair cat5e (5vcc/ground, data/ground pairs)
c) use 2k pullup resistor on Arduino side
I didn't read about DS18 shifting result by some value.. Strange. Shound't it just return -127?
Sensors are from China, not original from from MAxim.
B is incorrect. Don't use the pairs as pairs. Put the same signal on both paired wires. 5V/5V, Gnd/Gnd and Data/Data.
For C, it is not totally wrong but I would expect better performance with the correct 4.7K pullup close to the sensor. But usually you have many sensors on one cable so you can't do that.
Yes, you would expect a checksum error (-127) instead of an erroneous value. Maybe something else is wrong?