7
\$\begingroup\$

I have been playing around with some 1-Wire components and got these questions

schematic

simulate this circuit – Schematic created using CircuitLab

  1. Can I break anything if I forget the 4.7 k resistor ________?
  2. Does it have to be 4.7k _________?

Came across an Adafruit lib that used 10 k but changing between the two resistors (4.7k and 10k) didn't seem to influence the readout. But is it the lib that defines what resistor size I should use or should it just be between an interval..?

I'm a newbie when it comes to electronics and right now I'm just learning-by-doing. Reading the theory behind thing doesn't help me that much since I don't understand half of the terms used..

\$\endgroup\$
1

5 Answers 5

11
\$\begingroup\$

1) "Can I break anything if I forget the 4.7 k resistor?"

No. You might damage the external device if you drive the Arduino output active HIGH instead of high-impedance. Usually the libraries take care of this.

digitalWrite( 1 , HIGH ); pinMode( 1 , OUTPUT );  // Bad, active HIGH
digitalWrite( 1 , LOW );  pinMode( 1 , INPUT );   // Good, high impedance.

2) "Does it have to be 4.7k"?

No. Check the datasheet for details and considerations. Depending on speed and power requirements pull up resistors usually vary from 1kΩ to 100kΩ. Your 4k7 is about as good as my usual 10kΩ.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ My preferred one-wire implementation is to connect a resistor to an output-only port rather than to VDD, and use a second port pin as input only with a second resistor on it to protect against ESD. When wired in that fashion, nothing the processor can do will risk damaging anything. \$\endgroup\$
    – supercat
    Commented Dec 13, 2014 at 0:22
6
\$\begingroup\$

1-Wire devices have open drain outputs so the pullup is required to maintain a logic "1" when the bus is not driven, just like with I2C. The reason for using open drain outputs is also the same as in I2C: to allow multiple devices on the same bus (see also this question).

The value of 4.7K is most likely chosen to ensure sufficiently small rise time with common cable lengths. The real parameter that governs the maximum allowed resistor value is rise time of the signal, determined by bus resistance and capacitance.

You won't fry anything if you forget the resistor (as long as you don't drive the bus high from your master device) but your 1-wire bus isn't going to work except by some accident.

All of this is thoroughly documented in Maxim literature including datasheets and app notes.

\$\endgroup\$
5
\$\begingroup\$

No, it doesn't have to be 4.7k, the original spec said "about 5k", 4.7k is just a commonly available value in that range. There's an article on driving 1-wire temperature sensors with just the internal resistor on the Arduino (and I can confirm it works on the 1.8k resistor of a Pi too).

Basically, the master (microcontroller) pulls the wire low to ask a slave device to give a readout. The slave waits a predetermined length of time after the master pulls the line low to reply, by also pulling the line low. The master then checks the voltage on the line to determine 0 or 1.

The upper limit

This gives us the upper limit on the resistance that works. It needs to be low enough, given the capacitance of the wires and attached sensors, to bring the voltage on the line high before the host checks the value. For a single device, and a short length of wire, 100k is likely low enough, 50k is low enough for 3 devices and a meter of wire (or thereabouts), or 1 device and 10m of wire. Also, you can cheat and attach a second pin in pull-up mode if you need more power delivery.

That assumes you are running a dedicated power line. Using it in parasitic power mode you have to account for the power draw of the device on the other end, which will require looking at the applicable data sheets.

The Lower Limit

As for the lower limit, there isn't one for restoring the high signal, the moment the line is quiet, it's safe to drive it high. The problem comes if you drive it high while one of the slave devices is trying to "talk", the amps you put in through your pull-up resistor must be drained by the slave, depending on the internal resistance of the slave while it's pulling the line low, and its thermal limits, it will either cook the slave, or fail to pull the signal low. Which failure mode you get, and the minimum safe resistance, can usually be be figured out from the slave device's spec sheet. As a general rule, I usually aim to keep those sorts of components in the <10mA range (assuming they have 0 internal resistance while pulling the line low). This means the minimum resistance you want on your pull-up (assuming 5V drive) is 500Ω. It's likely reasonably safe to go a bit higher, depending on ambient temperature, and how often the slave "talks", but for temperature sensors, you will skew your reading if you feed enough current through the sensor that it warms up.

