Man-Cave Temperature: Rasperry Pi and DS1820

Yesterday, I was able to complete a fun little project. It was perfect, as it required very little time (only a few hours). This was enough to finish it while the family was out and about. Here is a rough outline of the steps I took:

Materials required:
1. DS1820 One-wire temperature measuring IC.
2. 4.7K resistor.
3. Extra wires from the junk pile.
4. Connectors, for attaching to the Raspberry Pi GPIO port.

1. Solder together wires. Follow this picture as a guide. See also this page for a nice picture of the Raspi GPIO pinout.
2. Turn off Raspberry Pi (is this necessary? Maybe not, but better safe than sorry), and connect circuit to Raspberry Pi GPIO port.
3. Follow directions in first link given above to add modules to kernel, so that temperature can be read. Also, create file to add in modules at run time, per your Linux distribution.
4. Create a script "" for running in cron (crontab -e), run hourly. The script also plots the temperature using gnuplot:


temp=$(cat /sys/bus/w1/devices/10-00080154d210/w1_slave | tr "=" " " |
awk 'NR==2 {print $11}')  
reading=$(echo "scale=3; ${temp}/1000.000" | bc -l)  
echo "$(date '+%Y%m%d%H%M%S')" "$reading" >>

gnuplot <<EOF  
set terminal png size 900, 300  
set output "/home/user/temperature/temperature.png"  
set xdata time  
set timefmt '%Y%m%d%H%M%S'  
set xlabel "Timestamp" offset 0,-1  
set ylabel "Temperature in deg. C"  
plot [:][:] "/home/user/temperature/readings.txt" using 1:2 title "deg. C" with lines  
cp /home/user/temperature/temperature.png

The result of my hackery is shown below. It isn't pretty, but it does the job.

ds1820 and R Pi

Measuring Temperature with the DS1820 on the Raspberry Pi.

You can see the temperature plotted over time here.

Comments !