Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read the real-time temperature of raspberry pie 4B processor (CPU)

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to read the real-time temperature of raspberry pie 4B processor (CPU). The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Read the real-time temperature of raspberry pie 4B processor (CPU)

Raspberry pie after the release of 4B, the performance has improved a lot, but the temperature is not high, so it is better to configure a small fan and heat sink, the effect is obvious.

1.Shell command to read the open terminal cd / sys/class/thermal/thermal_zone0 to view the temperature cat temp raspberry pie return value of 35050

The return value divided by 1000 is the current CPU temperature value. That is, the current temperature is 53 degrees Celsius. As shown in the following figure

two。 Write a c language program to read the program source code

The temperature is seen under the / sys/class/thermal/thermal_zone0/temp file.

Write code

Create the program file read_cpu_temp.c and open it to write code

/ / read the real-time temperature of raspberry pie 4B processor (CPU) / / compile / / gcc-o read_cpu_temp read_cpu_temp.c// run /. / read_cpu_temp#include#include#include#include#include#define TEMP_PATH "/ sys/class/thermal/thermal_zone0/temp" # define MAX_SIZE 32int main (void) {int fd; double temp = 0; char buffer [Max _ SIZE]; int i; while (I

< 100) { i+=1; //延时1s sleep(1); //打开文件 fd = open(TEMP_PATH,O_RDONLY); if(fd < 0) { fprintf(stderr,"Failed to open thermal_zone0/temp\n"); return - 1; } //读取文件 if(read(fd,buffer,MAX_SIZE) < 0) { fprintf(stderr,"Failed to read temp\n"); return -1; } //计算温度值 temp = atoi(buffer) / 1000.0; //打印输出温度 printf("Temp:%.4f\n",temp); //关闭文件 close(fd); }}编译运行结果gcc -o read_cpu_temp read_cpu_temp.c 编译程序出现三个警告,可以不用管它,生成可以执行文件read_cpu_temp 输入./read_cpu_temp运行程序 ./read_cpu_temp

(I installed a fan, a heat sink and a housing, which averaged about 36 degrees Celsius.)

3. Write Erlang programs, read and write code

Create the program file read_cpu_temp.erl and open it to write code

%% -%% @ author SummerGao%%% @ copyright (C) 2020 %% @ doc% @ end%%% Created: 15. July 2020 13:59%%%----module (read_cpu_temp).-author ("SummerGao").% API -export ([loop/0]) .loop ()-> {ok Original} = file:read_file ("/ sys/class/thermal/thermal_zone0/temp"), [A, _] = binary:split (Original, []), T = binary_to_integer (A) / 1000, io:format ("Temp ℃: ~ pairn", [T]), timer:sleep (1000), loop (). Compile and run the result Erlang/OTP 22 [erts-10.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] Eshell V10.4 (abort with ^ G) 1 > c (read_cpu_temp). {ok,read_cpu_temp} 2 > read_cpu_temp:loop (). Get hardware-related information and view cpu information lscpu

View memory information free-h

This is the end of the real-time temperature sharing on how to read the raspberry pie 4B processor (CPU). I hope the above content can be of some help and learn more. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report