Lighting Product Development Kit

Last Updated on : 2024-08-06 13:20:31download

This topic describes a Zigbee light demo built on top of the TuyaOS platform, featuring on/off control and adjustable brightness, color temperature, and color.

Overview

Features

  • When connected to a Tuya-enabled gateway, the Zigbee light can be remotely controlled through a Tuya-based mobile app, enabling users to control features including on/off, brightness, color temperature, HSV color, scenes, and music synchronization.
  • The kit includes handlers for most standard Zigbee 3.0 commands, ready to use after the Zigbee device is connected to a Zigbee 3.0 gateway.
  • Zigbee Touchlink networking and control.

Actions and behaviors

  • Device pairing

    • When POWER_ON_AUTO_JOIN in light_app_config.h is set to 1, an unpaired device will automatically start pairing after power on.

    • When POWER_ON_AUTO_JOIN in light_app_config.h is set to 0, pairing must be initiated manually. Power cycle the light to reset it, ensuring the number of cycles is greater than or equal to SCAN_NETWORK_RESET_COUNT. During the reset, the power cycle duration must not exceed five seconds. Otherwise, the count will be reset.

    • The pairing timeout is specified with ZIGBEE_JOIN_TIMEOUT_MS.

    • When the light starts pairing, it will indicate the status. When SCAN_NETWORK_PROMPT_METHOD is set to 0, the light blinks. When set to 1, it fades in and out. Specify the status indication duration with SCAN_NETWORK_PROMPT_TIME_S, which should typically be less than or equal to ZIGBEE_JOIN_TIMEOUT_MS.

    • Specify the indication behavior and HSVBT data during pairing as well as the solid on mode and HSVBT data after pairing with app_light_prompt_ctrl_start in app_light_prompt.c.

           //prompt start data
           prompt_start_data.on_off = TRUE;
        #if (APP_LIGHT_CHANNELS == 3)
           prompt_start_data.mode = COLOR_MODE;
        #else
           prompt_start_data.mode = WHITE_MODE;
        #endif
           prompt_start_data.b_data = 1000;    //range: 0-1000
           prompt_start_data.t_data = 1000;    //range: 0-1000
           prompt_start_data.h_data = 0;       //range: 0-360
           prompt_start_data.s_data = 1000;    //range: 0-1000
           prompt_start_data.v_data = 1000;    //range: 0-1000
      
           //prompt stop data
           prompt_stop_data.on_off = TRUE;
        #if (APP_LIGHT_CHANNELS == 3)
           prompt_stop_data.mode = COLOR_MODE;
        #else
           prompt_stop_data.mode = WHITE_MODE;
        #endif
           prompt_stop_data.b_data = 1000;     //range: 0-1000
           prompt_stop_data.t_data = 1000;     //range: 0-1000
           prompt_stop_data.h_data = 0;        //range: 0-360
           prompt_stop_data.s_data = 1000;     //range: 0-1000
           prompt_stop_data.v_data = 1000;     //range: 0-1000
      
    • Pair the light with a gateway. See the Pairing Instructions.

    • After the light is paired, it will be solid on and appear in the mobile app.

    • If the pairing times out (180 seconds by default), the light will return to solid on.

Create product

For more information about product creation, see Create Products.

Protocol details

Zigbee basics

Parameter Value
Profile ID 0x0104
Device ID
  • 0x0101: Cool white light (C)
  • 0x010C: Warm to cool white light (CW)
  • 0x0102: Colored light (RGB)
  • 0x010D: Cool white and colored light (RGBC) and white and colored light (RGBCW)

Endpoint

Endpoint Description
0x01 The endpoint of the current light.
0xF2 The endpoint of a Green Power device.

Supported clusters

Endpoint 0x01

Input clusters (server) Output clusters (client)
Basic (0x0000) OTA Upgrade (0x0019)
Identify (0x0003) Time (0x000A)
Groups (0x0004) /
Scenes (0x0005) /
On/Off (0x0006) /
Level Control (0x0008) /
Color Control (0x0300) /
Touchlink Commissioning (0x1000) /

Endpoint 0xF2

Input clusters (server) Output clusters (client)
/ Green Power (0x0021)

Supported attributes and commands

Basic cluster

Attributes

