• 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: TTL To CAN Raspberry Pi 5 Sound Card Raspberry Pi 5/4B easy Adapter Micro HDMI to HDMI 4K All Ports To Pi's USB Side Raspberry Pi UPS ESP32 C3 LCD Raspberry Pi 5 PCIe to M.2 5G/4G/3G HAT With RM520N-GL USB TO 2.5G Ethernet Port Converter RJ45 RTL8156B Driver-Free For Windows/macOS/Linux/Android RP2040 ESP32-S3N8R8 7inch LCD Display TouchScreen 800×480 WiFi Bluetooth CAN RS485 Sensor Raspberry Pi 5 PCIe to 4-CH M.2 NVMe 4-Ports SSD Board HAT Pi5 Four-Times Jetson Nano Expansion Board TVOC Sensor gas Sensor Expansion board UART High Sensitivity For Arduino /Raspberry Pi /Pico /ESP32 ESP32 UART USB Bus Servo ST RSBL Driver board For Raspberry PI Robot Raspberry Pi 5 Argon-NEO-M.2-NVME-PCIE-Expansion-Board Only For Argon NEO 5 Case (Not include) Thermal imaging camera Pi5 PCIe Sipeed NanoCluster Mini Cluster Board mini data center For Raspberry Pi CM45 / Computer /LM3H /M4N Computer USB Monitor Screen Raspberry Pi Compute Module 4 CM4 IO Board Dual Gigabit Ethernet Mini Router Board Zero LCD HAT (A) user guide