• sales

    +86-0755-88291180

Raspberry Pi ------ 4.3 Get CPU temperature,Adjust fan speed User Guide

Get CPU temperature,Adjust fan speed

The Raspberry Pi RGB_Cooling_HAT needs to be properly plugged into the GPIO port of the Raspberry Pi and open the Raspberry Pi system I2C function.

The experimental phenomenon is to read and print the Raspberry Pi CPU temperature, and adjust the speed of the fan rotation according to the temperature. The higher the temperature, the faster the rotation speed.

1. File transfer

1.1 Install WinSCP tool on the computer side, connect the Raspberry Pi and transfer the temp_control.zip package to the pi directory of the Raspberry Pi.

Path of WinSCP:[Raspberry Pi RGB_Cooling_HAT]---[Tools]---[winscp556_setup.1416364912.exe]


1.2 Extract file

Open the Raspberry Pi terminal and input command ls to find the RGB_Cooling_HAT.zip file. 

As shown below:


Input command to extract file:

unzip RGB_Cooling_HAT.zip


2. Compiling and running program

2.1 Input command to enter temp_control find file:

cd RGB_Cooling_HAT./

ls


2.2 2.2 Input command to run program.

python fan_temp.py 


After run this program, we can see the Raspberry Pi CPU temperature will be printed, and adjust the speed of the fan rotation according to the temperature. The higher the temperature, the faster the rotation speed.

3. About code

3.1 Initialize Raspberry Pi I2C configuration, import smbus module for I2C communication, import time module for delay, and import os module for access to operating system services


3.2 In the loop, use os.popen to obtain the temperature using the command vcgencmd measure_temp to obtain the CPU temperature, and intercept the temperature value and assign it to temp.


Get the temperature, then judge the temperature value and modify the fan speed.

It can be modified according to actual needs.


TAG: Milk-V Duo S WIFI Configuration Milk-V Duo Ethernet ESP32 desktop trinket Argon ONE V3 Case with FAN IR For Raspberry Pi 5 Raspberry Pi 3.5 inch DSI Display MIPI LCD (H) Capacitive TouchScreen 480x800 Pico-DALI2 Expansion Board For ESP32 C6 S3 DALI communication control multiple LED ESP32-S3 Development Board 4 inch LCD TouchScreen Display 480x480 RS485 /SHT20 /Relay For Arduino LVGL 86 TVbox RS485 Bus DeepSeek AI Voice Chat ESP32 S3 Development Board 1.8 inch AMOLED Display 368×448 1.8inch TouchScreen Programmable Watch QMI8658 /MIC /Audio /Battery Industrial Isolated USB TO 4CH RS485 (B) Converter UART CH344L For Wall/Rail-Mount Raspberry Pi 5 5V5A Power Raspberry Pi WatchDog luckfox-pico-ultra-w-WIFI-Bluetooth Spotpear DeepSeek XiaoZhi AI Voice Chat Robot BOX ESP32-S3 Development Board 1.28 inch Round LCD 1.28inch TouchScreen N16R8 Raspberry Pi MIPI Luckfox Pico MINI BPI PI5 Raspberry Pi CM5 to Pi 5 Expansion Board With USB microphone & Audio Port