• 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: ESP32 Thermal imaging camera UNO Minima RA4M1 ZERO Tiny SuperMini R7FA4M1 Board Compatible With R4 For Arduino Core3566004000 BPI-M4 Zero ESP32-S3 7inch LCD Display 7 inch TouchScreen 7B 1024×600 N16R8 CAN RS485 Sensor ESP32-S3 Development Board 4 inch LCD TouchScreen Display 480x480 RS485 /SHT20 /Relay For Arduino LVGL 86 TVbox ESP32-S3 0.85inch LCD 4 inch e Paper HAT+ E Ink Spectra E6 Full-Color 600x400 Screen Display For Arduino /Raspberry Pi /Jetson Nano /STM32 Raspberry Pi 9.7 inch e-Paper HAT+ (E) E-Ink E6 Full color 1120x784 Screen Display For Arduino /STM32 /ESP32/Jetson Nano Raspberry Pi HQ Camera Official Original High Quality For M12 Lenses 12.3MP IMX477 Sensor Raspberry Pi 5 PCIe to M.2 NVMe SSD Adapter Board HAT Spotpear ESP32 C5 Development Board 2.73 inch LCD Display Screen ILI9488 For Dual band WiFi Onborad SD-Port Raspberry Pi 5 PCIe To M.2 E KEY NGFF WIFI7 WIFI6 For BE200/AX210/AX200/RTL8822CE 2.66inch e-Paper e-link Module 360x184 4-Color Red Yellow Black White For Arduino Raspberry Pi STM32 Jetson Tutorial Information Wiki Program Code User Guide SpotPear 7inch-USB-Monitor user guide Raspberry Pi Pico 2 RP2350-Matrix Development Board 8×8 RGB LED Matrix QMI8658 6-Axis Sensor Pi 5 PCIe to M.2 NVMe SSD Board Raspberry Pi Pico Raspberry Pi 5 RTC charge