måndag 2 mars 2015

Raspberry PI and the DS18B20 one-wire temprature sensor

So, Raspberry PIs are fun to tinker with and what is easy to start with?

Checking the current temperature, of course!
So I got myself a Dallas Semiconductor DS18B20 on a little board by Keyes.
This is a thing the sell as an add-on for the Arduino.
The good thing with it is that it comes with the required pull-up resistor on the board. It also has a little LED that flashes when it is communicating. So, pretty easy to wire up, three wires like this.

To get going you login to the raspberry and make sure you load some w1 modules.
The permanent way of doing it is to edit the /etc/modules file and add the lines
w1-gpio
w1-therm
at the end of the file. This will load the modules at the next start.

you could also give the commands at the command prompt:
> sudo modproble w1-gpio
> sudo modproble w1-therm

After this it should be possible to go to the /sys/bus/w1/devices folder and list the directory contents.
My was totally empty.
After a lot of googling I found this site that had the solution to the problem:
edit /boot/config.txt and add the lines

# 1-wire settings
dtoverlay=w1-gpio,gpiopin=4

to the end of the file.

RESTART and hey presto! It works!

The previous mentioned site also had a link to http://www.raspberrypi.org/forums/viewtopic.php?p=675658#p675658 where the reasoning about this is well described.

Inga kommentarer: