lesson 11 DS18B20 temp sensor
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

lesson 11 DS18B20 temp sensor

by JimK123 on Thu Feb 28, 2013 8:55 pm

I was doing lesson 11 and the diagram shows to wire the temp sensor yellow lead to pin GPIO pin 4. The sample code works fine and I moved onto another lession using switches and in that lession you had to specify a pin as INput. I then was wondering why the temp sensor does not specify the pin # in the program ? When I googled pin 4 some people also reference it as clock. My question is does this sensor DS18B20 always have to be wired to pin 4 and how does the code know what pin to use ? I also noticed the temp sensor writes to a file in /sys/bus/w1/devices/28-xxx and the program reads the file. Is this good for long term use by it writing to the SD card over and over ? thanks
JimK123
 
Posts: 33
Joined: Sun Dec 26, 2010 6:04 pm

Re: lesson 11 DS18B20 temp sensor

by neilk on Fri Mar 01, 2013 1:59 am

Funny you should ask about pin 4; I had the same question and had just researched the answer.

In short: it is hard coded in the kernel to pin 4. It is not used until you load the w1-gpio kernel module; at that point pin 4 is dedicated to the one-wire bus until you unload the w1-gpio kernel module.

The actual assignment is made in https://github.com/raspberrypi/linux/blob/rpi-3.6.y/arch/arm/mach-bcm2708/bcm2708.c. The pin is assigned around the "#define W1_GPIO 4" line. Look for w1_gpio_platform_data to see the actual structure definition.

As far as I can tell: this version of the kernel is completely hard coded; it doesn't even allow overriding the pin defintions at module load time.

The kernel that comes with openwrt has a w1_gpio_custom module. This module allows pin definitions to be made at module load time. But that module seems to only live with openwrt, and hasn't been ported anywhere else.
neilk
 
Posts: 2
Joined: Mon Feb 11, 2013 2:05 pm

Re: lesson 11 DS18B20 temp sensor

by JimK123 on Fri Mar 01, 2013 9:54 am

thanks for the update. So I assume if I wanted to add additional temp sensors they would all go to pin 4 and each would get assigned a different serial # ?
JimK123
 
Posts: 33
Joined: Sun Dec 26, 2010 6:04 pm

Re: lesson 11 DS18B20 temp sensor

by neilk on Fri Mar 01, 2013 11:48 am

That's correct: all your one-wire devices go on pin four (assuming you haven't made your own kernel).

The one thing to keep in mind: you only need one pullup resistor between Vcc and Data for the whole bus. And some devices have internal pullup resistors, so check the datasheets.
neilk
 
Posts: 2
Joined: Mon Feb 11, 2013 2:05 pm

Re: lesson 11 DS18B20 temp sensor

by JimK123 on Fri Mar 01, 2013 1:07 pm

thank you for the update
JimK123
 
Posts: 33
Joined: Sun Dec 26, 2010 6:04 pm