DS18B20 - need help with setup

2,398 views
Skip to first unread message

Krzysiek Skwieciński

unread,
Jun 3, 2013, 2:49:55 PM6/3/13
to web...@googlegroups.com
Hi!

I connected my DS18B20 to a 5V power and GPIO4 with pull-up resistor. Everything seems to be ok then. Unfortunately I have no idea how to initialize the temp sensor. I cant make it appear in device page.
I added this code in a [DEVICE] section in config file: 
 # Setup a DS18B20 with 1-Wire slave auto-detect
tmp0 = DS18B20

I dont really have idea how to initialize it. I think I should add something else in the config file, but I dont know what.
Sorry. I used to use C and AVR controllers. Python and R Pi are quite new to me.

Thanks in advance

Toshi Bass

unread,
Jun 3, 2013, 4:45:18 PM6/3/13
to web...@googlegroups.com
Hi, With the code you added in the config file [Devices] section you should be seeing tmp0: Temperature: 23.88°C on the device page already, if not then you need to check your wiring its incorrect, once you get the sensor working on the device page you can add the following to script.py if you want to get the temperature as a arg, but get the sensor working on the device page first.

# Connect a DS18B20 with VCC to 3V, ground to ground and Data
# to GPIO #4. Then connect a 4.7K resistor from Data to VCC.

import glob
import time
import os
import datetime

#initialize DS18B20 device
os.system("sudo modprobe w1-gpio")
os.system("sudo modprobe w1-therm")
#find the DS18B20 device
devicedir = glob.glob("/sys/bus/w1/devices/28-*")
device = devicedir[0]+"/w1_slave"


# A macro with 1 args which return B20 temperature
@webiopi.macro
def MacroWith1Args(arg1):
    #open the DS18B20 file
    f = open (device, 'r')
    tsensor = f.readlines()
    f.close()
    #parse results from the file
    crc = tsensor[0].split()[-1]
    temp_C = float(tsensor[1].split()[-1].strip('t='))
    b20 = str(temp_C/1000.000)
    #print(b20)
    return(b20)


Hope it helps.......

Krzysiek Skwieciński

unread,
Jun 5, 2013, 1:48:01 PM6/5/13
to web...@googlegroups.com
Hi.
First of all thanks for your advice.
Unfortunatelly it didn't help. I checked the wiring many times but it still doesn't work.
I have yellow box on GPIO4 indicating positive signal on input but still nothing in device page. Could you send me your full config file so i can compare?

Toshi Bass

unread,
Jun 5, 2013, 7:02:09 PM6/5/13
to web...@googlegroups.com
Hi,

here you go....

[DEVICES]
# on all lines except these 4 items, (in reality you say you have tmp0 = DS18B20 so it should be working)
  
MCP0 = MCP23017 slave:0x20
Piface = MCP23S17
Temp0 = DS18B20
Temp1 = DS18B20 slave:28-000004bda38e


OK two things to try,
go here 

enter the following 3 lines one after the other - you should see confirmation that the sensor is working and the serial number something like 28-0000049bc218 
pi@raspberrypi:~$ sudo modprobe wire

pi@raspberrypi:~$ sudo modprobe w1-gpio

pi@raspberrypi:~$ sudo modprobe w1-therm 
when I connected my one it took 3 goes before I got the wiring correct wish I had seen that link ....

Toshi Bass

unread,
Jun 6, 2013, 2:49:31 PM6/6/13
to web...@googlegroups.com
sorry missed a crucial bit it was getting late, after you enter the 3 commands 

pi@raspberrypi:~$ sudo modprobe wire

pi@raspberrypi:~$ sudo modprobe w1-gpio

pi@raspberrypi:~$ sudo modprobe w1-therm 
 pi@raspberrypi:~$ cd /sys/bus/w1/devices/ there you should see a folder for your device: like this is my ones>

28-0000045328a0  28-000004bda38e  w1_bus_master1

that confirms the sensor is present.

hope that helps....

Toshi Bass

unread,
Jun 6, 2013, 4:29:06 PM6/6/13
to web...@googlegroups.com

Krzysiek Skwieciński

unread,
Jun 7, 2013, 1:20:15 PM6/7/13
to web...@googlegroups.com
Thank you very much!! It works fine now ;)
Btw the wiring was correct. I missed this part:

Alex Szilagyi

unread,
Jun 17, 2013, 7:55:14 PM6/17/13
to web...@googlegroups.com
@Krzysiek Skwieciński: Can you tell me, please from where did you've get:

 
pi@raspberrypi:~$ sudo modprobe wire

pi@raspberrypi:~$ sudo modprobe w1-gpio

pi@raspberrypi:~$ sudo modprobe w1-therm 

My temperature sensor is connected to RaspberryPi (5 V & GPIO 4) but I'm not able to see it at device monitor...


Thank you.

Alex Szilagyi

unread,
Jun 17, 2013, 7:56:39 PM6/17/13
to web...@googlegroups.com
P.S. - When I enter the above commands that you were referring to I get an error at this command ( sudo modprobe w1-gpio ):

ERROR: could not insert 'w1_gpio': No such device

Alex Szilagyi

unread,
Jun 17, 2013, 8:17:50 PM6/17/13
to web...@googlegroups.com
Final question...

If I uncomment the temp1 device then the webiopi doesn't start anymore. Do I have to uncomment anything else at [DEVICES] section?

