1

I am having a DS18B20 temperature sensor in a 3-wire setup (using a pullup resistor of 4.7 kOhm from data to 3.3v) on a Raspberry Pi model B+. It always return the value as shown below when using cat w1_slave to get the data:

50 05 4b 46 7f ff 0c 10 1c : crc=1c YES
50 05 4b 46 7f ff 0c 10 1c t=85000

It is not the problem of a particular DS18B20 as I have replaced it with another one and get the same result.

I also tried to unplug the three jumper wires from the Raspberry Pi header and connect into an Arduino without touching any circuit or connections on the breadboard, the same circuit works perfectly on my Arduino Pro Mini (3.3v). So it is not the problem in circuitry.

I also tried it on two different Raspberry Pi and get the same result.

The /boot/config.txt is enabled with the setting of dtoverlay=w1-gpio and gpiopin4 is used as default for input (in fact I tried different gpio pin configurations, but the results are the same).

Any one has the similar experience? Am I missing something?

Update

Here is the photo of my breadboard wiring:

enter image description here

As per @joan's comment, I also decided to solder the DS12B18 and the pull up resistor direct to the back of Raspberry Pi header connector to make sure verify that the problem is not due to pure join to connectivity (see the picture), but I get the same result.

enter image description here

9
  • Am I missing something? - yes, in the question you haven't shown where/how you are getting these readings - in arduino-land you not only need 1-wire library to speak to a DS18B20, you also need the DallasTemperature library to communicate with that particular sensor Apr 15, 2017 at 7:19
  • I am afraid it is a problem with the circuitry. Make sure all the joints are good and post a clear photo of your Pi connections.
    – joan
    Apr 15, 2017 at 7:56
  • @Jaromanda, I don't have the problem when using it on Arduino.
    – hcheung
    Apr 16, 2017 at 7:43
  • @joan, the same circuitry plug into an Arduino works perfectly without any problem, therefore it is not the joints and connection on my breadboard.
    – hcheung
    Apr 16, 2017 at 7:46
  • Suit yourself. 85 is returned when there is a communications failure. Communications failure is caused by poor circuitry.
    – joan
    Apr 16, 2017 at 8:07

2 Answers 2

4

As per @Ghanima's suggestion, repost my updated as a separate answer.

I've solved the problem by myself by changing the /boot/config.txt settings from

dtoverlay=w1-gpio

to

dtoverlay=w1-gpio, pullup=on

According to the /boot/overlays/README, the pullup=on would only needed if it is operated in 2-wire parasitic mode. My configuration is clearly not running in parasitic mode, but nevertheless, this seems to solved the problem, and I can get the temperature data consistently and correctly.

Information abstracted from /boot/overlays/REAME

Name:   w1-gpio
Info:   Configures the w1-gpio Onewire interface module.
        Use this overlay if you *don't* need a GPIO to drive an external pullup.
Load:   dtoverlay=w1-gpio,<param>=<val>
Params: gpiopin                 GPIO for I/O (default "4")
        pullup                  Non-zero, "on", or "y" to enable the parasitic
                                power (2-wire, power-on-data) feature

Further update

When I posted my question a year ago, I also had a USB Software-Defined Radio (SDR) plug in the Raspberry Pi along with DS18B21 sensor, the SDR draws a lot of current, by disconnecting the SDR, I'm able to get the temperature reading correctly most of the time, and only occasionally getting a reading of 85000. This suggests that in order for DS18B20 to functional properly, make sure you have stable power supply able to provide 5V@2A.

0
0

I had the same issue but with only one sensor. After a lot of trial and error I finally got it to work when I swapped my 3V3 pin from pin 17 to pin 1. Don't know the reason behind this as both should have the same voltage readings, but whenever I get hold of a voltage meter I will check it out.

Your Answer

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

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