Leaving the resistor out

If you leave it out and use the internal resistor, you'll be fine with a handful of components on a small circuit. If you leave it out and drive the line high directly, you don't get 0Ω, but you'll get a low enough resistance that you'll at the very least heat things up (the master when it pulls the line low, and whichever slaves try to respond). This almost certainly will shorten the life of your components. If you leave it out and don't connect anything to pull the voltage up, the circuit just won't work.

A note on parasitic power

It's possible to use one-wire devices without a dedicated power wire. Just signal and ground. To do this, the signal wire must be held high enough of the time for the devices attached to fill internal capacitors to allow them to function for the breif periods of time when the data line is pulled low. Of course, this loads the data line and will pull it lower the more devices which are using parasitic power. You can compensate for this by using a lower rated resistor. You can also drive the line high without the resistor, by putting the master's communication pin in voltage output mode. By specification, the slaves only speak after the master speaks to them, and only for a very breif duration. This means it is safe for the master to switch from output mode on the signal pin to input mode and pull it low to tell a slave to respond. Then the pull up resistor will restore the voltage on the data line and the slave will either pull it down in reply, or not. The master must wait until all slaves are done talking before once again driving the line high. This doesn't get you away from needing something for a pull-up resistor, as something needs to pull the line high while the slave is talking. (Well, you could drive the line high from the master by pulsing it, if the microcontroller's clock speed and circuit's capacitance are high enough, but I suspect it would be incredibly fragile with a terrible failure mode).

Shoot, forgot to include the link to the article mentioned above: https://wp.josh.com/2014/06/23/no-external-pull-up-needed-for-ds18b20-temp-sensor/

\$\endgroup\$
6
  • \$\begingroup\$ If the data line is directly connected to +V with no resistor, in addition to making the master very unhappy when it tries to pull the line low (read: burning out the NPN or NMOS of its output stage), the line will never actually go low, and you don't have to worry about burning the slaves because they will never have a pulse to respond to. \$\endgroup\$
    – Ben Voigt
    Commented Sep 19, 2022 at 22:17
  • \$\begingroup\$ You can't have "no resistor", you can have "no discrete resistor", the wires you use will have some resistance. If the slave sees the low voltage pulse and tries to respond will depend on the relative resistances of the logical wires, the maximum current of your supply before it dips, and so on. This assumes you short data to +V rather than have the controller drive the data pin high directly. In that case, the contoller will be fine, because it will drive the pin low, thereby ceasing driving the pin high (at least till the slave replies). Also, you could use some VRM other than a resistor. \$\endgroup\$
    – Perkins
    Commented Sep 22, 2022 at 16:59
  • \$\begingroup\$ I agree that you can't have "no resistance". A "resistor" is an intentional resistance, whether that's a discrete component or one portion of a bussed resistor or other collection of components, and contrasts with "parasitic resistance" which means any unintentional resistance, whether it's effective output impedance of a source, resistance of PCB traces, resistance of component leads, etc. Your analysis is mistaken in that it focuses on wire resistance. The dominant parasitic resistance will be in the IC output driver -- no low voltage pulse will ever get as far as the pin. \$\endgroup\$
    – Ben Voigt
    Commented Sep 22, 2022 at 17:18
  • \$\begingroup\$ So when you put your temperature sensor at the other end of 1km of 40ga speaker wire, and the pull up source 10km further down the line, it will magically die because you didn't include an intentional resistor, got it. I have no doubt your analysis is correct for the circuit you envision, but I believe you are assuming things not stated incorectly. Anyway, arguing solves nothing. I have a "spare" arduino I can risk burning out, and a scope. Assuming I don't wake up sick tomorrow (bad odds, c19 sucks), I'll see exactly how an arduino fares in each of the scenarios above. \$\endgroup\$
    – Perkins
    Commented Sep 24, 2022 at 3:57
  • \$\begingroup\$ In that scenario, the parasitic resistance in the output driver is probably still the most important, but now measuring at the pin you'll see significant delay in the reflections before the voltage settles at its final value. So you'd have to consider your speaker wire as a transmission line, with characteristic impedance and delay. I only assumed that the question involved something that could reasonably be described as "a wire", and your 10km transmission line is not a wire. \$\endgroup\$
    – Ben Voigt
    Commented Sep 26, 2022 at 0:05
