notholmen
Posts: 31
Joined: Tue Dec 25, 2012 10:10 am

1-wire troubles

Sat Jul 04, 2015 12:19 pm

Hi, Hello!

Some assistance needed.
I'm using Pi B+ and have followed this http://www.modmypi.com/blog/ds18b20-one ... spberry-pi guide to connect and read 1-wire directly to the GPIO 4.

Reading my two 1-wire DS18B20 sensors work great when the sensors are attached with a short cables.
But... This is when the troubles start.
When attaching a cable to the same sensor and read it further away it stops working and I get strange results.

The cable is about 30m dug down and hard to optically check. I have made readings with multi-meter and everything checks out. Resistance checked.

I have only two sensors attached.
Results with one sensor without cable and one with cable:

Code: Select all

robban@hemulen /sys/bus/w1/devices $ ls
28-58400000b4ac  28-98400000b4ac  28-d8400000b4ac  w1_bus_master1
robban@hemulen /sys/bus/w1/devices $ cat 28-58400000b4ac/
driver/    id         name       subsystem/ uevent     w1_slave   
robban@hemulen /sys/bus/w1/devices $ cat 28-58400000b4ac/w1_slave 
00 00 00 00 00 00 00 00 00 : crc=00 YES
00 00 00 00 00 00 00 00 00 t=0
robban@hemulen /sys/bus/w1/devices $ cat 28-98400000b4ac/w1_slave 
00 00 00 00 00 00 00 00 00 : crc=00 YES
00 00 00 00 00 00 00 00 00 t=0
robban@hemulen /sys/bus/w1/devices $ cat 28-d8400000b4ac/w1_slave 
00 00 00 00 00 00 00 00 00 : crc=00 YES
00 00 00 00 00 00 00 00 00 t=0
robban@hemulen /sys/bus/w1/devices $ 
The sensor ID's come, disappear and change. I can't get the sensor data out of them.
I have heard that this may be a sign of sensors not attached correctly, but I'm confident that the connections are good. The sensors are the same individual sensors that just worked without the long cable.

Again, after removing the cable sensor I can read everything like usual:

Code: Select all

robban@hemulen /sys/bus/w1/devices $ cat 28-00000733b4ac/w1_slave 
7e 01 4b 46 7f ff 02 10 25 : crc=25 YES
7e 01 4b 46 7f ff 02 10 25 t=23875
Is there a limit to how long cable I can attach with this method?
Any ideas what is going sideways here? Everything is the same but the cable.
Before I was able to read the sensor with an i2c add-on-board which I'm afraid is broken after a thunders storm.

notholmen
Posts: 31
Joined: Tue Dec 25, 2012 10:10 am

Re: 1-wire troubles

Sat Jul 04, 2015 12:58 pm

Just some updates:
Having both plugged in and trying to read the sensor the logs give me:

Code: Select all

Jul  4 14:54:25 hemulen kernel: [1131311.735899] w1_slave_driver 28-00000002b4ac: Read failed CRC check
Jul  4 14:54:28 hemulen kernel: [1131315.185818] w1_slave_driver 28-00000733b4ac: Read failed CRC check
Jul  4 14:54:31 hemulen kernel: [1131317.566022] w1_slave_driver 28-00000002b4ac: Read failed CRC check
Jul  4 14:54:33 hemulen kernel: [1131319.795909] w1_slave_driver 28-00000733b4ac: Read failed CRC check
Then after a while it disappears

My two sensor ID's are 28-00000733b4ac and 28-000007340c73.

ghp
Posts: 1543
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: 1-wire troubles

Sat Jul 04, 2015 2:56 pm

Hello, 30 m are a challenge. Do you use 3-wire connection (gnd, 3.3V, data) ? In this case, add a small cap of 0.1uF close to the device (3.3, gnd) to minimize supply voltage deviations. Try to use a smaller pullup value than the 4k7 defined, try 2k2 or even 1k. This reduces the effects by cable capacitance.

Regards,
Gerhard

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 1-wire troubles

Sat Jul 04, 2015 3:13 pm

