【硬件开发】树莓派4B散热性能

树莓派4B散热性能

树莓派引脚

树莓派 40Pin 引脚对照表
rpi-pins-40-0
在这里插入图片描述

注:本表格适用于各版本,并且兼容26Pin的树莓派B,树莓派B为26Pin,其引脚对应于上表的前26Pin。

使用下面这款 GPIO 参考卡片,让引脚功能一目了然,接线操作起来更方便。
在这里插入图片描述

性能测试代码

要在树莓派4B上测试其性能并监测温度变化,可以编写一个Python脚本,利用stress命令来生成负载,使用vcgencmd命令来监测温度。以下是一个简单的例子:

  1. 安装所需的软件包:
sudo apt update
sudo apt install stress
  1. 编写Python脚本来执行性能测试并监控温度变化:
import os
import time
import subprocess

def get_temperature():
    result = subprocess.run(['vcgencmd', 'measure_temp'], capture_output=True, text=True)
    temp_str = result.stdout
    temp_value = float(temp_str.split('=')[1].split("'")[0])
    return temp_value

def run_stress_test(duration):
    # Start stress test
    stress_process = subprocess.Popen(['stress', '--cpu', '4', '--timeout', str(duration)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    return stress_process

def monitor_temperature(interval, duration):
    end_time = time.time() + duration
    while time.time() < end_time:
        temp = get_temperature()
        print(f"Temperature: {temp}°C")
        time.sleep(interval)

if __name__ == "__main__":
    test_duration = 300  # Test duration in seconds (e.g., 5 minutes)
    monitoring_interval = 10  # Interval in seconds to monitor temperature

    print("Starting stress test...")
    stress_process = run_stress_test(test_duration)
    
    print("Monitoring temperature...")
    monitor_temperature(monitoring_interval, test_duration)

    stress_process.wait()
    print("Stress test completed.")

说明:

  1. 安装依赖包:确保安装了stress命令来生成负载。
  2. 获取温度:get_temperature函数使用vcgencmd measure_temp命令来获取当前的CPU温度。
  3. 运行压力测试:run_stress_test函数使用stress命令来生成CPU负载,持续指定的时间。
  4. 监测温度变化:monitor_temperature函数定期(每隔指定的时间)获取并打印温度,持续整个测试期间。
  5. 主程序:设置测试的持续时间和监测间隔,运行压力测试,并在测试过程中监测温度。

将上述代码保存为stress_test.py并运行:

python3 stress_test.py

这将会开始性能测试并每隔指定的时间打印树莓派的温度。你可以根据需要调整测试的持续时间和监测间隔。

此外,也可以通过以下命令查看温度:

watch -n 1 "awk '{print \"当前温度为: \" int(\$1/1000) \"°C\"}' /sys/class/thermal/thermal_zone0/temp"
# 或者
watch -n 1 "awk '{printf \"当前温度为: %.1f°C\\n\", \$1/1000}' /sys/class/thermal/thermal_zone0/temp"

reference

@misc{BibEntry2024Aug,
title = {{树莓派 40Pin 引脚对照表 { ∣ \vert } 树莓派实验室}},
year = {2024},
month = aug,
urldate = {2024-08-02},
language = {chinese},
note = {[Online; accessed 2. Aug. 2024]},
url = {https://shumeipai.nxez.com/raspberry-pi-pins-version-40}
}

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

或许,这就是梦想吧!

如果对你有用,欢迎打赏。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值