-
-
Save tmuka/3b1c74934e67dd046df6f43aa25711ce to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# This bash script outputs the status of your Pi and checks whether you are being throttled for undervoltage and gives you your temperature | |
# Article and discussion at https://jamesachambers.com/measure-raspberry-pi-undervoltage-true-clock-speeds/ | |
# Author James A Chambers 6-6-17 | |
# updated throttle reason codes by tmuka 2021-10 | |
# Output current configuration | |
vcgencmd get_config int | egrep "(arm|core|gpu|sdram)_freq|over_volt" | |
# Measure clock speeds | |
# for src in arm core h264 isp v3d; do echo -e "$src:\t$(vcgencmd measure_clock $src)"; done | |
# output human readable cpu speeds in GHz if you want raw data, use the previous line instead. | |
for src in arm core h264 isp v3d; do echo -e "$src:\t$(vcgencmd measure_clock $src | awk ' BEGIN { FS="=" } ; { printf("%.1fGHz\n", $2 / 1000000000) } ')"; done | |
# Measure Volts | |
for id in core sdram_c sdram_i sdram_p ; do echo -e "$id:\t$(vcgencmd measure_volts $id)"; done | |
# Measure Temperature | |
vcgencmd measure_temp | |
# See if we are being throttled | |
throttled="$(vcgencmd get_throttled)" | |
echo -e "$throttled" | |
if [[ $throttled != "throttled=0" ]]; then | |
# echo "WARNING: You are/have been throttled." | |
# updated warnings details based on https://raspberrypi.stackexchange.com/a/91433 | |
# https://forum.libreelec.tv/thread/17860-how-to-interpret-rpi-vcgencmd-get-throttled/ | |
# NOTE: The script is slightly out of date as bits 3 and 19 have now been added since the page was published. So | |
# 0x0 means nothing wrong | |
# 0x50000 means throttled has occurred since the last reboot. | |
# 0x50005 means you are currently under-voltage and throttled. | |
# | |
# Bit Hex value Meaning | |
# 0 1 Under-voltage detected | |
# 1 2 Arm frequency capped | |
# 2 4 Currently throttled | |
# 3 8 Soft temperature limit active | |
# 16 10000 Under-voltage has occurred | |
# 17 20000 Arm frequency capping has occurred | |
# 18 40000 Throttling has occurred | |
# 19 80000 Soft temperature limit has occurred | |
case $throttled in | |
"throttled=0x0") | |
echo "0x0 nothing wrong" | |
;; | |
"throttled=0x50000") | |
echo "0x50000 throttling occurred since last reboot" | |
;; | |
"throttled=0x50005") | |
echo "0x50005 currently under voltage and throttled." | |
;; | |
"throttled=0x1") | |
echo "0 1 Under-voltage detected" | |
;; | |
"throttled=0x2") | |
echo "1 2 Arm frequency capped" | |
;; | |
"throttled=0x4") | |
echo "2 4 Currently throttled" | |
;; | |
"throttled=0x8") | |
echo "3 8 Soft temperature limit active"; | |
;; | |
"throttled=0x10000") | |
echo "16 10000 Under-voltage has occurred" | |
;; | |
"throttled=0x20000") | |
echo "17 20000 Arm frequency capping has occurred" | |
;; | |
"throttled=0x40000") | |
echo "18 40000 Throttling has occurred" | |
;; | |
"throttled=0x80000") | |
echo "19 80000 Soft temperature limit has occurred" | |
;; | |
esac | |
fi |
updated so the script outputs human readable clock speeds in GHz instead of raw Hz.
added bits 3 and 19 data from https://forum.libreelec.tv/thread/17860-how-to-interpret-rpi-vcgencmd-get-throttled/
Hello.
Nice script, but I got error on line 24, because there are double brackets. After change to single bracket it's OK.
Also shouldn't be the result determined by bit mask, not only by comparison?
Hi @Benik3 the double brackets worked okay for me in Bash, maybe you're running a different shell? Yes, a bitmask would be better to detect when more than one of the conditions has occurred. I'd welcome your input on how to achieve that.
I'm running RPi Zero 2 W with latest Raspbian lite. I was connected with putty and run the bash simply by sh measurepi.sh
Maybe I will look on the bit mask, I'm new in RPi and bash, so I'm learning it just now :)
oh- i see there is more room for improvement as more than one of these bits may coexist. eg. i just saw "throttled=0x80008" which should report both present and past "soft temperature limit has occurred".