What kind of cable ? it is shielded ? twisted pair ? wire gauge ?

There is a problem with twisted pair cable . They are very good for noise immunity when you have a differential signal but they also add a lot of capacitance to the system.

A shielded cable also increase the capacitance of the cable.


If you are using a old telephone cable with 2 twisted pair. Use one pair for power and short the other pair wires together and use it for the data line. Or use one of the wire to ground instead of shorting them together.

Gauge is important since it will add resistance to the cable and the with capacitance effect it will reduce the rise and fall time.

What is your pull up resistor ? Decreasing the resistance value reduce the effect of the capacitance.

On long cable there is also a problem with echo signal.

Some stuff you could try.

1 - Decrease the resistance value . Put two 4k7 resistor on each end of the cable. This will increase the frequency response. (F = 1 / 2πRC). Or one single 2K2 resistor at the end of the line.

2 - Put 5V to power the DS18B20. But bring the 3.3V for the pull up resistor. In practice a 4k7 resistor with a 5V pull up is not a problem since the leakage current (5v-3.3V)/4k7 = 360µA won't increase the 3.3V power bus. The GPIO internal diode protection will redirect the current to the 3.3V and the regulator will deal with it.

3 - Add a small capacitor at the end between the GND and power to remove any noise. ~0.1µF

4 - Add a ferrite on the cable to remove any high frequency signal .

5 - Add a small resistance in serie with your sensor data line ,~150Ω to match impedance. This also help by preventing high spike surge when you data line toggle.

This is some of the stuff you could try. But Normally , like ghp said, reducing the pull-up resistor is the clue.

KombuchaKing
Posts: 8
Joined: Mon Apr 20, 2015 8:13 pm

Re: 1-wire troubles

Sat Jul 04, 2015 4:53 pm

2 - Put 5V to power the DS18B20. But bring the 3.3V for the pull up resistor. In practice a 4k7 resistor with a 5V pull up is not a problem since the leakage current (5v-3.3V)/4k7 = 360µA won't increase the 3.3V power bus. The GPIO internal diode protection will redirect the current to the 3.3V and the regulator will deal with it.

Could you elaborate on this a bit more? I am having similar problems and would like to attempt this. What do you mean by "bringing the 3.3V for the pull up resistor"?

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 1-wire troubles

Sat Jul 04, 2015 7:30 pm

This is a standard cmos logic gate.
Image

You will notice that the gate is protected with 2 diodes. one to GND and one to VDD.

So if you put 5V directly to the gate you will increase the VDD voltage, which is 3.3V. So you could possibly damage anything on the 3.3V. Good chance that you will blew the protection diode and render that GPIO not operational but it could be worse.

The point is that you could have some current passing to the protection diode until the 3.3V regulator can't stabilize the voltage. Normally a couple of mA won't do a thing but higher than that is taking risk. 360µA on one GPIO is not bad but not on all GPIO.

KombuchaKing
Posts: 8
Joined: Mon Apr 20, 2015 8:13 pm

Re: 1-wire troubles

Sat Jul 04, 2015 7:51 pm

Forgive me but my expertise is not electronics and circuitry.

I have four sensors consolidated to three female jumper cables and these are connected to the pi; 5V, GND, and GPIO4. in this setup, where would the 3.3V pullup be incorporated?

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 1-wire troubles

Sat Jul 04, 2015 8:22 pm

It's not just the pull up resistor to consider but everything. What kind of cable, The total capacitance of the cable, Twisted pair , shield , bus or star configuration, electromagnetic noise, distance of the cable, lightning protection, etc..

The pull up need to be near the sensor. Sometimes it is better to have 2 pull up resistor on each end.

So try the default 4K7 , if it doesn't work try 2K. With 5V don't go lower for the total pull up resistor.

I'm not an expert on 1 wire but I never find that protocol rock solid for long distance, (> 5 meters). This why I use RS-485 for long distance. Way faster and 1000 meters better.

ghp
Posts: 1543
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: 1-wire troubles

Sat Jul 04, 2015 8:30 pm