ID Name Data type (ID) Range Default
0x0000 ZCLVersion uint8 (0x20) 0x00 to 0xff 0x03
0x0001 ApplicationVersion uint8 (0x20) 0x00 to 0xff For example, 0b 01 00 0001 indicates 1.0.1, that is, 0x41 represents version 1.0.1. This attribute is used for OTA updates. When an OTA update is initiated, the gateway reads the version number of the update and pushes it to the Zigbee device. After the Zigbee device is restarted after the update, the gateway reads the current version to check for the update result. The firmware can only be updated to a higher version.
0x0002 StackVersion uint8 (0x20) 0x00 to 0xff 0x02
0x0003 HWVersion uint8 (0x20) 0x00 to 0xff 0x01
0x0004 ManufacturerName string (0x42) 0 to 32 bytes XXX…XXX. The value of this attribute is 16 bytes in length, consisting of an 8-byte prefix and 8-byte PID.
0 to 7 bytes: _TZ3000_.
8 to 16 bytes: The PID, the unique identifier of the Zigbee product you create on the Tuya Developer Platform. This field determines the UI and feature display on the mobile app. You can use the default PID if you do not require a custom one.
0x0005 ModelIdentifier string (0x42) 0 to 32 bytes TS0505B
0x0007 PowerSource enum8 (0x30) 0x00 to 0xff 0x01
0xFFFD ClusterRevision uint16 (0x21) 0x0000 to 0xffff 0x0001

Identify cluster

Attributes

ID Name Data type (ID) Range Default
0x0000 IdentifyTime uint16 (0x21) 0x0000 to 0xffff 0x0000
0xFFFD ClusterRevision uint16 (0x21) 0x0000 to 0xffff 0x0001

Commands

ID Name Direction
0x00 Identify Client to server
0x01 Identify Query Client to server

Groups cluster

Attributes

ID Name Data type (ID) Range Default
0x0000 NameSupport map8 (0x18) desc 0x00
0xFFFD ClusterRevision uint16 (0x21) 0x0000 to 0xffff 0x0002

Commands

ID Name Direction
0x00 Add group Client to server
0x01 View group Client to server
0x02 Get group membership Client to server
0x03 Remove group Client to server
0x04 Remove all groups Client to server
0x05 Add group if identifying Client to server

Scenes cluster

Attributes

ID Name Data type (ID) Range Default
0x0000 SceneCount uint8 (0x20) 0x00 to 0xff 0x00
0x0001 CurrentScene uint8 (0x20) 0x00 to 0xff 0x00
0x0002 CurrentGroup uint16 (0x21) 0x0000 to 0xfff7 0x0000
0x0003 SceneValid bool (0x10) 0 or 1 0x00
0x0004 NameSupport map8 (0x18) desc 0x00
0xFFFD ClusterRevision uint16 (0x21) 0x0000 to 0xffff 0x0002

Commands

ID Name Direction
0x00 Add group Client to server
0x01 View group Client to server
0x02 Get group membership Client to server
0x03 Remove group Client to server
0x04 Remove all groups Client to server
0x05 Add group if identifying Client to server

On/Off cluster

Attributes

ID Name Data type (ID) Range Default
0x0000 On/Off bool (0x10)
  • 0: Off
  • 1: On
0x00
0xFFFD ClusterRevision uint16 (0x21) 0x0000 to 0xffff 0x0002

Commands

ID Name Direction
0x00 Off Client to server
0x01 On Client to server
0x02 Toggle Client to server

Level Control cluster

Attributes

ID Name Data type (ID) Range Default
0x0000 CurrentLevel uint8 (0x20) 0x01 to 0xfe 0xfe
0x000F Options map8 (0x18) desc 0x00
0xFFFD ClusterRevision uint16 (0x21) 0x0000 to 0xffff 0x0002
Commands
ID Name Direction
0x00 Move to Level Client to server
0x01 Move Client to server
0x02 Step Client to server
0x03 Stop Client to server
0x04 Move to Level (with On/Off) Client to server
0x05 Move (with On/Off) Client to server
0x06 Step (with On/Off) Client to server
0x07 Stop (with On/Off) Client to server

Color Control cluster

Attributes

