Difference between revisions of "Temperature sensor example"

From BitWizard WIKI
Jump to: navigation, search
(Created page with " == initialization == #!/bin/sh bw_tool -a 94 -w 70:c7 # internal tempsens with internal 1.1V as reference bw_tool -a 94 -w 71:c6 # external tempsens with internal 1.1V as...")
 
(initialization)
Line 1: Line 1:
  
 
== initialization ==
 
== initialization ==
 +
 +
 +
The following is a script that I use to initialize the temperature sensors for the rpi_ui board.
  
 
  #!/bin/sh
 
  #!/bin/sh
Line 8: Line 11:
 
  bw_tool -a 94 -w 82:6
 
  bw_tool -a 94 -w 82:6
 
  bw_tool -a 94 -w 80:2
 
  bw_tool -a 94 -w 80:2
 
  
 
== readout ==
 
== readout ==

Revision as of 16:17, 3 December 2012

initialization

The following is a script that I use to initialize the temperature sensors for the rpi_ui board.

#!/bin/sh
bw_tool -a 94 -w 70:c7 # internal tempsens with internal 1.1V as reference
bw_tool -a 94 -w 71:c6 # external tempsens with internal 1.1V as reference
bw_tool -a 94 -W 81:1000
bw_tool -a 94 -w 82:6
bw_tool -a 94 -w 80:2

readout

#!/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