connection.jpg
connection.jpg (27.89 KiB) Viewed 4095 times
Hopefully as clear as needed. If you already power your sensors by 5V, then the pullup (here 1k) goes to 3.3V in order to protect the precious GPIO.

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 1-wire troubles

Sat Jul 04, 2015 8:49 pm

In my 40 years of electronic I never burn a gate with 2 ma of current passing by. Except maybe when I design a 35KV power supply but that power supply was not connected to any electronic device.

You will have to show me how to burn one cmos junction with 2 ma of current. Like everything in electronic heat is the issue
2ma at 1.7V won't create to much heat but 5V with no resistor will!

KombuchaKing
Posts: 8
Joined: Mon Apr 20, 2015 8:13 pm

Re: 1-wire troubles

Sat Jul 04, 2015 9:01 pm

So the connecting of the 3.3V through a resistor does what exactly?

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 1-wire troubles

Sat Jul 04, 2015 9:10 pm

The DS18B20 is open collector. This means it could put the data signal low put not high.

it is acting like a switch to ground. To put the data high a pull up is needed.

You need a pull up resistor to set the voltage high. A longer cable had a increase in capacitance value and the rise time will be lower. to prevent the longer rise time you need to decrease the resistor value but there is a limit on how much you could decrease it.

KombuchaKing
Posts: 8
Joined: Mon Apr 20, 2015 8:13 pm

Re: 1-wire troubles

Sun Jul 05, 2015 3:37 pm

So would the simplest method be to obtain a sample of resistors of varying resistance and try them out?

ghp
Posts: 1543
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: 1-wire troubles

Sun Jul 05, 2015 4:53 pm

Hello,
try starting with 1k Ohm. If you got 4k7 Ohm resistors with your DS18B20-sensors, then apply them in parallel (3 of 4k7 in parallel are 1k56). Try also to apply 0.1uF capacitors close to the sensors on the power supply.
Regards,
Gerhard

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 1-wire troubles

Sun Jul 05, 2015 7:20 pm

I.M.O. Cable is maybe to most important part. If it doesn't work with a 2K resistor you should check the type of cable you have.

I just took 1 spare cable that I got, 30 meters of 22 solid awg unshielded, untwisted 4 wires made for telephone communication. I hook up 2 DS18B20 sensors on each ends. Took a 4k7 resistor pull up at the farthest end of the PI and everything works fine.

So the thing is what type of cable do you have. If you have multiple drop point What do you do with the ground. Be aware of ground loop problem.

Like I said shielded and twisted pair cable have way more capacitance effect and that could be a problem. The wire gage also could be problematic.

So it is not just the resistor to check. Your cable is maybe to most important part!

boyoh
Posts: 1487
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: 1-wire troubles

Sun Jul 05, 2015 11:31 pm

notholmen wrote:Hi, Hello!

Some assistance needed.
I'm using Pi B+ and have followed this http://www.modmypi.com/blog/ds18b20-one ... spberry-pi guide to connect and read 1-wire directly to the GPIO 4.

Reading my two 1-wire DS18B20 sensors work great when the sensors are attached with a short cables.
But... This is when the troubles start.
When attaching a cable to the same sensor and read it further away it stops working and I get strange results.

The cable is about 30m dug down and hard to optically check. I have made readings with multi-meter and everything checks out. Resistance checked.

I have only two sensors attached.
Results with one sensor without cable and one with cable:

Code: Select all