ID Name Data type (ID) Range Default
0x0000 CurrentHue uint8 (0x20) 0x00 to 0xfe 0x00
0x0001 CurrentSaturation uint8 (0x20) 0x00 to 0xfe 0xfe
0x0003 CurrentX uint16 (0x21) 0x0000 to 0xfeff 0x0000
0x0004 CurrentY uint16 (0x21) 0x0000 to 0xfeff 0x0000
0x0007 ColorTemperatureMireds uint16 (0x21) 0x0000 to 0xfeff 0x0000
0x0008 ColorMode enum8 (0x30) 0x00 to 0x02 0x02
0x000F Options map8 (0x18) / 0x00
0x0010 NumberOfPrimaries uint8 (0x20) 0x00 to 0x06 0xff
0x4001 EnhancedColorMode enum8 (0x30) 0x00 to 0xff 0x02
0x400A ColorCapabilities map16 (0x19) 0x0000 to 0x001f 0x0019
0x400B ColorTempPhysicalMinMireds uint16 (0x21) 0x0000 to 0xfeff 0x0099
0x400C ColorTempPhysicalMaxMireds uint16 (0x21) 0x0000 to 0xfeff 0x01F4
0x400D CoupleColorTempToLevelMinMireds uint16 (0x21) ColorTempPhysicalMinMireds to ColorTempPhysicalMaxMireds 0x0099
0x4010 StartUpColorTemperatureMireds uint16 (0x21) 0x0000 to 0xfeff 0x0099
0xFFFD ClusterRevision uint16 (0x21) 0x0000 to 0xffff 0x0002

Commands

ID Name Direction
0x00 Move to Hue Client to server
0x01 Move Hue Client to server
0x02 Step Hue Client to server
0x03 Move to Saturation Client to server
0x04 Move Saturation Client to server
0x05 Step Saturation Client to server
0x06 Move to Hue and Saturation Client to server
0x07 Move to Color Client to server
0x08 Move Color Client to server
0x09 Step Color Client to server
0x0a Move to Color Temperature Client to server
0x47 Stop Move Step Client to server
0x4b Move Color Temperature Client to server
0x4c Step Color Temperature Client to server

Touchlink Commissioning cluster

Attributes

ID Name Data type (ID) Range Default
0xFFFD ClusterRevision uint16 (0x21) 0x0000 to 0xffff 0x0001

Commands

ID Name Direction
0x00 Scan request Client to server
0x02 Device information request Client to server
0x06 Identify request Client to server
0x07 Reset to factory new request Client to server
0x10 Network start request Client to server
0x12 Network join router request Client to server
0x14 Network join end device request Client to server
0x16 Network update request Client to server

OTA cluster

Attributes

ID Name Data type (ID) Range Default
0x0000 UpgradeServerID EUI64 (0xF0) / 0xffffffffffffffff
0x0001 FileOffset uint32 (0x23) / 0x00000000
0x0002 CurrentFileVersion uint32 (0x23) / 0x00000040
0x0006 ImageUpgradeStatus enum8 (0x30) / 0x00
0x0007 Manufacturer ID uint16 (0x21) / 0x1002
0x0008 Image Type ID uint16 (0x21) / 0x1602
0x0009 MinimumBlockPeriod uint16 (0x21) / 0x0000
0xfffd ClusterRevision uint16 (0x21) 0x0000 to 0xffff 0x0001

Commands

ID Name Direction
0x00 Image Notify Server to client
0x01 Query Next Image Request Client to server
0x02 Query Next Image Response Server to client
0x03 Image Block Request Client to server
0x05 Image Block Response Server to client
0x06 Upgrade End Request Client to server
0x07 Upgrade End Response Server to client

Mapping between DPs and clusters

DP ID DP description
1 On/Off
2 Mode
3 Brightness
4 Color temperature
5 Color
6 Scene
8 Music sync
9 Real-time adjustment

DP1 On/Off

Direction Cluster ID Attribute ID Type Value
Cloud-to-device 0x0006
  • 0x00: Off
  • 0x01: On
- -
Device-to-cloud 0x0006 0x0000 Boolean
  • 0: Off
  • 1: On

DP2 Mode

Direction Cluster ID Attribute ID Type Value
Cloud-to-device 0x0300 0xF0: Tuya-specific command -
  • 0: White light
  • 1: Colored light
  • 2: Scene mode
  • 3: Music mode
Device-to-cloud 0x0300 0xF000: Tuya-specific attribute uint8
  • 0: White light
  • 1: Colored light
  • 2: Scene mode
  • 3: Music mode

DP3 Brightness

