Contact Us
Log In

Zigbee Common Solution

Last Updated on : 2022-03-29 03:53:21download

Zigbee’s general solution is one of the major MCU connection solutions. You can quickly complete the MCU connection to Zigbee general connection protocol of the Tuya module, and implement device networking. Tuya provides complete development services from modules, apps to cloud services. Compared to other communication module solutions, the Zigbee module requires the gateway, supports ad hoc networks, and features low power. This topic describes the MCU development process through Tuya Zigbee general solution.

Development process

Step 1: Create products

Log in to the IoT console and create a product. Select the desired product, and select Zigbee for net pairing mode. After finishing creation, you select the functions, panel, module, and firmware based on your product, and download the MCU development documents accordingly.

You can find the specific description of creating products in MCU Connection Solution. See Product creation.

Zigbee Common Solution

Common module

The platform recommends the common module models when you create a product. TYZS3 and TYZS5 are the most frequently selected Zigbee modules for Zigbee’s general solution.

Zigbee Common Solution

Two kinds of firmware are available for Tuya Zigbee modules, electrical firmware, and ELV (extra-low voltage) firmware. Electrical firmware suits products that require an uninterruptible power supply. ELV firmware suits battery-powered products that require low power consumption.

After selecting the module and firmware, you can purchase the module sample online. The hardware engineer will proceed with the board layout design. See the documentation related to hardware development in the documentation center.

Datasheet: TYZS5 Module Datasheet

Schematic diagram of the minimum module: TYZS5 Module & MCU serial communication instructions

Step 2: Network configuration verification

When receiving the module, it is suggested that, before start coding, you run the provided module debugging assistant, and connect the Zigbee module in MCU simulation mode to check if the module can work properly. Meanwhile, you can get familiar with the protocol interaction process, which will help you to proceed with development debugging.

Zigbee Common Solution

In MCU simulation mode, the debugging assistant simulates the MCU to automatically respond to the module with the correct protocol data. After you configure the network through the mobile phone, you can test DP data reporting and sending. The procedure of operating the assistant and module network configuration is as follows. Before the operation, you need to learn about the operation instruction of the Tuya module debugging assistant. For beginners, see Module Debugging Assistant Instruction.

  1. Based on the schematic diagram of the minimum system, you build the peripheral circuit of the module and jump the wire directly in case of simple testing.

  2. Open the debugging assistant in the development documents, and import the debugging file. Select the Zigbee general protocol and MCU simulation mode.

  3. Connect the module serial port to the computer through a USB-to-TTL adapter, and select the corresponding serial port and Baud in the assistant. After you open the serial port and click Start, you will see the initial protocol interaction between the module and the host.

    Note: If the module does not send data after power on, check if the peripheral circuit of the module is correct.

  4. Click Configure Module, and the module enters network configuration mode. Configure network on the app according to the status. See the app operation instruction for network configuration operation.

    Note: Before configuring a sub-device, you need to configure the network of the gateway on the Tuya Smart app or Smart Life app. Then, the Zigbee sub-device can be added. For more information, see the documentation Zigbee Network Configuration Description.

    Zigbee Common Solution

Step 3: Software development

During hardware debugging, you will see a sequence of serial port protocol interaction data between the module and MCU. To understand this data, refer to the protocol documentation in the development documents. The protocol consists of a basic protocol and function protocol. The basic protocol is product-neutral and shared by the modules. It consists of a module initial command and certain extension function command. The function protocol works to report and send commands based on the basic protocol and specifies the DP data format. The basic protocol is updated in real-time in the documentation center. See Tuya Zigbee module UART communication protocol.

There are two methods to connect the MCU to Tuya module protocol, migrating MCU SDK or connecting the protocol by yourself.

Connect the protocol by yourself

If the MCU resource is limited or migrating MCU SDK is inapplicable, you can connect the protocol by yourself.

Migrate MCU SDK

If the MCU resource is sufficient, it is recommended to directly migrate MCU SDK, which facilitates the development process. MCU SDK in the development documents is the protocol application code in C language, and it can be directly imported to the MCU project. MCU SDK requirements for MCU hardware resources: 4 KB Flash, about 100 bytes of RAM. RAM is related to DP data length. For example, the OTA function takes more than 260 bytes. A 9-level nested function is adopted. If you do not have adequate resources, you can implement the connection protocol. The functions in the SDK package can act as references.

MCU SDK migration tutorial: MCU SDK Migration

Step 4: Protocol verification

After migrating MCU SDK, you can use the module debugging assistant in module simulation mode to verify the MCU code. The operation is similar to the MCU simulation mode. In the module simulation mode, the assistant automatically sends the initial data flow to verify whether the MCU response is correct, and sends prompts for data error. After the initial interaction, you can test other extension functions.

Note: The module simulation mode only verifies the MCU serial port protocol, and does not support networking. After finishing the test, connect the MCU to the actual module and proceed with joint network configuration debugging.

Zigbee Common Solution

Zigbee Common Solution25

Step 5: Joint debugging

After the assistant verifies the code, connect the MCU to the module and configure the network on the app. You will enter function joint debugging. Joint debugging is used to test whether the DPs reporting and sending work properly. The links of useful tools adopted in the debugging are as follows:

Query the background log: log in to the IoT Console and enter Operation center. Query device background log according to its device ID.

Online support center: Tuya provides online services. If the documentation cannot solve your problems, raise your questions online and our technical team will help you troubleshoot problems.