Raspberry Pi - Getting the temperature sensor to work.

I had 'issues' with getting the temperature sensor to work with the Raspberry Pi. So I did some more searching...

Add the following line to /boot/config.txt

Then you can 'probe' the Pi...

sudo modprobe w1-gpio
sudo modprobe w1-therm

To check this has 'worked':-
cd /sys/bus/w1/devices/
This should show the temperature file:-
10-00080254a833 [ or similar file name][IF it doesn't, you need to check everything.]

Change directory to it:-

cd 10-00080254a833
To 'read' the DS18x20 [mine is so old...]
cat w1_slave

This should show something like this :-

pi@raspberrypi /sys/bus/w1/devices $ cd 10-00080254a833
pi@raspberrypi /sys/bus/w1/devices/10-00080254a833 $ cat w1_slave
23 00 5d 58 ff ff 04 10 3d : crc=3d YES
23 00 5d 58 ff ff 04 10 3d t=17500
pi@raspberrypi /sys/bus/w1/devices/10-00080254a833 $

Yes! It really was 17.5C in the study. Cool now to find a C program to get the reading...

Brad's Raspberry Pi Blog - has the answer. 

But only one 'gotcha'! The temperature sensor in current day use is a DS18B20 and mine is a DS1820. The 'output' is not '28-' but a '10-'. This requires a small change to the C program. A recompile later and all is well. Reading the sensor to three decimal places. Hmm.


No comments:

Post a Comment