Direction Cluster ID Attribute ID Type Value
Cloud-to-device 0x0008 0xF0: Tuya-specific command - 2 bytes, ranging from 0x0000 to 0x03E8.
Device-to-cloud 0x0008 0xF000: Tuya-specific attribute uint16 2 bytes, ranging from 0x0000 to 0x03E8.

DP4 Color temperature

Direction Cluster ID Attribute ID Type Value
Cloud-to-device 0x0300 0xE0: Tuya-specific command - 2 bytes, ranging from 0x0000 to 0x03E8.
Device-to-cloud 0x0300 0xE000: Tuya-specific attribute uint16 2 bytes, ranging from 0x0000 to 0x03E8.

DP5 Color

Direction Cluster ID Attribute ID Type Value
Cloud-to-device 0x0300 0xE1: Tuya-specific command - H: 2 bytes, ranging from 0x0000 to 0x0168. S: 2 bytes, ranging from 0x0000 to 0x03E8. V: 2 bytes, ranging from 0x0000 to 0x03E8.
Device-to-cloud 0x0300 0xE100: Tuya-specific attribute uint4 H: 2 bytes, ranging from 0x0000 to 0x0168. S: 2 bytes, ranging from 0x0000 to 0x03E8. V: 2 bytes, ranging from 0x0000 to 0x03E8.

DP6 Scene

Direction Cluster ID Attribute ID Type Value
Cloud-to-device 0x0300 0xF1: Tuya-specific command - Data length is 2 + 8 × n. n (n ≤ 8) represents the number of units of a scene.
Device-to-cloud 0x0300 0xF003: Tuya-specific attribute uint16 2 bytes, ranging from 0x0000 to 0x03E8.

For more information about DP data parsing, see DP6 Scene.

DP8 Music or DP9 Real-time adjustment

Direction Cluster ID Attribute ID Type Value
Cloud-to-device 0x0300 0xF2: Tuya-specific command - 11 bytes

These two DPs use the same Zigbee protocol. For more information about DP data parsing, see DP8 Music.

Default heartbeat

Report the app version at a random interval between 150 and 180 seconds.

Build and flash firmware

Build firmware

  1. Open your product development kit in Visual Studio Code and expand the software/TuyaOS/apps folder in the left navigation pane. The demo project folder will appear.

    Lighting Product Development Kit
  2. Right-click the folder and choose Build Project. Enter the version number of the build in the format x.x.x, and hit the Enter key to confirm.

  3. Once the build is finished, the console will print the following information.

    Lighting Product Development Kit

    The build output is found in apps/*product name*/output, where QIO is for production and UG is for an OTA update.

    Lighting Product Development Kit
  4. Clear the build cache. Before building the Telink firmware, it is recommended to select Clean Project, enter a version number, and then press Enter to clear the build cache.

    Lighting Product Development Kit Lighting Product Development Kit

Flash firmware

  • Use the chip vendor’s flashing tool, found in TLSR8258_3.8.1\software\TuyaOS\docs\, to upload firmware to Telink chips.
  • For more information about the flashing tools from Tuya and Silicon Labs, see Flash Firmware and Authorize Module.

Routine development

Configure basic information

Configure device registration

In the app_dev_register.c file within the project’s src folder, you can modify the registered device information, including device ID, cluster, and attribute.

Add or remove the registered server cluster, as shown below.

// server cluster list
CONST TAL_CLUSTER_T app_server_cluster_list[] = {
    DEF_CLUSTER_IDENTIFY_CLUSTER_ID(identify_attr_list)
    DEF_CLUSTER_GROUPS_CLUSTER_ID(group_attr_list)
    DEF_CLUSTER_SCENES_CLUSTER_ID(scene_attr_list)
    DEF_CLUSTER_ON_OFF_CLUSTER_ID(onoff_attr_list)
    DEF_CLUSTER_ZLL_COMMISSIONING_CLUSTER_ID(zll_commissioning_attr_list)
    DEF_CLUSTER_LEVEL_CONTROL_CLUSTER_ID(level_control_attr_list)
    DEF_CLUSTER_COLOR_CONTROL_CLUSTER_ID(color_control_attr_list)
};

Modify the registered endpoint and device ID, as shown below.

