• sales

    +86-0755-88291180

Raspberry Pi ------ 3.4 Control RGB light User Guide

4 Control RGB light

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.

This experimental phenomenon shows that all RGB light become green.

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 temp_control.zip file. 

As shown below:


Input command to extract file:

unzip temp_control.zip


2. Compiling and running program

2.1 Input command to enter temp_control find file:

cd temp_control/

ls


2.2 Input command to compile:

gcc -o rgb rgb.c -lwiringPi


Among them, the gcc compiler is called, -o means to generate the file, rgb is the generated file name, rgb.c is the source program, -lwiringPi is the wiringPi library that references the Raspberry Pi.

2.3 Input command to run the program

./rgb


We can see that all RGB light become green.

3. About code

3.1 There are three RGB lights on the expansion board, so the number of defined lights is 3, and the setRGB and closeRGB functions are declared.


3.2 void setRGB(int num, int R, int G, int B) function:

Set the RGB light color, num refers to which light, 0 is the first light, 1 is the second light, 2 is the third light. If it is greater than or equal to 3, then, all the lights are set at the same time. The R, G, and B values range from 0 to 255.


3.3 Turn off RGB. According to the protocol, the RGB register is turned off to 0x07 and the data is 0x00.


3.4 Initialize the I2C configuration in the main function.


3.5 Turn off the RGB light first, then set the RGB light. If it is not turned off first, it will affect the display effect. The effect of setRGB can be set by yourself.