• 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: Raspberry Pi 5 Audio Card Raspberry Pi 5 PCIe to SATA Expansion Board with EEPROM HAT+ STM32 programmer X1200 Raspberry Pi 5 UPS Board Uninterruptible Power Supply For 18650-Li-Battery (NOT includ) Raspberry Pi Pico 2 RP2350B Industrial 8-Channel Relay IOT LAN Digital Input DIO /RS485 /RJ45 Ethernet /POE ESP32-S3 Industrial-Grade IOT RS485 CAN Communicator WiFi Bluetooth Industrial Modbus RTU RS485 8-ch 30A High Current Relay Module (E) With Digital Input 14 inch Dual LCD Computer PC Monitor Display Double Secondary Screen Type C Mini HDMI 1080P For Windows/MacOS Raspberry Pi Mini Sipeed Lichee Tang Nano 4K FPGA MINI Development Board W1NSR-LV4C GOAI Gowin Core3566002000 Jetson Orin 5G/4G/3G expansion board GNSS GPS SIM8260G-M2 SIM8262E-M2 Raspberry Pi Pico 2 RP2350 bit board Size & Port high Compatible With BBC Micro:bit Raspberry Pi 5 Jetson Nano Heatsink Jetson Nano IO Board USB-CAN-B Pi 5 PCIe to M.2 Raspberry Pi Display E-Paper Font Tutorial