Temperature sensor example
Jump to navigation
Jump to search
initialization
The following is a script that I use to initialize the temperature sensors for the rpi_ui board.
#!/bin/sh ui="bw_tool -a 94" #ui="bw_tool -a 94 -I -D /dev/i2c-1" $ui -w 70:c7 # internal tempsens with internal 1.1V as reference $ui -w 71:c6 # external tempsens with internal 1.1V as reference $ui -W 81:1000 $ui -w 82:6 $ui -w 80:2
The above script is written for the SPI version of the board. The commented out like is for the i2c-version. So activate that line if you have the i2c version (remove the comment marker).
readout
The following is a script that shows the temperature on stdout. I call this script "showtemp".
#!/bin/sh # # # Set the number of samples to 64, and shift by 0, or set the # number of samples to 4096 and shift by 6. The latter is recommended! # adcmaxval=65520 #adcmaxval=1023 # # MCP9700 degrees per volt. vperdeg=0.010 #refvoltage=4.9000 refvoltage=1.1000 # mcp offset voltage is 500mv at 0 deg. At 0.010 volt per deg that comes to # 50 degrees C. offset=50 # # # 60 adc channel 0, direct value (0-1023) # 68 adc channel 0, averaged value (0-65520 with nsamp=4096, shift=6) # 61 adc channel 1, direct value (0-1023) # 69 adc channel 1, averaged value (0-65520 with nsamp=4096, shift=6) register_to_read=69 # # settings are done, now the preparations. convfactor=`(echo scale = 10 ; echo obase=16;echo $refvoltage / $vperdeg / $adcmaxval ) | bc` offsethex=`(echo obase=16; echo scale=3;echo $offset) | bc ` # now do the real deal. rawtemp=`sudo bw_tool -s 100000 -a 94 -R $register_to_read:s | tr a-z A-Z` (echo ibase=16; echo scale=3;echo $rawtemp \* $convfactor - $offsethex) | bc
display
The following clears the screen and then shows the temperature.
bw_tool -a 94 -w 10:0 bw_tool -a 94 -t "temp: "`./showtemp`