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/
Locked
User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

lesson 11 DS18B20 temp sensor

Post by jimk123 »

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

User avatar
neilk
 
Posts: 2
Joined: Mon Feb 11, 2013 3:05 pm

Re: lesson 11 DS18B20 temp sensor

Post by neilk »

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/bl ... /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.

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: lesson 11 DS18B20 temp sensor

Post by jimk123 »

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

User avatar
neilk
 
Posts: 2
Joined: Mon Feb 11, 2013 3:05 pm

Re: lesson 11 DS18B20 temp sensor

Post by neilk »

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.

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: lesson 11 DS18B20 temp sensor

Post by jimk123 »

thank you for the update

Locked
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/

Return to “Adafruit Raspberry Pi® accessories”