= Raspberry Pi and DS18S20 temperature measurement = This page records some work on using DS18S20 with Raspberry Pi and plotting using AWK, SVG and JavaScript. == Raspberry Pi and DS18S20 == One wire - DS18S20 reader Used GPIO4 pin 7 - middle pin. 3v3 to power gnd to gnd / 3v3 ----------------+ DS18S20 - top (|- buss --GPIO4--[4k7]--/ \ gnd Web pages to help:- http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/hardware http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/hardware http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/ds18b20 == Shell Script - loop.sh == The script below puts the
#! /bin/bash # # Shell Script to poll temperature chips # usage: bash loop.sh # # http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/hardware # echo "---------------------" ls /sys/bus echo "---------------------" sudo modprobe w1-gpio sudo modprobe w1-therm echo "---------------------" ls /sys/bus echo "---------------------" while [[ 1 ]] do echo "========" > ~/Desktop/tmp.txt date >> ~/Desktop/tmp.txt cat /sys/bus/w1/devices/10-*/name >> ~/Desktop/tmp.txt cat /sys/bus/w1/devices/10-*/w1* >> ~/Desktop/tmp.txt echo " " >> ~/Desktop/tmp.txt # # use AWK to extract the temperatures. appends gbF() to gbookFtemp.js # cat ~/Desktop/tmp.txt awk -f loop.awk ~/Desktop/tmp.txt cat ~/Desktop/tmp.txt >> ~/Desktop/loop_log.txt sleep 3 done== Awk Script loop.sh == This awk script extracts the temperature and puts the results into a javascript include file.# # # loop.awk # # usage: awk -f loop.awk loop_log.txt # # # pull out the temperature from loop_log.txt written by loop.sh # Appends to "gbookFtemp.js" # # #//gbF( name,email,postedOn,IPaddress,userfield1,userfield2,userfield3,userfield4,comments){ BEGIN { FS="=" # zero the temperatures ln[1]=0 ln[2]=0 ln[3]=0 ln[4]=0 # print "" > "gbookFtemp.js" notFirst = 0 } /====/{ print $0 getline print $0 lnp=1 cnt +=1 if ( notFirst ){ print "gbF( 'awk','t@pi','" lastDate " ','127.0.0.1'," ln[1] "," ln[2] "," ln[3] "," ln[4] ",'comments');" >> "gbookFtemp.js" } # prepare for next readings notFirst = 1 ln[1]=0 ln[2]=0 ln[3]=0 ln[4]=0 lastDate = $0 } /t=/{ # found a line with a temperature ln[lnp] = ($NF/1000) lnp ++ } END { cnt +=1 print "gbF( 'awk','t@pi','" lastDate " ','127.0.0.1'," ln[1] "," ln[2] "," ln[3] "," ln[4] ",'comments');" >> "gbookFtemp.js" }== SVG - loopDS18S20reportSVG.svg == The SVG below includes the readings in gbookFtemp.js and plots them.