• sales

    +86-0755-88291180

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

3 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: Industrial Isolated RS485 TO ETH (C) RJ45 Converter Wall/Rail-Mount For Modbus SpotPear FLASH File System Operation Jetson Orin Case GC9107 Raspberry Pi 24.5 inch Type C/HDMI 2K Display 24.5inch Screen 2560x1440 Computer PC Phone For Xbox/PS4/Switch USB Camera 2MP GC2093 ‌WDR Backlight Compensation‌ Onboard microphone Raspberry Pi 5 PD Power Raspberry Pi PICO Keyboard Pi5-Active-Cooler-C JETSON NANO B01 Raspberry Pi Pico 2.15 inch e-Paper HAT+ B E-Ink Red/Black/White 296×160 Screen Display For Arduino /Raspberry Pi /Jetson Nano /STM32 LCC-14 VGA to LVDS 7inch-DSI-LCD-H User Guide Raspberry Pi 10.85 inch e-Paper ink screen display black white 1360×480 For Arduino /Jetson /STM32 /ESP32 i7-1165G7 Mobile Robot Raspberry Pi 12.3 inch LCD HDMI /Type C Display In-Cell Capacitive TouchScreen 1920x720 For Jetson Nano/mini Computer PC