3
\$\begingroup\$

If you replace the resistor with a short you can potentially damage D1, if it ever tries to output '0'. If you don't have the resistor at all, there is no power supply to the 1-wire device.

It's a "pullup" resistor. Its exact value isn't important, there is probably a broad range in which it will work.

\$\endgroup\$
8
  • \$\begingroup\$ How can you damage D1 by leaving out the resistor?? \$\endgroup\$ Commented Mar 24, 2013 at 11:22
  • \$\begingroup\$ If you drive it low while it's connected to 5V? \$\endgroup\$
    – pjc50
    Commented Mar 24, 2013 at 13:32
  • \$\begingroup\$ @pjc50 - Can you edit to clarify this? I assumed the resistor not being there means the pin is not connected to anything (which I think many others might too) as opposed to a short between the pin and 5V. \$\endgroup\$
    – Oli Glaser
    Commented Mar 24, 2013 at 13:51
  • \$\begingroup\$ I removed my downvote after the clarificaion. But note that if you remove the resistor, there is still power to the 1-wire device via the +5V connection. \$\endgroup\$ Commented Mar 24, 2013 at 14:49
  • \$\begingroup\$ The +5V isn't connected to the 1-wire device (not shown), only data and ground are. \$\endgroup\$
    – pjc50
    Commented Mar 24, 2013 at 15:02
0
\$\begingroup\$

I did implement one wire protocol a while ago by bit banging 1-wire protocol with a GPIO pin. I can't recollect the exact value of resistor used but it uses some resistor, probably 4.7KΩ, to pull up the voltage to 5V because the bus operates on parasitic power.All slave devices operate on parasitic power drawn from the 1-wire bus if they require it. If you dont use the resistor, the bus would be logically low.Even if you use a incorrect value of the resistor nothing may happen with just a 5V power supply which you are using from the board.The only outcome seems that bus would be at a lower level than 5V which is probably not enough for the master or a slave to interpret that the bus is idle. A 5V level on bus means that the bus is idle. The pins of the MCU are in open drain mode which is why you need a pull up resistor to keep the bus at 5V at all times except when the MCU or a slave is controlling the bus. Read about open drain and push-pull modes of GPIO pins of your MCU.

\$\endgroup\$
4
  • \$\begingroup\$ 1-wire allows for, but does not require, parasitic power. Even when not using parasitic power, a resistor is needed. \$\endgroup\$
    – Perkins
    Commented Sep 22, 2022 at 16:43
  • \$\begingroup\$ Parasitic power is needed for slaves which require it. Otherwise its not required. \$\endgroup\$
    – Amit M
    Commented Sep 22, 2022 at 16:49
  • \$\begingroup\$ I believe the master is not required to supply any particular amount of parasitic power, however. So it's theoretically possible that the master's pull-up resistor could be too large for a device to be powered from the bus. \$\endgroup\$
    – Hearth
    Commented Sep 22, 2022 at 17:06
  • \$\begingroup\$ Most 1-wire devices like temperature sensors seem to operate at 3.3V or 5V. Its either one of these. Even if the slaves dont draw power, the bus is still kept high when idle. This requires 4V. ti.com/lit/ds/symlink/lm35.pdf . There seem four voltage rages for 1-wrie devices. as given here maximintegrated.com/en/design/technical-documents/tutorials/1/…. I don't remember which voltage it was. Probably 3.3V for LM35 temperature sensor. \$\endgroup\$
    – Amit M
    Commented Sep 22, 2022 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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