//endpoint descriptor
TAL_ENDPOINT_T dev_endpoint_desc[] = {
    {0x01, ZHA_PROFILE_ID, ZG_DEVICE_ID_EXTENDED_COLOR_LIGHT, SERVER_CLUSTER_NUM, (TAL_CLUSTER_T *)&app_server_cluster_list[0], 0, NULL},
    {0xF2, ZGP_PROFILE_ID, ZG_DEVICE_ID_GP_PROXY_MINIMUM, 0, NULL, CLIENT_CLUSTER_NUM, (TAL_CLUSTER_T *)&app_client_cluster_list[0]},
};

Modify firmware information

In the app_config.yml file within the project directory, configure information including the PID, model ID, and device type. Two configuration modes are available for this file. Choose the one that suits your needs. The content and function of the file are as follows:

#######################################################################
# COMPATIBILITY of [Tuya mode]
# For the use of Tuya redefined attributes:
# [cluster:0x0000,attribute:0x0004] Tuya manufacturer name
# [cluster:0x0000,attribute:0x0005] Tuya model ID
########################################################################
Firmware_Information:
  description: "this is a demo project"
  device_role: "router"   # router/sleep_end_dev
  image_type: 0x1602
  manufacture_id: 0x1002
  model_id: "TS0505B"
  manufacture_name: "_TZ3210_hxyvqfuz" # capacity+pid
  module_name: "ZSU"
  chip_id: "efr32mg21a020f1024im32" # efr32mg21a020f1024im32/efr32mg21a020f768im32


########################################################################
# COMPATIBILITY of [Zigbee standard mode]
# For the use of ZCL standard attributes:
# [cluster:0x0000,attribute:0x0004] ManufacturerName
# [cluster:0x0000,attribute:0x0005] ModelIdentifier
########################################################################
# Firmware_Information:
#   description: "this is a demo project"
#   device_role: "router"   # router/sleep_end_dev
#   image_type: 0x1602
#   manufacture_id: 0x1002
#   model_id: "custom"
#   manufacture_name: "custom"
#   product_id: "bhzkbugw"
#   capacity: "_TZ3210_"
#   product_type: "TS0502B"  
#   module_name: "ZSU"
#   chip_id: "efr32mg21a020f1024im32" # efr32mg21a020f1024im32/efr32mg21a020f768im32

To customize the model_id and manufacture_name attributes, you must select the second mode and specify capacity, product_type, and product_id.

Name Feature
description The product description.
device_role The device role, with router for a standard power router device and sleep_end_dev for a low power end device. Be cautious when making changes.
image_type The firmware information, used to verify OTA updates.
manufacture_id The manufacturer ID, used to verify OTA updates.
model_id The device model, used to identify features after the device connects to a Tuya-enabled gateway. Be cautious when making changes.
manufacture_name A value that combines the product capability value and Tuya’s PID, separated by an underscore (_), for example, _TZ3210_hxyvqfuz.
module_name The module model, indicating which module the product uses.
chip_id The chip model, indicating which chip the product uses. Do not change this field.
capacity The capability value of a Tuya-enabled product. Do not change this field. If you do need to change this field, contact the product manager.
product_type The device model, used to identify features after the device connects to a Tuya-enabled gateway. Be cautious when making changes.
product_id The product ID (PID) assigned by Tuya. It is currently set to a default PID, which will be replaced with a new one during flashing.

Configure product development kit

