Algorithms, Blockchain and Cloud

BASH Script to Monitor the CPU Frequency and Temperature on Raspberry PI


We can write a BASH Script to print out the current CPU frequency and temperature on Raspberry PI.

#pi@raspberrypi:~ $ cat ./cpu_freq.sh 
#!/bin/bash

temp=`head -n 1 /sys/class/thermal/thermal_zone0/temp | xargs -I{} awk "BEGIN {printf \"%.2f\n\", {}/1000}"`

echo $((`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq`/1000)) MHz, $temp degrees

Then, we can simpily run the following BASH command to monitor the CPU frequency and Temperature for Raspberry PI every few seconds:

# monitor interval: every 3 seconds
while : ; do ./cpu_freq.sh; sleep 3; done

This is super useful if you are overclocking your raspberry PI e.g. 4B model you can tweak/overclock the ARM CPU to 2147 MHz and GPU to 750 MHz. You can modify the /boot/config.txt. Latest Raspberry PI models will automatically throttle the CPU if temperature gets too hot.

#uncomment to overclock the arm. 700 MHz is the default.
over_voltage=6
arm_freq=2147
force_turbo=1
gpu_freq=750

The `force_turbo` will enable CPU to run at maxium frequency even it is idle. After overclocking, you may also need to reduce the CPU temperature by plugin a heatsink or external Fan.

Most Raspberry PI External Fans are on 5V power – which you can see which two pins are for this by using the Raspberry PI utility pinout.

Overclocking Raspberry PI 4 to 2147MHz

Just make sure you have a good cooling for CPU before you overclock the Raspberry PI ARM CPU.

Raspberry Pi

–EOF (The Ultimate Computing & Technology Blog) —

506 words
Last Post: Algorithms to Determine a Ugly Number/Integer
Next Post: Teaching Kids Programming - QuickSort Algorithm Simply Explained (Python)

The Permanent URL is: BASH Script to Monitor the CPU Frequency and Temperature on Raspberry PI (AMP Version)

Exit mobile version