Read Raspberry Pi 4B processing unit (CPU) real-time temperature
After Raspberry Pi release 4B, performance improved a lot, but the temperature is not high, so it is best to configure a small fan and heat sink is quite good
Two kinds of measures can be implemented
1.Shell command reads
Open a terminal
cd /sys/class/thermal/thermal_zone0
Check temperature
cat temp
Raspberry Pi return value
53069
The return value is divided by 1000 the current value of the CPU temperature. That the current temperature is 53 degrees Celsius. As shown below
2. write a program to read c language
Here, I basically copied https://blog.csdn.net/xukai871105/article/details/38349209 code,
Under revised increase of reading the print cycle 1s for a total of 100 times print program exits, so easy to see when the real-time refresh
Source Code
It is to look at the temperature / sys / class / thermal / thermal_zone0 / temp files
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 #include<sys/types.h> 5 #include<sys/stat.h> 6 #include<fcntl.h> 7 8 #define TEMP_PATH "/sys/class/thermal/thermal_zone0/temp" 9 #define MAX_SIZE 32 10 11 int main(void) 12 { 13 int fd; 14 double temp = 0; 15 char buffer[MAX_SIZE]; 16 int i; 17 18 while(i < 100) 19 { 20 i+=1; 21 22 //延时1s 23 sleep(1); 24 25 //打开文件 26 fd = open(TEMP_PATH,O_RDONLY); 27 if(fd < 0) 28 { 29 fprintf(stderr,"Failed to open thermal_zone0/temp\n"); 30 return - 1; 31 } 32 33 //Reading the file 34 is IF (Read (FD, Buffer, MAX_SIZE) < 0 ) 35 { 36 fprintf (stderr, " the Failed to Read TEMP \ n- " ); 37 [ return - . 1 ; 38 is } 39 40 // calculated temperature value 41 is TEMP atoi = (Buffer) / 1000.0 ; 42 is 43 is // printout temperature 44 is the printf ( " the Temp:. 4F% \ n- " , TEMP); 45 46 is // close file 47 Close (FD); 48 } 49 }
Write code
Create a program and open the file ReadTemp.c write code
Compile and run results
gcc -o ReadTemp ReadTemp.c there are three compiler warning, you can not ignore it, you can generate executable file to run the program ReadTemp input ./ReadTemp
(I installed fans and heat sinks and housing, probably average about 53 degrees Celsius)
hardware information
Information cpu and memory information