Temperature Datalogger with DS18B20 Sensor

17 14773
I try to get the temperature with the DS18B20 Temp. Sensor, but in the folder /sys/bus/w1/devices should be the data.with sudo modprobe wire && sudo modprobe w1_gpio && sudo modprobe w1_therm nothing happens. With lsmod I do not see the wire and w1_gpio and w1_therm loaded.
I have used Pin 7 (PI 03) on my bananapi, any suggestion what to change or type?

Thanks for help.
Post Last Edited by actkk2000 at 2014-8-25 22:44

My experience with Raspbian 3.1: ... =16612&fromuid=1602

I connected 1-wire to pin 12 (gpio18) using this as pinout guide:

Post Last Edited by deks at 2014-8-26 04:37

How do I load the modules? I tried this:

sudo modprobe wire
sudo modprobe w1-gpio
sudo modprobe w1-therm

after that in the folder  "/sys/bus/w1/devices" there are no temp data.
With "lsmod" I also do not see the modules loaded.

Edited by actkk2000 at Sun Nov 2, 2014 04:37

Reply 3# deks

- This worked for me on Raspbian 3.1 (haven't try other distros)

- I followed these directions to connect basic DS18B20:

- I modified script.bin following these directions:

- I connected gpio using this pinout schemathics as guide:

I connected middle pin of DS18B20 to gpio18 (pin#12 of BananaPi) because I am already using gpio4 (pin #7)
But wherever gpio you choose has to match 1-wire parameter that you added in script.bin:
  1. [w1_para]
  2. gpio = 18
Copy the Code
When succeeded you will see something like this:

  1. bananapi@lemaker ~ $ cd /sys/bus/w1/devices/
  2. bananapi@lemaker /sys/bus/w1/devices $ ls
  3. 28-000005330162  w1_bus_master1
Copy the Code

Here the code for Python script:

  1. nano
Copy the Code

Copy this inside:

  1. import os
  2. import glob
  3. import time
  4. import subprocess
  5. os.system('modprobe w1-gpio')
  6. os.system('modprobe w1-therm')
  7. base_dir = '/sys/bus/w1/devices/'
  8. device_folder = glob.glob(base_dir + '28*')[0]
  9. device_file = device_folder + '/w1_slave'
  10. def read_temp_raw():
  11.     catdata = subprocess.Popen(['cat',device_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  12.     out,err = catdata.communicate()
  13.     out_decode = out.decode('utf-8')
  14.     lines = out_decode.split('\n')
  15.     return lines
  16. def read_temp():
  17.     lines = read_temp_raw()
  18.     while lines[0].strip()[-3:] != 'YES':
  19.         time.sleep(0.2)
  20.         lines = read_temp_raw()
  21.     equals_pos = lines[1].find('t=')
  22.     if equals_pos != -1:
  23.         temp_string = lines[1][equals_pos+2:]
  24.         temp_c = float(temp_string) / 1000.0
  25.         temp_f = temp_c * 9.0 / 5.0 + 32.0
  26.         return temp_c, temp_f
  27. while True:
  28.         print(read_temp())
  29.         time.sleep(1)
Copy the Code
Ctrl + x to exit
Answer Yes

Finally run:
  1. sudo python
Copy the Code

This will give a temperature output in Celsius and Fahrenheit every 1 sec in this format:

  1. (18.75, 65.75)
Copy the Code

Thanks I have changed the script.bin, now I have the file for the temperature for a short time and after a while it is not more there, than I have just the w1_bus_master1 file without the temp. file 10-000...

When I check the modules with lsmod the w1-gpio and w1-therm are not there.

After a reboot I have the temp. file again for a short time  without a temperature.

Post Last Edited by actkk2000 at 2014-8-27 19:51

Be sure to connect the sensor respecting polarity, use the "face" (where is written) as reference:


Be sure to have the correct sensor. I have this one:

Are you using Raspbian3.1 or 3.0 ?

I'm using Raspbian 3.1. with the change of the
  1. script.bin
Copy the Code
, I add the change to the end of the file [w1_para]....
The sensor is a Dallas DS1820 (without the B) but it should work.

In the beginning it seams to work I had the 10-000802bxxx file and in it there is the
  1. crc=00 NO
Copy the Code
but it should be YES, and after a while I get
  1. w1_slave: No such file or directory
Copy the Code
and with a cd ..  I am in a different directory /sys/devices/w1_bus_master1# but it should be
  1. /sys/bus/w1/devices#
Copy the Code

What is your current cpu frequency and default governor?

Could it be a case of dropping the device due to this issue? ... amp;page=1#pid15472

I get the following:
grep . /sys/devices/system/cpu/cpu*/cpufreq/*freq*
root@lemaker:/sys/bus/w1/devices# grep . /sys/devices/system/cpu/cpu*/cpufreq/*freq*

You right now it is going to the other issue since the temp file 10-00xxxx shows up and dissapears.

You have to log in before you can reply Login | Sign Up

Points Rules