Please add w1-therm kernel module for DS18B20!


#1

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.


#2

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:

edit:

seems like there is already what you are searching for :wink: http://www.chip-community.org/index.php/Kernel_4.4_with_SPI_and_1-wire


#3

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


#4

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?

/Marc


#5

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


#6

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.


#7

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 ds_read.pl 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.)

Code:

#!/usr/bin/perl
$file = "/sys/devices/w1_bus_master1/28-0000060f136f/rw";

sub send_command {
  my $cmd = shift;
  my $f;
  sleep(1);
  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!


#8

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


#9

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


#10

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


#11

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?

Thanks


#12

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

#!/usr/bin/python
import time

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

def send_command (cmd):
  time.sleep(0.75)
  with open(file, 'wb') as f:
     f.write(cmd) 

def read_data ():
  with open(file, 'rb') as f:
      t = f.read()
  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:~# ./temperaturefromds18b20.py
('Temperature ', 85)


#13

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.


#14

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 https://dl.dropboxusercontent.com/u/48891705/chip/4.4.13-ntc-mlc/w1_therm.ko
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
#15

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?


#16

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.


#17

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
#18

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: http://trasto.net/blog/index.php?post/2017/01/20/Leer-y-mostrar-temperatura-usando-el-sensor-DS18B20-con-CHIP

I think this it could be useful to someone else.