Please add w1-therm kernel module for DS18B20!


It seems that the w1-gpio module already comes with the kernel for the CHIP but not the w1-therm module?!?!

This means we can’t use the popular DS18B20’s temperature sensors.


check out @renzo thread about compiling your own kernel. He got on including all the stuff you need for this temperature chip :slight_smile:

you might downgrade to 4.3 to get it working but it’s possible for you without compiling your own kernel :wink:


seems like there is already what you are searching for :wink:


Yup, but w1-therm should really be in the kernel to start with given that one can’t add it as a module.


I have a DS18B20 working with w1_therm as module.
But I have an issue while booting with the wires connected to the CHIP.
The boot procedure hangs on “WIFI” (cfg80211).
Is this “the reason” why w1_therm should be compiled inside the kernel?



I absolut agree with you but I’m happy that you came up with another kernel for a quick fix :wink:


Yup. If you search around you’ll find reports that if w1-gpio is loaded before w1-therm the latter hangs. So they either both need to be compiled-in or both as modules and loaded in the correct order. Sigh.


I’ve be able to talk to a DS18B20 on a stock Kernel 4.4 board without any special modules. It’s a bit of a hack because you have to parse the bytes yourself. Instructions:

  • Hook up your DS18B20: Black wire to GND, Red wire to VCC_3V3, and yellow wire to LCD-D2. (I assume it won’t work if you are using a LCD.). Add a 4.7K resistor from LCD-D2 to GND.
  • You should see a new directory appear in the /sys/devices/w1_bus_master1/ directory. It should start with “28-”, with a unique ID after that. It automatically refreshes the device list every 10 seconds. Edit the filename below for the ID you found.
  • If you see several and/or changing IDs in that directory, it’s likely you didn’t install a 4.7K pull-up correctly.
  • Create this perl script.
  • Make sure to chmod a+x to make it executable.
  • I put in huge delays to ensure a stable voltage. You could probably trim the delays, but beware that reading too fast can easily corrupt your data.
  • Prints data in degrees C, but probably over-estimating the accuracy, it might be wise to assume the accuracy is only 0.5C.
  • Don’t assume the data is good without checking the CRC. (Exercise left to the reader.)


$file = "/sys/devices/w1_bus_master1/28-0000060f136f/rw";

sub send_command {
  my $cmd = shift;
  my $f;
  open($f, ">", $file) or die "can't open $file: $!";
  binmode($f) or die "can't binmode $file: $!";;
  syswrite($f, $cmd) or die "can't write $file: $!";
  close($f) or die "can't close $file: $!";

sub read_data {
  my $f;
  my $t;
  open($f, "<", $file) or die "can't open $file: $!";
  binmode($f) or die "can't binmode $file: $!";
  sysread($f, $t, 1000);
  close($f) or die "can't close $file: $!";
  return $t;

send_command(chr(0x44)); # Start temp conversion command
send_command(chr(0xbe)); # Read data command
my $ret = read_data();
print unpack("s", substr($ret,0,2))/16; # Grab the first 2 bytes, shift the decimal
print "\n";

Hope this helps someone!


If you reboot your CHIP while the temp sensor is attached, doesn’t it hang during boot?


I can reboot and power cycle just fine. It take about a minute before I can SSH in over WiFi, but I’m not sure if that is any slower than before. dmesg didn’t show any stalls (last entry was at 34 seconds). But I can say it doesn’t hang forever.

uname -a says Linux chip 4.4.11-ntc #1 SMP Sat May 28 00:27:07 UTC 2016 armv7l GNU/Linux


BraveNewCurrency, a BIG thanks for your Perl code for reading the DS18B20. It works like a charm!


Hi all,

I used to have it working with Renzo’s kernel 4.3.0 patched to have w1_therm module and my temp sensor worked pretty fine (pull up etc)

check Keenly wanting onewire support

I upgrade to latest kernel 4.4:
Linux chip 4.4.13-ntc-mlc #1 SMP Thu Nov 3 01:28:54 UTC 2016 armv7l GNU/Linux

I launched the perl script and the result is 85.
Now 85 is the wrong temperature reading value (a default value returned by driver when temperature is not readable). Should some parameter like pull up in the kernel be set?

Any clue?



By the way I have translated into python, but the result is absolutely the same.
My chip gets me temperature 85

import time

file = "/sys/devices/w1_bus_master1/28-000007011953/rw"

def send_command (cmd):
  with open(file, 'wb') as f:

def read_data ():
  with open(file, 'rb') as f:
      t =
  return t

send_command(b'\x44')    # Start temp conversion command
send_command(b'\xbe')    # Read data command

ret = read_data()

buf0 = ord(ret[0])
buf1 = ord(ret[1])
t = buf1 << 8 | buf0
if t & 0x8000: # sign bit set
    t = -((t ^ 0xffff) + 1)
t = t / 16

print ('Temperature ', t)

============================ now run
root@chip:~# ./
('Temperature ', 85)


85 is the default temperature that the sensor itself picks when it is unable to get a reading. This means that there is some level of communication going on, to be able to even get this default value.

Really though, it’s a shame there seems to be so much resistance from Next Thing Co. to just add the modules officially to the kernel.


For 4.4.13-ntc-mlc you you could download my compiled module

cd /lib/modules/4.4.13-ntc-mlc/kernel/drivers/w1/slaves
sudo wget
sudo depmod

and add this into crontab

sudo crontab -e
@reboot /usr/bin/timeout 3 /sbin/modprobe w1_therm

This will install the module at startup and take care of the hang after 3 seconds.

Reading DHT11 / DHT22 / AM2302 sensors

You can be confident that your python translation is correct (huuuge thanks!). I am able to get temperatures for two ds18b20 sensors with it. As LloydAtkinson mentions (and I’m reasonably certain I’ve seen it elsewhere in this, or another NTC onewire related thread) the sensor returns 85 when it can’t get a reading. Is it possible you’ve got a faulty connection/sensor?


Thank you so much @danjperron!

I was looking at your reply, installed your module run the depmod and tadaaa! It just works.

Great Community! Thanks y’all.


A new flashable kernel which includes 1-wire built-in support has been released.

  • More input device drivers (joysticks, gamepads such as PS3/4 and Xbox Controllers)
  • 1-wire modules
  • DVB/TV Tuner modules

Keenly wanting onewire support

Hi everyone!
today i try the perl and python scripts and works perfect. After, i update the system (sudo apt-get update and sudo apt-get upgrade) and it comes a kernel upgrade. I install it and i got the support using the modules:

  • w1_therm
  • w1_gpio

Everyone should try to update the kernel.
It was installed this:

  • Linux version 4.4.13-ntc-mlc (bamboo@ip-172-31-23-220) (gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu1) ) #1 SMP Thu Sep 8 19:54:49 UTC 2016
    And it was upgraded by this one:
  • Linux version 4.4.13-ntc-mlc (bamboo@ip-172-31-21-118) (gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu1) ) #1 SMP Tue Dec 6 21:38:00 UTC 2016

I wrote a post (in spanish) about what i do. It’s here:

I think this it could be useful to someone else.