61
9 How to Control WS2812 RGB LED
●WS2812 LED light is a commonly used module on our robot products. There are three WS2812 lights on
each module. Please pay attention when connecting. The signal line is different in direction, which needs to be
connected to WS2812 after being led out from the Raspberry Pi. The IN end of the LED lamp module, when the
next WS2812 LED module needs to be connected, the signal line is led out from the OUT end of the previous
WS2812 module and connected to the IN end of the next WS2812 LED.
●When using the Raspberry Pi with the driver board Motor HAT installed, the WS2812 LED module can
be connected to the WS2812 interface on the Motor HAT using a 3pin cable.
●We use a third-party library
project on GitHub.
●If you connect the WS2812 LED module to Motor HAT's WS2812 interface, the signal line is equivalent
to the Raspberry Pi On GPIO 12, information about the pin number of the Raspberry Pi can refer to this official
document
GPIO
●Use the following command to install rpi_ws281x for the Raspberry Pi. Since the Raspberry Pi has two
versions of Python built in, the Python3 code is used as an example, so pip3 is adopted to install the library.
pip3 install rpi-ws281x
● Next, we will explain the program. This program is written in the Raspberry Pi and executed in the
Raspberry Pi. For the specific method, you can refer to 8 Programming in the Raspberry Pi.
●Import dependencies
import
time
from
rpi_ws281x
●Construction of LED control class
rpi_ws281x
import
*
to control the WS2812 LED light, you can learn more about this
Need help?
Do you have a question about the AWR Adeept Wheeled Robot and is the answer not in the manual?