Blog 08
CPU & GPU sensor
For this I combined 2 codes. Together they should display the cpu + gpu temperature on your display. And recheck it every 5 seconds. This should than also be visible on your display.
The code for reading the cpu and gpu and the clock code from Blog 04
The code first gets the cpu temp with thermal_zone0 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 ) 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. The (( )) is always needed at +, *, /, %. ( for the -, ** you always use [[ ]] )
After that we do the gpu temperature the result from measure_temp you would normally would look like: temp=34.7'C
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
( sadly the raspberry pi display doesn't know 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
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 fast!