The device name (#temp1 = DS18B20) is enough or implies something else also?

Below is my config:

[DEVICES]
# Device configuration syntax:
# name = device [args...]
#   name   : used in the URL mapping
#   device : device name
#   args   : (optional) see device driver doc
# If enabled, devices configured here are mapped on REST API /device/name
# Devices are also accessible in custom scripts using deviceInstance(name)
# See device driver doc for methods and URI scheme available

# Raspberry native UART on GPIO, uncomment to enable
# Don't forget to remove console on ttyAMA0 in /boot/cmdline.txt
# And also disable getty on ttyAMA0 in /etc/inittab
#serial0 = Serial device:ttyAMA0 baudrate:9600

# USB serial adapters
#usb0 = Serial device:ttyUSB0 baudrate:9600
#usb1 = Serial device:ttyACM0 baudrate:9600

#temp0 = TMP102
#temp1 = TMP102 slave:0x49
#temp1 = DS18B20
#temp3 = DS18B20 slave:28-0000049bc218

#bmp = BMP085

#gpio0 = PCF8574
#gpio1 = PCF8574 slave:0x21

#light0 = TSL2561T
#light1 = TSL2561T slave:0b0101001

#gpio0 = MCP23017
#gpio1 = MCP23017 slave:0x21
#gpio2 = MCP23017 slave:0x22

#pwm0 = PCA9685
#pwm1 = PCA9685 slave:0x41

#adc = MCP3008
#dac = MCP4922 chip:1

#------------------------------------------------------------------------#

[REST]
# By default, REST API allows to GET/POST on all GPIOs
# Use gpio-export to limit GPIO available through REST API
#gpio-export = 21, 23, 24, 25

# Uncomment to forbid changing GPIO values
#gpio-post-value = false

# Uncomment to forbid changing GPIO functions
#gpio-post-function = false

# Uncomment to disable automatic device mapping
#device-mapping = false

#------------------------------------------------------------------------#

[ROUTES]
# Custom REST API route syntax :
# source = destination
#   source      : URL to route
#   destination : Resulting URL
# Adding routes allows to simplify access with Human comprehensive URLs

# In the next example with have the bedroom light connected to GPIO 25
# and a temperature sensor named temp2, defined in [DEVICES] section
#  - GET  /bedroom/light       => GET  /GPIO/25/value, returns the light state
#  - POST /bedroom/light/0     => POST /GPIO/25/value/0, turn off the light
#  - POST /bedroom/light/1   => POST /GPIO/25/value/1, turn on the light
#  - GET  /bedroom/temperature => GET  /devices/temp2/temperature/c, returns the temperature in celsius
#/bedroom/light = /GPIO/25/value
#/bedroom/temperature = /devices/temp2/temperature/c

#/livingroom/light = /devices/expander0/0
#/livingroom/brightness = /devices/adc/0/float
#/livingroom/temperature = /devices/temp0/temperature/c

#/weather/temperature = /devices/bmp/temperature/c
#/weather/pressure = /devices/bmp/pressure/hpa

Thanks!


On 18 June 2013 02:56, Alex Szilagyi <alex.s...@gmail.com> wrote:
P.S. - When I enter the above commands that you were referring to I get an error at this command ( sudo modprobe w1-gpio ):

ERROR: could not insert 'w1_gpio': No such device

--
You received this message because you are subscribed to a topic in the Google Groups "WebIOPi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/webiopi/Hii_XHV-sNk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to webiopi+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Toshi Bass

unread,
Jun 18, 2013, 6:27:00 AM6/18/13
to web...@googlegroups.com
Hi Alex, 

Remember these sudo commands have nothing to do with webiopi there commands to the linux operating system, and you need to get the temp sensor working here even before trying to see temps in webiopi.

so if you are getting ERROR: could not insert 'w1_gpio': No such device.... when you enter  
pi@raspberrypi:~$ sudo modprobe wire 
pi@raspberrypi:~$ sudo modprobe w1-gpio

Then the clue is in the error statement, it cannot find any sensor connected to the pi, You have almost certainly connected up the sensor incorrectly, you can Google "raspberry pi DS18B20" and find plenty of references, http://raspbrew.tumblr.com/ is very good and explains everything, (personally i use 3.3v not 5v only because every article i read does this in combination with a 4k7 resistor, i guess changing the voltage or the resistor size may give false readings or perhaps no readings !)  once you have cleared the fault follow the above commands with these, below and once you can see the sensor address in cd /sys/bus/w1/devices/ , then is the time to change the webiopi config file and check the device manager page.

pi@raspberrypi:~$ sudo modprobe w1-therm

 pi@raspberrypi:~$ cd /sys/bus/w1/devices/ 

ps I see no reason why webiopi should stop running after you comment or uncomment #temp1 = DS18B20, are you remembering to restart the pi after making the changes ? (you don't need to do anything else in the config file just change the above statement in the devices section as you have done)

hope it helps.....

On Tuesday, June 18, 2013 1:17:50 AM UTC+1, Alex Szilagyi wrote:
Final question...

If I uncomment the temp1 device then the webiopi doesn't start anymore. Do I have to uncomment anything else at [DEVICES] section?

The device name (#temp1 = DS18B20) is enough or implies something else also?

Alex Szilagyi

unread,
Jun 18, 2013, 1:48:05 PM6/18/13
to web...@googlegroups.com
Toshi Bass,

You're explanations were just I needed! Very glad to see such a detailed reply and thank you for your time.

I'll try in couple of minutes and let you know my progress.

Thank you,
Alex
Reply all
Reply to author
Forward
0 new messages