I'm using the raspberry pi (model B) with the DS18B20 to read temperature. I connected 9 sensors through the 1wire (port 4), however I'm having a few sensors with a weird problem.

The sensors disappear and come back in a few minutes, also I have removed some sensors but nothing change.

I'm using the normal connection (VCC with 4.7k through the line data and GND/VCC 3.3v (external supply) connected, each sensor has around 3m of cable.

Does any one had the same problem?

I'm thinking to buy the i2c -> 1wire (https://www.abelectronics.co.uk/products/3/Raspberry-Pi/27/29/1-Wire-Pi) does any one recommend it?

Is there any other solution to read temperature using 9 digital sensors?

  • 1
    9 cables at 3 meters each I would assume electrical problem caused by the wire net acting as a big capacitor. Also using parasitic power could cause this kind of behaviour.
    – Simson
    Sep 9 '14 at 7:01
  • Does it work with just 1? If so, try keep adding them one at a time until it doesn't work.
    – Craig
    Sep 9 '14 at 16:39
  • You made two mistakes: First, your onewire needs to be a bus, not a star topology. Make lobes by using free wires in the cable. Second, a 4.7k pullup to 3.3V isn't sufficient to power an DS18B20 during the temperature conversion. It needs up to 1mA, so your pullup to 3.3V should be 1.5k (or you need the strong pullup, which can be hard to debug whether it's working.)
    – Janka
    Dec 6 '16 at 4:01
  • @Janka As I understood the sensors are not bus powered, so your second argument is obsolete. But indeed the 4,7k could be too much, considering Simsons point: Maybe the net is too slow with this pullup.
    – Philippos
    Mar 20 '17 at 16:36
  • @Canela For very long nets I would suggest using differential instead of single-ended transmission. You can use it with different busses, aber the downside is that you'd need converters for each sensor. Maybe you can succeed without, but I see no way around looking at the signal with an oscilloscope. Meters of cables, reflections everywhere will result in noise on the bus. Proper termination at the endpoints could reduce noise enough to make it work (but you can't kill all reflection with your topology). But this is the wrong forum for this stuff
    – Philippos
    Mar 20 '17 at 16:44

this is answered here.

the ideal way to read multiple sensor is use I2C sensors.

this is the only way you can chain multiple sensors together or you can use analog sensors but they will take lot of analog pins but i2c will use only 2 lines. lets say you are using Pi2/3, then i will suggest get a raspberry Pi hat which has I2C port so that you can connect all your i2c devices with Pi within seconds and it will make sure your hardware is correct.

now you have the Pi with an I2C adpter let move on the sensor part. TI,AD,NXP,freescale and lot of other companies make temp sensor with I2C but you want to connect more then one sensor so there are two options.

get 6 different different I2C sensors with different different I2C address, if you have two sensors with same address it wont work. you can get sensors with address line and just change address and you can connect them with Pi without any address conflict. i will suggest use this TMP 100 sensor i prefer this one because it has 2 address line with floating address line support so you can hookup 6 sensor with one i2c line. there are advantage of using same sensors are that you dont have to read 6 datasheet to write your code you will need to study one datasheet and write the code its way easy. if your all sensors are same then you will have better results to compare.

  • I don't understand why I2C should be better for this purpose than 1-wire. All problems with signal integrity and delay apply to both synchronous single-ended busses as well. The protocol of 1-wire with the unique IDs is even better for large numbers of sensors. There are scenarios where I2C fits clearly better, but why here?
    – Philippos
    Mar 20 '17 at 16:32

The problem here is that 1-wire uses a parasitic supply from the data line. This means there is a fanout limit, or max number of devices on the bus that is determined by the total current draw of your devices and proportional the pull-up resistor and the supply voltage.

In this case, your system has a maximum fanout of 7 devices (calculated below), and you are powering 9, the best solution is to decrease the value of the pull-up resistor to say, 1k

Additionally, it is prefered with 1-wire to use a daisy chain and not long parallel wires. Using 3m cables to distant sensors adds significant capacitance to the line. To compensate this, a smaller pull-up resistor can be used as well.

How to calculate the fanout of 1-wire bus

Each device, during phantom power phase, will draw a maximum of 15uA. Therefore for our estimates, the total current draw is the number of devices times 15uA.

The the maximum fanout is when the total current reduces the supply voltage to <2.8V through our Pull-Up resistor.



If we take your 3.3V supply with 4.7K, we can calculate

FANOUT=(3.3-2.8)/(4.7)*1/(0.015)= 7

Which means 9 devices is beyond the fan-out limit of the bus in your configuration.

The best option here is to reduce the value of the P-U resistor to 1k in order to achieve a limit of 30 devices on the 1-wire bus. This will increase the consumption of the 1-wire bus from ~1mA to ~5ma, not very significant in powered applications.

More Concerns

When running sensors on long parallel cables, then there is additional capacitance on the line, this will reduce the maximum speed of communication determined by the slew rate . In the worst case If you have 10nF for parasitic supply storage, and say 10nF more with 9 parallel cables at 3m each (using ~100pf/ft), with 4.7K, we calculate T=1/R*C=100uS, which means that the maximum rate of communication on a bus is 5KHZ or less. .

This is the worst case, so you may get away with faster rates, but you will have intermittent connection occasionally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.