• 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.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: Servo PWM motor WP5320 WP5335 35/20KG.CM 180° PWM digital servo double ball bearings Raspberry Pi UGV Beast ROS2 PT AI OpenCV Robot Car MediaPipe USB Binocular Camera 2MP OS02G10 Distortion Free Binocular Synchronous Frame USB 2.0 Plug and Play Raspberry Pi 5 UPS HAT E 4-Port For 21700-Li-Battery (NOT includ) 5V6A Uninterruptible Power Supply 3D Display Transparent Screen NVIDIA Jetson Xavier NX AI 21TOPS Supercomputer Edge Computing eMMC-16GB RAM 8/16GB ESP32 2 inch Capacitive TouchScreen LCD Display ST7789 CST816D 240x320 For Arduino/Raspberry Pi/Pico Industrial UART USB TO 8CH RS485 Isolated Converter For 35mm standard rail and stacked installation Raspberry Pi 5 Silver-Shadow Case Raspberry Pi IR Thermal Imaging Camera Milk V spotpear Raspberry Pi 13.3 inch DSI MIPI Display 13.3inch LCD Capacitive TouchScreen 1920x1080 RS232 to RS485 ESP32-S3 Relay 6-Channel IOT WiFi Bluetooth RS485 Pico Protection Circuits Raspberry Pi Touch Display 2 Official Original Capacitive TouchScreen 7 inch LCD TFT 720x1280 Raspberry Pi Audio Raspberry Pi 5 Power Raspberry Pi SIM7670G LTE-4G-Cat-1/GNSS/USB-HUB Expansion Board Raspberry Pi 21.5 inch Type C/HDMI Display Screen 1920x1080 Computer PC Phone Xbox/PS4/Switch