robban@hemulen /sys/bus/w1/devices $ ls
28-58400000b4ac  28-98400000b4ac  28-d8400000b4ac  w1_bus_master1
robban@hemulen /sys/bus/w1/devices $ cat 28-58400000b4ac/
driver/    id         name       subsystem/ uevent     w1_slave   
robban@hemulen /sys/bus/w1/devices $ cat 28-58400000b4ac/w1_slave 
00 00 00 00 00 00 00 00 00 : crc=00 YES
00 00 00 00 00 00 00 00 00 t=0
robban@hemulen /sys/bus/w1/devices $ cat 28-98400000b4ac/w1_slave 
00 00 00 00 00 00 00 00 00 : crc=00 YES
00 00 00 00 00 00 00 00 00 t=0
robban@hemulen /sys/bus/w1/devices $ cat 28-d8400000b4ac/w1_slave 
00 00 00 00 00 00 00 00 00 : crc=00 YES
00 00 00 00 00 00 00 00 00 t=0
robban@hemulen /sys/bus/w1/devices $ 
The sensor ID's come, disappear and change. I can't get the sensor data out of them.
I have heard that this may be a sign of sensors not attached correctly, but I'm confident that the connections are good. The sensors are the same individual sensors that just worked without the long cable.

Again, after removing the cable sensor I can read everything like usual:

Code: Select all

robban@hemulen /sys/bus/w1/devices $ cat 28-00000733b4ac/w1_slave 
7e 01 4b 46 7f ff 02 10 25 : crc=25 YES
7e 01 4b 46 7f ff 02 10 25 t=23875
Is there a limit to how long cable I can attach with this method?
Any ideas what is going sideways here? Everything is the same but the cable.
Before I was able to read the sensor with an i2c add-on-board which I'm afraid is broken after a thunders storm.
I think lowering the pull up resistor might
be the wrong approach, making the in/put
impedance to low, this might divide the
the in/put signal out of exsistance,
You could do a bit of experimental work
Try a 15k preset, and adjust until you
get the correct value, This might over come
the signal lose , due to the long cable run.
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 1-wire troubles

Sun Jul 05, 2015 11:40 pm

If you know somebody with an oscilloscope you could figure out a lot !

What is the Idle voltage with the pull up. What is the rising and falling slope and what is the 0V at the PI and at the sensor.
Also is there an echo which perturbates your signal.

You didn't tell us what kind of cable you are using. This very important to know.

Are they twisted pair, shielded , wire gage ? If they are twisted pair which wire go to which signal?

You should look beyond the resistor.

Daniel

ghp
Posts: 1543
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: 1-wire troubles

Mon Jul 06, 2015 12:45 pm

Hello, think it is time to check the cable. This does not reveal capacitance problems, but broken wires or connected wires can be found.
With a led (a simple one, red, green, yellow, but no blue or white) and a 1k-resistor, make the following setup. Disconnect GPIO 4, disconnect all sensors, and attach the led as follows:
wire_led.png
wire_led.png (5.16 KiB) Viewed 3907 times
Check the led and series resistor first between 3.3V and GND on pi side first. LED should be bright.
Then look for the remote end of the cable.
Between (3) and (4), the led lights up, as the pullup on pi side and the series resistor are connecting it to 3.3V. (2)-(4) is bright, (1)-(4) even brighter. To doublecheck the connections, remove the pullup on pi side and (3)-(4) should not light up.
If the led does not light up, perhaps you switched the wires or one of them is broken.

Or do you own a multimeter, then just measure voltages. But disconnect sensors and GPIO4 too before.

Regards,
Gerhard

KombuchaKing
Posts: 8
Joined: Mon Apr 20, 2015 8:13 pm

Re: 1-wire troubles

Tue Jul 07, 2015 9:59 pm

I am using 22 guage doorbell wire.
I have 12 wires, each about a foot long, that are connected to 4 screw terminal blocks and these all go to a circuit board. They are soldered to the underside of 4 six pin headers and I have 3 jumper cables coming from each of the headers. These jumper wires are then consolidated to 3 connections with a 4k7 ohm resistor between vcc and data. These three lines are then connected to the pi via gpio.

I am not savvy with electronics or computer jargon (I am a chemist) so, please, a simple response would be immensely appreciated.

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 1-wire troubles

Wed Jul 08, 2015 1:57 am

@KombuchaKing
12 wires , 1 foot long
Look messy! Maybe a picture will help!
How many sensors, five ?
The 4K7 should work!
What is your problem. Does it work. Did you try with one sensor first and after that adding one at the times.
Only one resistor for the full project is needed.

Return to “Interfacing (DSI, CSI, I2C, etc.)”