Difference between revisions of "Blog 08"

From BitWizard Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
== CPU & GPU sensor ==
== CPU & GPU sensor ==


For this I combined 2 codes. Together they should display the CPU + GPU temperature on your display, which should be rechecked every 5 seconds. The temperatures will be visible on your display.
For this I combined 2 codes. (The code for reading [https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=34994&start=25 the cpu and gpu] and the clock code from [[Blog 04]]) Together they should display the CPU + GPU temperature on your display, which should be rechecked every 5 seconds. The temperatures will be visible on your display.


The code first gets the CPU temp with thermal_zone0
The code for reading [https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=34994&start=25 the cpu and gpu] and the clock code from [[Blog 04]]
The result would be something like: 36318.

36318 goes trough 1000 to get it to 36. ( it only looks at the full numbers, otherwise it should be 36.318 )
The code first gets the cpu temp with thermal_zone0
Then the line under it does 36318 trough 100, what makes it 363
The result would be something like: 36318
363108 goes trough 1000 to get it too 36 ( it only looks at the full numbers, otherwise it should be 36.318 )
After we use %. What % does is that it divides 363 with full 36's and the time it can't get divided with 36 it will give the amount of numbers it got left.
then the line under it does 35780 trough 100, what makes it 363
After we use %. What % does it that is divides 363 with full 36's and the time it can't get divided with 36 it will give the amount of number he still got.
(What is of course 3.) This is a smart trick to get the 1 decimal place after the number.
(What is of course 3.) This is a smart trick to get the 1 decimal place after the number.
The (( )) is always needed at +, *, /, %. ( for the -, ** you always use [[ ]] )
The (( )) is always needed at +, *, /, %. ( for the -, ** you always use [[ ]] )


After that we do the gpu temperature
After that we get the GPU temperature.
the result from measure_temp you would normally would look like:
The result from measure_temp would normally look something like:
temp=34.7'C
temp=34.7'C


We are going to print 'GPU Temp: 'before the temperature, so we don't want 'temp=' to appear. To remove it we do: gpuTemp0//temp=



We are going to print 'GPU Temp: 'before it so we don't want temp= to appear. To remove it we do: gpuTemp0//temp=
to say temp= has to go away
to say temp= has to go away



Latest revision as of 12:00, 17 September 2015

CPU & GPU sensor

For this I combined 2 codes. (The code for reading the cpu and gpu and the clock code from Blog 04) Together they should display the CPU + GPU temperature on your display, which should be rechecked every 5 seconds. The temperatures will be visible on your display.

The code first gets the CPU temp with thermal_zone0 The result would be something like: 36318. 36318 goes trough 1000 to get it to 36. ( it only looks at the full numbers, otherwise it should be 36.318 ) Then the line under it does 36318 trough 100, what makes it 363 After we use %. What % does is that it divides 363 with full 36's and the time it can't get divided with 36 it will give the amount of numbers it got left. (What is of course 3.) This is a smart trick to get the 1 decimal place after the number. The (( )) is always needed at +, *, /, %. ( for the -, ** you always use [[ ]] )

After that we get the GPU temperature. The result from measure_temp would normally look something like: temp=34.7'C

We are going to print 'GPU Temp: 'before the temperature, so we don't want 'temp=' to appear. To remove it we do: gpuTemp0//temp= to say temp= has to go away

( Sadly the raspberry pi display doesn't know the Celsius mark so I replaced it with: ' )

#!/bin/bash 
DISPL="bw_tool -I -D /dev/i2c-1 -a 94"  

$DISPL -W 10:0:b  

while true; do 
       cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp) 
       cpuTemp1=$(($cpuTemp0/1000)) 
       cpuTemp2=$(($cpuTemp0/100)) 
       cpuTempM=$(($cpuTemp2 % $cpuTemp1)) 

       gpuTemp0=$(/opt/vc/bin/vcgencmd measure_temp) 
       gpuTemp0=${gpuTemp0//temp=/} 

       $DISPL -W 11:00:b 
       $DISPL -t "CPU Temp: "$cpuTemp1"."$cpuTempM"'C" 

       $DISPL -W 11:20:b 
       $DISPL -t "GPU Temp: "$gpuTemp0 

       sleep 5 
  
done


CPU&GPU.jpg


The maximum temperature the raspberry pi should get is 70 degrees! If it is getting higher than 70 degrees it is recommended to cool the Raspberry pi down as fast as you can!


Look at my other projects at the Blog list