树莓派3B+/4B报告“low voltage warning”

需求场景

用的好好的树莓派,有一天连接VNC,发现桌面任务栏一直提示

low voltage warning,please check your power supply

如下图:

看样子是供电不足,可是树莓派的负载并不高啊。

解决方案

搜了一大圈基本都是说电源的问题,现在使用的电源是以前小米2/小米Note手机自带的电源。经过反复测试,发现跟温度有关,冬天的时候问题不大,到了夏天,由于老式电源转换效率低,大量电能被转换成了热量,导致长时间充电后,温度上升很快,引起降压,断电后过一段时间就可以了,但是一旦温度上升到一定程度,问题依旧。

后来买了个努比亚大白20W氮化镓充电器之后,就不会报告这个错误了。氮化镓的充电器转化效率更高,升温更少,并且更耐高温。

由于这个提示只有在连接显示器或VNC连接时才能在GUI桌面任务栏看到,如果是SSH登录就看不到了,非常的不方便。最好是能够通过命令判断是否电压不足。

具体的脚本详见 https://gist.github.com/maxme/d5f000c84a4313aa531288c35c3a8887

通过此脚本可以查看CPU和电压不足的问题。不过每次登录之后需要手动运行,实在不方面。而且脚本中采用了while循环需要手动中断脚本。所以可以把代码中的while循环去掉,并且在SSH登录的时候执行命令病输出到登录信息上。

注意电压充足的情况下,输出电压为1.2V,而不是 5V,主板的5V是没办法通过脚本直接测量的。我们只能通过脚本测量CPU、内存控制器、内存输入输出、内存本身的电压,主板电压只能用万用表来测量。

效果如下,具体方式参考 ubuntu修改ssh登录提示信息

修改后的raspberry-power-supply-check.sh代码如下:

#!/bin/bash
function throttleCodeMask {
  perl -e "printf \"%s\", $1 & $2 ? \"$3\" : \"$4\""
}
function throttledToText {
  throttledCode=$1
  throttleCodeMask $throttledCode 0x80000 "Soft temperature limit has occurred, " ""
  throttleCodeMask $throttledCode 0x40000 "Throttling has occurred, " ""
  throttleCodeMask $throttledCode 0x20000 "Arm frequency capping has occurred, " ""
  throttleCodeMask $throttledCode 0x10000 "Under-voltage has occurred, " ""
  throttleCodeMask $throttledCode 0x8 "Soft temperature limit active, " ""
  throttleCodeMask $throttledCode 0x4 "Currently throttled, " ""
  throttleCodeMask $throttledCode 0x2 "Arm frequency capped, " ""
  throttleCodeMask $throttledCode 0x1 "Under-voltage detected, " ""
}
temp=$(vcgencmd measure_temp | cut -f2 -d=)
real_clock_speed=$(vcgencmd measure_clock arm | awk -F"=" '{printf ("%0.0f", $2 / 1000000); }' )
sys_clock_speed=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
voltage=$(vcgencmd measure_volts | cut -f2 -d= | sed 's/000//')
throttled_text=$(throttledToText $(vcgencmd get_throttled | cut -f2 -d=))
echo "$temp $sys_clock_speed / $real_clock_speed MHz $voltage - $throttled_text"

参考链接