• sales

    +86-0755-88291180

Raspberry Pi ------ 4.5 Change RGB color according to CPU temperature User Guide

5 - Change RGB color according to CPU temperature

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, adjust the color change of the RGB lamp according to the temperature.

The color distribution is roughly as follows: the low temperature turns blue, the medium temperature turns yellow, and the high temperature turns red.

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.zipfile. 

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 Input command to run program

python rgb_temp.py


The terminal will print the current CPU temperature value, and the RGB light color will also change with the color change.

3. About code

3.1 Initialize the 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 Define RGB light function


3.3 Turn off the RGB lights first, and then set the RGB lights. If you do not turn off the lights, it will affect the display effect.


3.4 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.


3.5 Obtain the temperature, determine the temperature value, and modify the fan speed.

It can be modified according to actual needs. The RGB lamp color correspondence can be searched online to view the RGB color comparison table.


TAG: Raspberry Pi Pico Basics User Guide Raspberry Pi ST7789 X1015 Raspberry Pi 5 PCIe to M.2 Key-M NVMe SSD Board Pi5 2280 Sipeed NanoCluster Mini Cluster Board mini data center For Raspberry Pi CM45 / Computer /LM3H /M4N ESP32-S3 AI 1.54-inch e-Paper Ink Screen 1.54inch Display AIoT Development Board Deepseek ESP32 C6 AI 0.85inch Development Board 0.85 inch DeepSeek RGB surround light Dual mike Raspberry Pi Pico 2 RP2350 2.8 inch LCD Capacitive TouchScreen Development Board 240x320 Display QMI8658 6-Axis /PCM5101 Audio /SD /RTC /Battery Port ESP32-S3 Round Screen Tutorial Raspberry Pi Compute Module 5 CM5 Cortex A76 BCM2712 With/Without Wi-Fi RAM 2/4/8/16GB eMMC Lite/8/16/32/64GB Retail electronic Labe ESP32-P4 Pico WIFI6 Development Board C6 MIPI DSI 10.1-inch Display /CSI Camera /Audio Speaker Mic AI Deepseek ESP32 ST7789 configuration Mini TOF Time-of-Flight Laser Ranging Radar Sensor Compatible UART with Arduino Raspberry Pi ESP32 and Pico Raspberry Pi 8/10.1inch Touch Screen industrial All-in-one Aluminum enclosure supporting 4K output Servo PWM motor WP5320 WP5335 35/20KG.CM 180° PWM digital servo double ball bearings Luckfox Pico Camera MIS5001 5MP wide-angle lenses‌ For RV1106/Pro/MAX/Ultra (Not For RV1103 Pico) Raspberry Pi 5 Industrial Modbus RS485 RTU 8-ch Magnetic Latching Relay Module (C) With Digital Input ESP32-S3 ST7789