RGB cooling HAT needs to be correctly inserted into the GPIO port of the Raspberry Pi and the I2C function of the Raspberry Pi must be turned on.
The phenomenon of this experiment is to read and print the Raspberry Pi CPU temperature, and adjust the color change of the RGB light according to the temperature.
The color distribution is: low temperature turns blue, medium temperature turns yellow, and high temperature turns red.
1.1 Enter the folder and view the files in the current folder
cd RGB_Cooling_HAT/
xxxxxxxxxx
ls
1.2 Run programm
xxxxxxxxxx
python rgb_temp.py
At this time, the terminal will print the current CPU temperature value, and the RGB light color will also change with the color change.
2.1 Initialize the Raspberry Pi I2C configuration, import the smbus module for I2C communication, the time module for delay, and the os module for accessing operating system service functions.
2.2 Define and set the RGB light function
2.3 Turn off the RGB lights first, and then set the RGB lights. If not turned off first, the display effect will sometimes be affected.
2.4 In the loop, use the command vcgencmd measure_temp to obtain the CPU temperature through os.popen to obtain the temperature, intercept the temperature value and assign it to temp.
2.5 After obtaining the temperature, determine the temperature value and modify the fan speed. It can be modified according to actual needs. For RGB light color correspondence, you can search online to view the RGB color comparison table.