Configure a range of settings in the light_app_config.h file within the product’s include folder.

  • The options for basic product configurations are as follows:

    Item Feature
    APP_LIGHT_CHANNELS Light color.
    • 1: Cool white light (C)
    • 2: Warm to cool white light (CW)
    • 3: Colored light (RGB)
    • 4: Cool white and colored light (RGBC)
    • 5: White and colored light (RGBCW)
    DEFAULT_TX_POWER The device’s transmit power. Change it based on your hardware.
    LIGHT_ON_GRADUAL_TIME_MS The light fade-in time, a Tuya-specific feature.
    LIGHT_OFF_GRADUAL_TIME_MS The light fade-out time, a Tuya-specific feature.
  • The options for device pairing configurations are as follows:

    Item Feature
    ZIGBEE_JOIN_TIMEOUT_MS The pairing timeout, in milliseconds.
    POWER_ON_AUTO_JOIN Whether to automatically trigger pairing for an unpaired device upon power on.
    SCAN_NETWORK_RESET_COUNT The power cycle times to trigger a reset.
    SCAN_NETWORK_PROMPT_TIME_S The pairing status indication duration, in seconds.
    SCAN_NETWORK_PROMPT_METHOD The pairing status indication behavior. 0: Blink. 1: Breathing effect.
  • The options for hardware configurations are as follows:

    Item Feature
    PWM_MODE_ENABLE 1: Enable PWM output. 0: Disable PWM output.
    APP_PWM_FREQUENCY The PWM frequency.
    APP_PWM_POLARITY The active level for PWM output.
    APP_PWM_RED_PIN_NUM The I/O pin for red light output.
    APP_PWM_GREEN_PIN_NUM The I/O pin for green light output.
    APP_PWM_BLUE_PIN_NUM The I/O pin for blue light output.
    APP_PWM_COLD_PIN_NUM The I/O pin for cool white light output.
    APP_PWM_WARM_PIN_NUM The I/O pin for warm white light output.
    BRIGHT_MODE_CCT The mode for color temperature adjustment. 0: CW mode. 1: CCT mode.
    CTRL_PIN_ENABLE 1: Enable the control pin. 0: Disable the control pin.
    CTRL_PIN_NUM The I/O pin for the control pin output.
    CTRL_PIN_LEVEL The active level for the control pin output.
    POWER_CONFIG_ENABLE 1: Enable power conversion. 0: Disable power conversion.
    CW_POWER_CONFIG The white light power, ranging from 100 to 200 in percentage.
    RGB_POWER_CONFIG The colored light power, ranging from 100 to 200 in percentage.
    LIGHT_CONFIG_CW_MIN The minimum duty cycle for the white light pin output, ranging from 1 to 100 in percentage.
    LIGHT_CONFIG_CW_MAX The maximum duty cycle for the white light pin output, ranging from 1 to 100 in percentage.
    LIGHT_CONFIG_COLOR_MIN The minimum duty cycle for the colored light pin output, ranging from 10 to 100 in percentage.
    LIGHT_CONFIG_COLOR_MAX The maximum duty cycle for the colored light pin output, ranging from 10 to 100 in percentage.
    COLOR_TEMPERATURE_KEV_MAX The maximum color temperature in Kelvin degrees.
    COLOR_TEMPERATURE_KEV_MIN The minimum color temperature in Kelvin degrees.
  • The options for gamma configurations are as follows:

    Item Feature
    GAMMA_ENABLE 1: Enable gamma correction. 0: Disable gamma correction.
    RED_GAMMA The gamma for the red light, ranging from 0 to 100.
    RED_WHITE_BALANCE The white balance for the red light, ranging from 0 to 100.
    GREEN_GAMMA The gamma for the green light, ranging from 0 to 100.
    GREEN_WHITE_BALANCE The white balance for the green light, ranging from 0 to 100.
    BLUE_GAMMA The gamma for the blue light, ranging from 0 to 100.
    BLUE_WHITE_BALANCE The white balance for the blue light, ranging from 0 to 100.
  • The options for production testing configurations are as follows:

    Item Feature
    LIGHT_BEACON_MF_TEST_ENABLE 1: Enable beacon testing. 0: Disable beacon testing.
    PRODUCT_STEP1_REPEAT Whether repeated testing is allowed.
    PRODUCT_COLD_AGING_MINS The aging time for the cool white light.
    PRODUCT_WARM_AGING_MINS The aging time for the warm white light.
    PRODUCT_COLOR_AGING_MINS The aging time for the RGB light.
  • The options for standard and Tuya-specific Zigbee configurations are as follows:

    Item Feature
    ZIGBEE_START_UP_ON_OFF_ENABLE Whether to enable startup on/off. 0: Disable. 1: Enable.
    TUYA_PRIVATE_CAMMAND_ENABLE Whether to enable Tuya-specific features. 0: Disable. 1: Enable.

Configure pins

PWM output pin

Configure the I/O pin for PWM output in the light_app_config.h file within the product’s include folder, as shown below.

//pwm io config
#define APP_PWM_RED_PIN_NUM     APP_GPIO_PA3
#define APP_PWM_GREEN_PIN_NUM   APP_GPIO_PD2
#define APP_PWM_BLUE_PIN_NUM    APP_GPIO_PC5
#define APP_PWM_COLD_PIN_NUM    APP_GPIO_PA4
#define APP_PWM_WARM_PIN_NUM    APP_GPIO_PA0

Pin mapping between Telink and Tuya

The pin mapping for the Telink platform is as follows. TUYA_GPIO_NUM_0 corresponds to 0, and so on.

