Difference between revisions of "Blog 05"

From BitWizard WIKI
Jump to: navigation, search
Line 142: Line 142:
  DISPL="bw_tool -I -D /dev/i2c-1 -a 94"
  DISPL="bw_tool -I -D /dev/i2c-1 -a 94"
  $DISPL -W 10:0:b
  $DISPL -W 10:0:b
   while true;do  
   while true;do  
         bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00  
         bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00  

Latest revision as of 14:33, 21 September 2015


Now the temperature sensor: For making the temperature sensor we have to make 2 script.

Script 1(The name I gave it was: ui):

 ui="bw_tool -a 94 -I -D /dev/i2c-1" 
 $ui -W 70:c7:b # internal tempsens with internal 1.1V as reference 
 $ui -W 71:c6:b # external tempsens with internal 1.1V as reference 
 $ui -W 81:1000:s 
 $ui -W 82:6:b 
 $ui -W 80:2:b 

After this we make ui executable:

chmod +x ui 

And look if it worked:

ls -l ui 

This result should have -rwxr-xr-x like me: -rwxr-xr-x 1 root root 216 Sep 7 15:46 ui

Ater you see it works activate it:


( There will be nothing printed out when you activate it )

Now it's time to make the second script. ( I named it showtemp)

# 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!
# MCP9700 degrees per volt. 
# mcp offset voltage is 500mv at 0 deg. At 0.010 volt per deg that comes to 
# 50 degrees C. 
# 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)

# 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 -I -D /dev/i2c-1 -a 94 -R $register_to_read:s | tr a-z A-Z`
(echo ibase=16; echo scale=3;echo $rawtemp \* $convfactor - $offsethex)  | bc

After that we make is executable, like we did with the ui script.

chmod +x showtemp 
ls -l showtemp 

-rwxr-xr-x 1 pi pi 999 Sep 7 14:26 showtemp

We trying it out I got failures, because I didn't download bc.:

apt-get install bc 

To check if your scripts work:

sh -x ./ui 
+ ui=bw_tool -a 94 -I -D /dev/i2c-1 
+ bw_tool -a 94 -I -D /dev/i2c-1 -W 70:c7:b 
+ bw_tool -a 94 -I -D /dev/i2c-1 -W 71:c6:b 
+ bw_tool -a 94 -I -D /dev/i2c-1 -W 81:1000:s 
+ bw_tool -a 94 -I -D /dev/i2c-1 -W 82:6:b 
+ bw_tool -a 94 -I -D /dev/i2c-1 -W 80:2:b 
sh -x ./showtemp 
+ adcmaxval=65520 
+ vperdeg=0.010 
+ refvoltage=1.1000 
+ offset=50 
+ register_to_read=69 
+ + bc 
echo scale = 10 
+ echo obase=16 
+ echo 1.1000 / 0.010 / 65520 
+ convfactor=.006E06E01 
+ echo obase=16 
+ echo+  scale=3 
bc+ echo 50  
+ offsethex=32 
+ sudo bw_tool+  -I -Dtr a-z A-Z 
 /dev/i2c-1 -a 94 -R 69:s 
+ rawtemp=ACC3 
+ echo ibase=16 
+ echo scale=3 
+ echo ACC3 * .006E06E01 - 32 
+ bc 

If a line is wrong it should give a warning.

So now everything is fine it is time to print it out:

bw_tool -I -D /dev/i2c-1 -a 94 -t "temp: "`./showtemp`

(The remove the latest temperature and see the newest one:

bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
bw_tool -I -D /dev/i2c-1 -a 94 -t "temp: "`./showtemp


Code that I used: [Temperature Sensor example]

Now we have this. It may be better that we also get it to refresh around a several second instead we have to type the code:

bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
bw_tool -I -D /dev/i2c-1 -a 94 -t "temp: "`./showtemp

over and over again. So I am going to try to mix the previous code with temperature code so it will check the code every amount of time. ( I will take 5 sec )

I made the script(Temp5):

DISPL="bw_tool -I -D /dev/i2c-1 -a 94"

$DISPL -W 10:0:b

 while true;do 
        bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
        bw_tool -I -D /dev/i2c-1 -a 94 -t "temp: "`./showtemp` 
        sleep 5 

Do like the other times: chmod +x Temp5

And now when you do:


He will print the temperature every 5 seconds.

On Blog 06 I combined made it possible to show the time and temperature on the display.