DS18B20 and Raspberry picoW GPIO

Thread Starter

rewIndustry

Joined Feb 4, 2023
30
the following is actually two questions.

according to what i can find on the net, almost everybody is telling me that i need a 4.7k pull up resistor on the data line, when connecting the Dallas Semiconductor One Wire temperature sensor:

https://www.analog.com/media/en/technical-documentation/data-sheets/ds18b20.pdf

admit i am very rusty, been 40 years since i studied these things, but according to my reading of the spec, the sensor pulls 1.5 mA at most on the power pin, and 5 uA at most on the data pin.

am using raspberry picoW in this design, they embed the RP2040 chip:

https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf

i am not using "parasitic power" in my application, and i will not be chaining devices on the data line, there is only one sensor per pico.

according to the RP2040 specs, "Output drive strength can be set to 2mA, 4mA, 8mA or 12mA"

i found one circuit where it appears someone has tested this sensor without an external pull up resistor:

https://robocraze.com/blogs/post/ds18b20-with-raspberry-pi-pico-using-micropython

and i have done the same - i can confirm this works, so far reliably over 48 hours, but i cannot work out if i risk damaging the pico, doing this.

so the first question - is the pico internal GPIO strong enough to handle the DS18B20 DQ line, without an external pull up?

the DS18B20 is currently being powered by a GPIO output pin, connected directly to VDD on the sensor.

it seems that even the minimum GPIO drive on the RP2040 is more than enough to power the DS18B20.

and so my second question is - am i right to believe that a single DS18B20 can safely be powered by one pico GPIO output?


micropython for above:
class DSTemp:

  def __init__ ( self, power_pin, sense_pin, power_ms = 500, sense_ms = 500 ):

    self.power_pin = machine.Pin( power_pin, mode = machine.Pin.OUT, value = 0 )

    self.sense_pin = machine.Pin( sense_pin )

    self.power_ms = power_ms

    self.sense_ms = sense_ms

    self.lock = asyncio.Lock()

    self.state = False


  def active( self, state=True ):

    await self.lock.acquire()

    if self.state != state:

      self.power_pin.value( state )

      if( state ): await asyncio.sleep_ms( self.power_ms )

      self.state = state

    self.lock.release()

    return self.state


  def sensor( self ):

    await self.lock.acquire()

    if self.state:

      ds = ds18x20.DS18X20( onewire.OneWire( self.sense_pin ) )

      roms = ds.scan()

      print( roms )

      ds.convert_temp()

      await asyncio.sleep_ms( self.sense_ms )

      if len(roms):

        pad = ""

        for rom in roms:

          print( hexlify(roms).decode(), ":", "%6.1f" % (ds.read_temp(s)))

          pad = pad + "%.2fC " % ds.read_temp( rom )

      else: pad = "no sensors"

    else: pad = "power is off"

    self.lock.release()

    return pad


and is called as follows:


dsTemp1 = DSTemp( 0, 1 )

await dsTemp1.active()

result = await dsTemp1.sensor()
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,845
hi rewind,
On many sensor devices the signal line output is open circuit Collector/Drain, so a pull-up is needed, I use a 10K.
E
 

Ian Rogers

Joined Dec 12, 2012
1,136
Just refer to the Datasheet... The power requirement states 1.5mA but that could be for the 5v specification. There may well be a voltage convertor inside, but I wouldn't take it for granted.. Also the pullup is the better option... 10k as Eric said will be fine for a single unit on the bus, but you need a stronger pullup every time you add devices to the bus.
The DS range of devices are 3 ~ 5v .
 

MrSalts

Joined Apr 2, 2020
2,767
is the pico internal GPIO strong enough to handle the DS18B20 DQ line, without an external pull up?

The pull-up is not about whether the pico GPIO is "strong enough", the resistor is needed to complete the circuit. A pull up is just needed as part of the I2c protocol. A pull up is not needed if the pins are just used as GPIO so not having a resistor is the default because it is easier to add one if the pin is used for I2c than it is to force a designer to remove a resistor if the pin is used for GPIO.
 

Thread Starter

rewIndustry

Joined Feb 4, 2023
30
thank you everyone for these answers.

however the RP2040 has internal pull up resistors that can be set on the GPIO outputs.

what are these for, if not to complete open collector/drain type logic?
 

Ya’akov

Joined Jan 27, 2019
9,143
thank you everyone for these answers.

however the RP2040 has internal pull up resistors that can be set on the GPIO outputs.

what are these for, if not to complete open collector/drain type logic?
If you are using the internal pull ups then you are using a pull up! You are not running without one…
 

MrSalts

Joined Apr 2, 2020
2,767
If you are using the internal pull ups then you are using a pull up! You are not running without one…
Literally, yes, practically, no.

thank you everyone for these answers.

however the RP2040 has internal pull up resistors that can be set on the GPIO outputs.
It certainly has 50k Ohm internal oull-ups. Those might work for you but the standard for decent speed connections is 4.7k ohms. Good luck. If you have trouble, your next step, will be to add 4.7k to 10k external pull-ups.

what are these for, if not to complete open collector/drain type logic?
they are to allow a push button to be held high until it is pressed and connected to ground, through the pull-up resistor so you can have a logic high, a logic low snd no fear of shorting high to low when the button is pressed.
 
Top