#define APP_GPIO_PA0    TUYA_GPIO_NUM_0
#define APP_GPIO_PA1    TUYA_GPIO_NUM_1
#define APP_GPIO_PA2    TUYA_GPIO_NUM_2
#define APP_GPIO_PA3    TUYA_GPIO_NUM_3
#define APP_GPIO_PA4    TUYA_GPIO_NUM_4
#define APP_GPIO_PA5    TUYA_GPIO_NUM_5
#define APP_GPIO_PA6    TUYA_GPIO_NUM_6
#define APP_GPIO_PA7    TUYA_GPIO_NUM_7
#define APP_GPIO_PB0    TUYA_GPIO_NUM_8
#define APP_GPIO_PB1    TUYA_GPIO_NUM_9
#define APP_GPIO_PB2    TUYA_GPIO_NUM_10
#define APP_GPIO_PB3    TUYA_GPIO_NUM_11
#define APP_GPIO_PB4    TUYA_GPIO_NUM_12
#define APP_GPIO_PB5    TUYA_GPIO_NUM_13
#define APP_GPIO_PB6    TUYA_GPIO_NUM_14
#define APP_GPIO_PB7    TUYA_GPIO_NUM_15
#define APP_GPIO_PC0    TUYA_GPIO_NUM_16
#define APP_GPIO_PC1    TUYA_GPIO_NUM_17
#define APP_GPIO_PC2    TUYA_GPIO_NUM_18
#define APP_GPIO_PC3    TUYA_GPIO_NUM_19
#define APP_GPIO_PC4    TUYA_GPIO_NUM_20
#define APP_GPIO_PC5    TUYA_GPIO_NUM_21
#define APP_GPIO_PC6    TUYA_GPIO_NUM_22
#define APP_GPIO_PC7    TUYA_GPIO_NUM_23
#define APP_GPIO_PD0    TUYA_GPIO_NUM_24
#define APP_GPIO_PD1    TUYA_GPIO_NUM_25
#define APP_GPIO_PD2    TUYA_GPIO_NUM_26
#define APP_GPIO_PD3    TUYA_GPIO_NUM_27
#define APP_GPIO_PD4    TUYA_GPIO_NUM_28
#define APP_GPIO_PD5    TUYA_GPIO_NUM_29
#define APP_GPIO_PD6    TUYA_GPIO_NUM_30
#define APP_GPIO_PD7    TUYA_GPIO_NUM_31

Pin mapping between Silicon Labs MG21 and Tuya

The pin mapping for Silicon Labs MG21 is as follows.

#define APP_GPIO_PA0    0
#define APP_GPIO_PA1    1
#define APP_GPIO_PA2    2
#define APP_GPIO_PA3    3
#define APP_GPIO_PA4    4
#define APP_GPIO_PA5    5
#define APP_GPIO_PA6    6
#define APP_GPIO_PB0    7
#define APP_GPIO_PB1    8
#define APP_GPIO_PC0    9
#define APP_GPIO_PC1    10
#define APP_GPIO_PC2    11
#define APP_GPIO_PC3    12
#define APP_GPIO_PC4    13
#define APP_GPIO_PC5    14
#define APP_GPIO_PD0    15
#define APP_GPIO_PD1    16
#define APP_GPIO_PD2    17
#define APP_GPIO_PD3    18
#define APP_GPIO_PD4    19

Application files

  • app_main.c: The main function file, one of the most important files in product development. It includes program initialization functions, network status callbacks, ZCL data reception callbacks, attribute writing callbacks, application flash read/write functions, and production testing callbacks.

  • app_dev_register.c: The device registration file, including the device ID, cluster ID, and attribute ID. You can modify this file to update a device’s registered information.

  • app_light_prod.c: The production testing file. When the device receives a beacon advertising packet for initiating a production test, it will trigger tal_beacon_mf_test_callback, which calls prod_test_callback. The device will then enter an automated production test with blinking lights. This file implements the status indication for production testing. Do not modify it unless necessary.

  • app_light_prompt.c: The status indication file, including the functions for blinking and breathing effects.

  • app_cluster_onoff.c: Processes commands for the Zigbee 3.0 On/Off cluster.

  • app_cluster_level_control.c: Processes commands for the Zigbee 3.0 Level Control cluster.

  • app_cluster_color_control.c: Processes commands for the Zigbee 3.0 Color Control cluster.

Support and help

If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.