Last Updated on : 2025-08-04 06:42:25download
This demo uses Tuya’s BPx series modules and an RGB light strip with a WS2812B driver chip. It allows users to control individual bead colors, multiple scene modes, custom (DIY) lighting effects, and super bx-group (Tuya’s next-generation group control solution) by using the Tuya app.
Before getting started, prepare the following hardware products and connect them according to the table below.
| Feature | GPIO |
|---|---|
| Data pin of strip lights | P20 (SPI_MOSI) |
| UART_TX | P10 (BPU module’s RX) |
| UART_RX | P09 (BPU module’s TX) |
| Button (Active low) | P07 |
The button is optional for a manual reset. You can modify the code for alternative reset methods.
Log in to the Tuya Developer Platform and create a dreamcolor strip lights product. After the product is created, you will receive the list of two free licenses for subsequent testing. For more information, see Create Products.
Log in to Tuya Wind IDE and download the latest TuyaOS PHY6222 Bluetooth LE SDK.
For quick testing, you need to manually write the authorization information into the module. After completing debugging, you need to disable debug mode, write the authorization information to the module using Tuya’s host, and then copy and paste one of the two free licenses into the corresponding position of the macro definition below.
Download the compiled firmware to the module, reboot the module, and then use the Tuya app to try out this demo.
This demo consists of two parts: software initialization and processing of received DP data.
Software initialization
This is implemented in the OPERATE_RET tuya_init_last(VOID_T) function, including initialization of the light configuration parameters and SPI.
user_light_param_init();
user_spi_init(); // SPI initialization
user_light_init(); // Light initialization
Receive DP data
Data processing is implemented in VOID_T tuya_ble_protocol_callback(tuya_ble_cb_evt_param_t* event).
Receive and process the data of a single device
case TUYA_BLE_CB_EVT_DP_DATA_RECEIVED: {
app_tuya_vendor_light_dp_data(event->dp_received_data.p_data, event->dp_received_data.data_len);
} break;
Receive and process the data of the super bx-group
case TUYA_BLE_CB_EVT_GROUP_DP_DATA_RECEIVED: {
app_tuya_light_dp_group_data(event->group_dp_data_received.p_data, event->group_dp_data_received.data_len);
} break;
Before testing super bx-group functionality, scanning must be enabled.
Enter the \PHY6222_TuyaOS-3.12.0\software\TuyaOS\.log\ folder, open the generated Keil project, go to Project Options, and then change HOST_CONFIG=4 to HOST_CONFIG=6. Then, save and rebuild the project.

Log printing is a frequently used debugging feature. This example uses the module’s UART_TX (P9) pin for log output at 1,000,000 baud.
If you are debugging by using Tuya Wind IDE, you need to modify the project configuration through the Config feature of Tuya Wind IDE to enable printing.
After selecting both ENABLE_LOG and BOARD_ENABLE_LOG, save and exit the Config interface, and then rebuild the project to enable log printing.

If you are debugging by using Keil, to enable log printing, you can directly add these two macro definitions to app_config.h, and then rebuild the project.
#define ENABLE_LOG 1
#define BOARD_ENABLE_LOG 1
In the function void ty_light_json_config_devicecfg_data_init(void), two critical properties of the strip lights are configured: the number of beads and the RGB color order.
s_device_cfg.us_ic_num = 68; // The number of beads
s_device_cfg.colororder = GRB_ORDER;
The current project supports a maximum of 68 beads by default. You can modify the maximum number of beads based on the available memory status. It is recommended to refactor the transmission logic in the SPI transmit function.
Currently, in OPERATE_RET tal_spi_xfer(TUYA_SPI_NUM_E port_num, VOID_T *send_buf, VOID_T *recv_buf, UINT32_T length), a buffer is defined for sending data, while another buffer is defined at the application layer for storing transmission data. These can be optimized into a single buffer to save memory usage, enabling transmission of more bead data in a single operation.
void spi_master_tx(IN LIGHT_COLOR_RGB_S* p_tx_buff,IN u16 us_len);
After receiving the RGB data for each bead, this function will output WS2812B driving signals through the pre-configured SPI output pin (initialized earlier), sequentially lighting up the corresponding beads.
After completing debugging, if the program uses cloud-mode flashing to write authorization information, you need to comment out the TUYA_SDK_DEBUG_MODE macro definition in app_config.h. The method for commenting is the same as enabling log printing, with two available approaches. If using Tuya Wind IDE’s Config feature, for Keil development, you can simply comment it out in the source file.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback