Designing a voice-control product prototype (MCU access)

Last Updated on2020-08-06 06:17:56

Overview

Due to the rapid development of the smart speaker market, the voice recognition and control are very popular in smart homes.

Many manufacturers of smart devices aim to develop and enhance the voice control ability. However, smart speakers are not available in everyone’s home, and the access requirements of major speaker brands are respectively independent.

The voice module provided by Tuya Smart can well solve this problem. Just like typical modules, the serial port can be connected to achieve local voice control without speakers.

Materials

Hardware (3)
  • NUCLEO-G071RB

    Count:1

    more

  • TUYA Sandwich Voice Wi-Fi Board (VWXR2)

    Count:1

    more

  • TUYA Sandwich (PWM + IIC) Lighting Function Board

    Count:1

    more

Steps

  • Step 1: Project introduction

    Both the Wi-Fi voice development board and the typical Wi-Fi development board follow the common serial port protocol.

    For an MCU development engineers, the access process is the same as that of the ordinary Wi-Fi module. The voice control ability is integrated on the module. Developers do not need to do more development alone. The Tuya sandwich voice function board has two microphone interfaces and a speaker interface onboard, and the module has a built-in wake-up word “Xiǎo Zhì Guǎn Jiā” (小智管家 in Chinese).

    Taking the RGB/Warm/Cool multi-color lights as an example, this topic introduces the development process of voice-controlled smart lights.

  • Step 2: Module Debugging during software development

    The software development process is based on Arduino to achieve protocol interaction among MCU, sensors, and modules.

    The communication between the MCU and the module can be adjusted to realize network configuration of the App, and the MCU data is transmitted to the App.

    Step 2.1: Environment setup

    For detailed instruction on environment setting up of sandwich development board, see MCU Development environment setup.

    The preceding reference talks about how to add the ST development board to the Arduino IDE, and integrate the STM32CubeProgrammer to realize the compilation and download function. You must read it carefully.

    Step 2.2: Downloading the development kit

    After the environment is ready, you can create a project and download the detailed tutorial for transplanting the Tuya MCU SDK development kit. For more information, see MCU Quick Start.

    Note: When you create a product, you must select Wi-Fi for the communication protocol. And the module model and firmware must be relevant to the voice module.

    demovwxr2 wifi module.png

    Step 2.3: Porting and debugging

    After successful porting, you will see the selected product panel. The communication part of the module are tuned up. Next, you must transplant the driver of the RGB/Warm/Cool multi-color lights function board.

    For detailed information about SDK porting and debugging, see MCU Quick Start.

  • Step 3: Function board debugging during software development

    You can download the driver of RGB/Warm/Cool multi-color light for reference. PWM_IIC_RGB_Drive.zip

    Add the driver file to the project, and the application layer code sample is as follows.

    void setup() {
      pinMode(PC13, INPUT);     // Key detection initialization
      mySerial.begin(9600);     // Software serial port initialization
      mySerial.println("myserial init successfully!");
      Serial.begin(115200);     //PA3 RX   PA2 TX
      Serial.println("serial init successfully!\r\n");
      light_data_int();
      IIC_Init();
      delay(10);
      rgb_init(0, 0, 0);
      timer_init();
      wifi_protocol_init();
      Hue_shade_start(&a);
    
    }
    
    void loop() {
      if (init_flag == 0) {
        time_cnt++;
        if (time_cnt % 5000 == 0) {
          time_cnt = 0;
          cnt ++;
        }
        wifi_stat_led(&cnt);  // Network status indicator light
      }
    
      wifi_uart_service();
      myserialEvent();      // Serial port receive processing function
      key_scan();           // Press the button to reset the network
    
    }
    
    
  • Step 4: Testing the network

    After all functions are the successful transplantation of the function board code, the network are re-configured. Firstly, the functions of the mobile phone, such as light switch and color adjustment, were tested and proved to be correct.

Summary

By leveraging the Tuya IoT platform, Tuya sandwich development board, and Arduino IDE, the prototype of a voice-controlled RGB/Warm/Cool multi-color lights can be quickly realized.